diff --git a/README.md b/README.md index 16c46b4..812764a 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ _NOTE: By default, this plugin only generates output when run in production mode | `disableCookies` | (optional) If true, no cookie will be used by Matomo. | | `cookieDomain` | (optional) Specify cookie domain. | | `localScript` | (optional) If set, load local `piwik.js` script from the given path, instead of loading it from your `matomoUrl`. | +| `trackLoad` | (optional) If true, it will track the loading of the matomo library. Defaults to `true`. | | `dev` | (optional) Activate dev mode by setting to `true`. Will load all scripts despite not running in `production` environment. Ignores your local browser's DNT header too. Outputs some information in console about what it is doing. Useful for local testing but careful: all hits will be send like in production. | ```js diff --git a/src/gatsby-browser.js b/src/gatsby-browser.js index 7a76e81..57cd3ed 100644 --- a/src/gatsby-browser.js +++ b/src/gatsby-browser.js @@ -12,7 +12,7 @@ function getDuration() { return difference } -export const onRouteUpdate = ({ location, prevLocation }) => { +export const onRouteUpdate = ({ location, prevLocation }, pluginOptions) => { if (process.env.NODE_ENV === 'production' || window.dev === true) { if (!window._paq) return @@ -22,6 +22,10 @@ export const onRouteUpdate = ({ location, prevLocation }) => { prevLocation && prevLocation.pathname + prevLocation.search + prevLocation.hash + const { + trackLoad = true + } = pluginOptions + // document.title workaround stolen from: // https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-google-analytics/src/gatsby-browser.js const sendPageView = () => { @@ -45,7 +49,10 @@ export const onRouteUpdate = ({ location, prevLocation }) => { if (first) { first = false - _paq.push(['trackEvent', 'javascript', 'load', 'duration', getDuration()]) + + if (trackLoad) { + _paq.push(['trackEvent', 'javascript', 'load', 'duration', getDuration()]) + } if (dev) { console.debug(`[Matomo] Tracking duration for: ${url}`)