gatsby-plugin-matomo/src/gatsby-browser.js

36 lines
772 B
JavaScript
Raw Normal View History

2018-05-07 18:29:27 +02:00
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 = ({ location }) => {
if (process.env.NODE_ENV !== 'production' && typeof _paq !== 'undefined') {
window._paq = window._paq || []
2018-05-07 18:29:27 +02:00
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'])
}
2018-05-07 18:29:27 +02:00
}
return null
2018-05-07 18:29:27 +02:00
}