Permalink
Browse files

improvements for SPA tracking

  • Loading branch information...
kremalicious committed Jun 28, 2018
1 parent 347f951 commit 7d653d564cb0ca4ae05d6897d94185ea2198462e
Showing with 10 additions and 13 deletions.
  1. +2 −0 src/gatsby-browser.js
  2. +8 −13 src/gatsby-ssr.js
@@ -35,9 +35,11 @@ exports.onRouteUpdate = ({ location }) => {
console.log(`[Matomo] Page view for: ${pathname}`)
}
} else {
window._paq.push(['setReferrerUrl', pathname])
window._paq.push(['setCustomUrl', pathname])
window._paq.push(['setDocumentTitle', pathname])
window._paq.push(['trackPageView'])
window._paq.push(['enableLinkTracking'])

if (window.dev) {
console.log(`[Matomo] Page view for: ${pathname}`)
@@ -9,22 +9,20 @@ function buildTrackingCode(pluginOptions) {
window.dev = ${pluginOptions.dev}
if (window.dev === true || !(navigator.doNotTrack == '1' || window.doNotTrack == '1')) {
window._paq = window._paq || [];
window._paq.push(['setTrackerUrl', '${
pluginOptions.matomoUrl
}/piwik.php']);
window._paq.push(['setTrackerUrl', '${pluginOptions.matomoUrl}/piwik.php']);
window._paq.push(['setSiteId', '${pluginOptions.siteId}']);
window._paq.push(['enableLinkTracking']);
window._paq.push(['trackPageView']);
window._paq.push(['enableLinkTracking']);
window._paq.push(['enableHeartBeatTimer']);
window.start = new Date();
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.defer=true; g.async=true; g.src='${script}'; s.parentNode.insertBefore(g,s);
if (window.dev === true) {
console.log('[Matomo] Tracking initialized')
console.log('[Matomo] matomoUrl: ${pluginOptions.matomoUrl}, siteId: ${
pluginOptions.siteId
}')
console.log('[Matomo] matomoUrl: ${pluginOptions.matomoUrl}, siteId: ${pluginOptions.siteId}')
}
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.defer=true; g.async=true; g.src='${script}'; s.parentNode.insertBefore(g,s);
}
`

@@ -37,10 +35,7 @@ function buildTrackingCode(pluginOptions) {
}

function buildTrackingCodeNoJs(pluginOptions, pathname) {
const html = `<img src="${pluginOptions.matomoUrl}/piwik.php?idsite=${
pluginOptions.siteId
}&rec=1&url=${pluginOptions.siteUrl +
pathname}" style="border:0" alt="tracker" />`
const html = `<img src="${pluginOptions.matomoUrl}/piwik.php?idsite=${pluginOptions.siteId}&rec=1&url=${pluginOptions.siteUrl + pathname}" style="border:0" alt="tracker" />`

return (
<noscript

0 comments on commit 7d653d5

Please sign in to comment.