Skip to content

Commit

Permalink
Enable Matomo configuration via env vars, in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Parisot committed Dec 1, 2021
1 parent 58e686e commit f392d0c
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 48 deletions.
5 changes: 4 additions & 1 deletion ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const { parsed } = require('dotenv').config({ path: 'stylo.env'})

module.exports = {
apps: [
{
name: "front",
script: "vite",
cwd: "./front/gatsby"
cwd: "./front/gatsby",
env: parsed
},
{
name: "export",
Expand Down
6 changes: 4 additions & 2 deletions front/gatsby/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<meta name="twitter:description" content="Stylo, online text editor for scholars">
<meta name="twitter:image" content="/favicon.ico">
<script src="https://polyfill.io/v3/polyfill.min.js"></script>
{{#if SNOWPACK_MATOMO}}
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
Expand All @@ -29,14 +30,15 @@
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analyseweb.huma-num.fr/";
var u="{{ SNOWPACK_MATOMO_URL }}";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '286']);
_paq.push(['setSiteId', '{{ SNOWPACK_MATOMO_SITE_ID }}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
{{/if}}
</head>
<body>
<div id="root" aria-live></div>
Expand Down
118 changes: 117 additions & 1 deletion front/gatsby/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion front/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"node-fetch": "^2.6.1",
"prettier": "^2.3.0",
"sass": "^1.43.4",
"vite": "^2.6.14"
"vite": "^2.6.14",
"vite-plugin-handlebars": "^1.6.0"
}
}
11 changes: 11 additions & 0 deletions front/gatsby/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { defineConfig } from 'vite'
import { env } from 'process'
import react from '@vitejs/plugin-react'
import handlebars from 'vite-plugin-handlebars'

const { NODE_ENV, SNOWPACK_MATOMO_URL, SNOWPACK_MATOMO_SITE_ID } = env

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -18,6 +21,14 @@ export default defineConfig({
},
plugins: [
react(),
handlebars({
context: {
NODE_ENV,
SNOWPACK_MATOMO: Boolean(SNOWPACK_MATOMO_URL) && Boolean(SNOWPACK_MATOMO_SITE_ID),
SNOWPACK_MATOMO_URL,
SNOWPACK_MATOMO_SITE_ID,
}
})
],
define: {
'process.env': {
Expand Down
Loading

0 comments on commit f392d0c

Please sign in to comment.