diff --git a/server/server.js b/server/server.js index 78c5789..83927db 100644 --- a/server/server.js +++ b/server/server.js @@ -51,6 +51,11 @@ app.use((req, res, next) => { csrf: req.session.csrf }) + // Add Piwik tracker if configured + if (config.piwik && config.piwik.site_id) { + res.locals.piwik = config.piwik + } + next() }) diff --git a/views/layout.pug b/views/layout.pug index dd1e448..e2fb219 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -3,6 +3,19 @@ html head meta(charset="utf8") meta(name="viewport", content="width=device-width, initial-scale=1") + if piwik + script(type="text/javascript"). + var _paq = _paq || []; + /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function() { + var u="#{piwik.track_url}"; + _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setSiteId', '#{piwik.site_id}']); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); + })(); block links link(rel="stylesheet", type="text/css", href="/style/main.css") link(rel="stylesheet", type="text/css", href="/style/footer.css")