From 04b8ba19038f49571a0f19099f9af4575739a8fb Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sat, 30 Mar 2019 14:30:50 +0100 Subject: [PATCH] better page url & referrer url tracking --- src/gatsby-browser.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/gatsby-browser.js b/src/gatsby-browser.js index c396b8a..7bb03ff 100644 --- a/src/gatsby-browser.js +++ b/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}`) } } }