Permalink
Browse files

do nothing on route updates when piwik isn't loaded and in development

  • Loading branch information...
kremalicious committed May 8, 2018
1 parent 71fb56d commit 6c0a840de21ce46f544b6ce9a7dd63e961e7ab6b
Showing with 25 additions and 22 deletions.
  1. +17 −14 src/gatsby-browser.js
  2. +8 −8 src/gatsby-ssr.js
@@ -13,20 +13,23 @@ function getDuration() {
}

exports.onRouteUpdate = ({ location }) => {
window._paq = window._paq || []
if (process.env.NODE_ENV !== 'production' && typeof _paq !== 'undefined') {
window._paq = window._paq || []

if (first) {
first = false
window._paq.push([
'trackEvent',
'javascript',
'load',
'duration',
getDuration(),
])
} else {
window._paq.push(['setCustomUrl', location.pathname])
window._paq.push(['setDocumentTitle', location.pathname])
window._paq.push(['trackPageView'])
if (first) {
first = false
window._paq.push([
'trackEvent',
'javascript',
'load',
'duration',
getDuration()
])
} else {
window._paq.push(['setCustomUrl', location.pathname])
window._paq.push(['setDocumentTitle', location.pathname])
window._paq.push(['trackPageView'])
}
}
return null
}
@@ -40,14 +40,14 @@ function buildTrackingCodeNoJs(siteId, matomoUrl, siteUrl, pathname) {

exports.onRenderBody = ({ setPostBodyComponents, pathname }, pluginOptions) => {
if (process.env.NODE_ENV === 'production') {
const siteId = pluginOptions.siteId
const siteUrl = pluginOptions.siteUrl
const matomoUrl = pluginOptions.matomoUrl
const siteId = pluginOptions.siteId
const siteUrl = pluginOptions.siteUrl
const matomoUrl = pluginOptions.matomoUrl

return setPostBodyComponents([
buildTrackingCode(siteId, matomoUrl),
buildTrackingCodeNoJs(siteId, matomoUrl, siteUrl, pathname)
])
}
return setPostBodyComponents([
buildTrackingCode(siteId, matomoUrl),
buildTrackingCodeNoJs(siteId, matomoUrl, siteUrl, pathname)
])
}
return null
}

0 comments on commit 6c0a840

Please sign in to comment.