mirror of
https://github.com/kremalicious/gatsby-plugin-matomo.git
synced 2024-12-22 17:23:23 +01:00
do nothing on route updates when piwik isn't loaded and in development
This commit is contained in:
parent
71fb56db48
commit
6c0a840de2
@ -13,20 +13,23 @@ function getDuration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.onRouteUpdate = ({ location }) => {
|
exports.onRouteUpdate = ({ location }) => {
|
||||||
window._paq = window._paq || []
|
if (process.env.NODE_ENV !== 'production' && typeof _paq !== 'undefined') {
|
||||||
|
window._paq = window._paq || []
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false
|
first = false
|
||||||
window._paq.push([
|
window._paq.push([
|
||||||
'trackEvent',
|
'trackEvent',
|
||||||
'javascript',
|
'javascript',
|
||||||
'load',
|
'load',
|
||||||
'duration',
|
'duration',
|
||||||
getDuration(),
|
getDuration()
|
||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
window._paq.push(['setCustomUrl', location.pathname])
|
window._paq.push(['setCustomUrl', location.pathname])
|
||||||
window._paq.push(['setDocumentTitle', location.pathname])
|
window._paq.push(['setDocumentTitle', location.pathname])
|
||||||
window._paq.push(['trackPageView'])
|
window._paq.push(['trackPageView'])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
@ -40,14 +40,14 @@ function buildTrackingCodeNoJs(siteId, matomoUrl, siteUrl, pathname) {
|
|||||||
|
|
||||||
exports.onRenderBody = ({ setPostBodyComponents, pathname }, pluginOptions) => {
|
exports.onRenderBody = ({ setPostBodyComponents, pathname }, pluginOptions) => {
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
const siteId = pluginOptions.siteId
|
const siteId = pluginOptions.siteId
|
||||||
const siteUrl = pluginOptions.siteUrl
|
const siteUrl = pluginOptions.siteUrl
|
||||||
const matomoUrl = pluginOptions.matomoUrl
|
const matomoUrl = pluginOptions.matomoUrl
|
||||||
|
|
||||||
return setPostBodyComponents([
|
return setPostBodyComponents([
|
||||||
buildTrackingCode(siteId, matomoUrl),
|
buildTrackingCode(siteId, matomoUrl),
|
||||||
buildTrackingCodeNoJs(siteId, matomoUrl, siteUrl, pathname)
|
buildTrackingCodeNoJs(siteId, matomoUrl, siteUrl, pathname)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user