diff --git a/data/meta.yml b/data/meta.yml index 2e3a46e..a4270ec 100644 --- a/data/meta.yml +++ b/data/meta.yml @@ -25,7 +25,7 @@ addressbook: /vcard-matthias-kretschmann.vcf typekit: dtg3zui googleanalytics: UA-1441794-4 -matomoDomain: https://analytics.kremalicious.com +matomoUrl: https://analytics.kremalicious.com matomoSite: 2 avatarBase64: > diff --git a/gatsby-browser.js b/gatsby-browser.js index f45ef48..e69de29 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -1,35 +0,0 @@ - -// Matomo page tracking -// https://github.com/scottnonnenberg/blog/blob/master/gatsby-browser.js -let first = true - -function getDuration() { - const start = window.start || new Date() - const now = new Date() - const difference = now.getTime() - start.getTime() - - if (difference === 0) { - return null - } - - return difference -} - -exports.onRouteUpdate = state => { - window._paq = window._paq || [] - - if (first) { - first = false - window._paq.push([ - 'trackEvent', - 'javascript', - 'load', - 'duration', - getDuration(), - ]) - } else { - window._paq.push(['setCustomUrl', state.pathname]) - window._paq.push(['setDocumentTitle', state.pathname]) - window._paq.push(['trackPageView']) - } -} diff --git a/gatsby-config.js b/gatsby-config.js index 3058ac4..70e2736 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -2,7 +2,7 @@ const path = require('path') const fs = require('fs') const yaml = require('js-yaml') const meta = yaml.load(fs.readFileSync('./data/meta.yml', 'utf8')) -const { url, googleanalytics } = meta +const { url, googleanalytics, matomoUrl, matomoSite } = meta module.exports = { siteMetadata: { @@ -44,6 +44,14 @@ module.exports = { respectDNT: true, }, }, + { + resolve: 'gatsby-plugin-matomo', + options: { + siteId: `${matomoSite}`, + siteUrl: `${url}`, + matomoUrl: `${matomoUrl}`, + }, + }, { resolve: 'gatsby-plugin-svgr', options: { diff --git a/gatsby-ssr.js b/gatsby-ssr.js index a7fb3ac..e69de29 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -1,49 +0,0 @@ -import React, { Fragment } from 'react' -const fs = require('fs') -const yaml = require('js-yaml') -const meta = yaml.load(fs.readFileSync('./data/meta.yml', 'utf8')) -const { url, matomoDomain, matomoSite } = meta - -// add Matomo tracking code -// adapted from: -// https://github.com/scottnonnenberg/blog/blob/master/html.js#L58 -exports.onRenderBody = ({ setPostBodyComponents, pathname }) => { - if (process.env.NODE_ENV === 'production') { - if (!(navigator.doNotTrack == '1' || window.doNotTrack == '1')) { - const js = ` - window._paq = window._paq || []; - window._paq.push(['setTrackerUrl', '${matomoDomain}/piwik.php']); - window._paq.push(['setSiteId', '${matomoSite}']); - window._paq.push(['enableLinkTracking']); - window._paq.push(['trackPageView']); - window._paq.push(['enableHeartBeatTimer']); - window.start = new Date(); - - var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; - g.type='text/javascript'; g.defer=true; g.async=true; - g.src='${matomoDomain}/piwik.js'; - s.parentNode.insertBefore(g,s); - ` - - const noJs = `tracker` - - return setPostBodyComponents([ - -