Skip to content
Permalink
Browse files

better page url & referrer url tracking

  • Loading branch information...
kremalicious committed Mar 30, 2019
1 parent 24f57da commit 04b8ba19038f49571a0f19099f9af4575739a8fb
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/gatsby-browser.js
@@ -14,12 +14,13 @@ function getDuration() {
return difference
}

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

const pathname = location.pathname
const url = location.pathname + location.search + location.hash
const prevUrl = prevLocation && prevLocation.pathname + prevLocation.search + prevLocation.hash

if (first) {
first = false
@@ -32,17 +33,17 @@ exports.onRouteUpdate = ({ location }) => {
])

if (window.dev) {
console.log(`[Matomo] Page view for: ${pathname}`)
console.log(`[Matomo] Page view for: ${url}`)
}
} else {
window._paq.push(['setReferrerUrl', pathname])
window._paq.push(['setCustomUrl', pathname])
window._paq.push(['setDocumentTitle', pathname])
window._paq.push(['setReferrerUrl', prevUrl])
window._paq.push(['setCustomUrl', url])
window._paq.push(['setDocumentTitle', url])
window._paq.push(['trackPageView'])
window._paq.push(['enableLinkTracking'])

if (window.dev) {
console.log(`[Matomo] Page view for: ${pathname}`)
console.log(`[Matomo] Page view for: ${url}`)
}
}
}

0 comments on commit 04b8ba1

Please sign in to comment.
You can’t perform that action at this time.