1
0
mirror of https://github.com/kremalicious/gatsby-plugin-matomo.git synced 2024-12-22 09:13:19 +01:00

improvements for SPA tracking

This commit is contained in:
Matthias Kretschmann 2018-06-28 19:53:03 +02:00
parent 347f951174
commit 7d653d564c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 11 additions and 14 deletions

View File

@ -35,9 +35,11 @@ exports.onRouteUpdate = ({ location }) => {
console.log(`[Matomo] Page view for: ${pathname}`) console.log(`[Matomo] Page view for: ${pathname}`)
} }
} else { } else {
window._paq.push(['setReferrerUrl', pathname])
window._paq.push(['setCustomUrl', pathname]) window._paq.push(['setCustomUrl', pathname])
window._paq.push(['setDocumentTitle', pathname]) window._paq.push(['setDocumentTitle', pathname])
window._paq.push(['trackPageView']) window._paq.push(['trackPageView'])
window._paq.push(['enableLinkTracking'])
if (window.dev) { if (window.dev) {
console.log(`[Matomo] Page view for: ${pathname}`) console.log(`[Matomo] Page view for: ${pathname}`)

View File

@ -9,22 +9,20 @@ function buildTrackingCode(pluginOptions) {
window.dev = ${pluginOptions.dev} window.dev = ${pluginOptions.dev}
if (window.dev === true || !(navigator.doNotTrack == '1' || window.doNotTrack == '1')) { if (window.dev === true || !(navigator.doNotTrack == '1' || window.doNotTrack == '1')) {
window._paq = window._paq || []; window._paq = window._paq || [];
window._paq.push(['setTrackerUrl', '${ window._paq.push(['setTrackerUrl', '${pluginOptions.matomoUrl}/piwik.php']);
pluginOptions.matomoUrl
}/piwik.php']);
window._paq.push(['setSiteId', '${pluginOptions.siteId}']); window._paq.push(['setSiteId', '${pluginOptions.siteId}']);
window._paq.push(['enableLinkTracking']);
window._paq.push(['trackPageView']); window._paq.push(['trackPageView']);
window._paq.push(['enableLinkTracking']);
window._paq.push(['enableHeartBeatTimer']); window._paq.push(['enableHeartBeatTimer']);
window.start = new Date(); window.start = new Date();
if (window.dev === true) {
console.log('[Matomo] Tracking initialized')
console.log('[Matomo] matomoUrl: ${pluginOptions.matomoUrl}, siteId: ${
pluginOptions.siteId
}')
}
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; 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); 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}')
}
} }
` `
@ -37,10 +35,7 @@ function buildTrackingCode(pluginOptions) {
} }
function buildTrackingCodeNoJs(pluginOptions, pathname) { function buildTrackingCodeNoJs(pluginOptions, pathname) {
const html = `<img src="${pluginOptions.matomoUrl}/piwik.php?idsite=${ const html = `<img src="${pluginOptions.matomoUrl}/piwik.php?idsite=${pluginOptions.siteId}&rec=1&url=${pluginOptions.siteUrl + pathname}" style="border:0" alt="tracker" />`
pluginOptions.siteId
}&rec=1&url=${pluginOptions.siteUrl +
pathname}" style="border:0" alt="tracker" />`
return ( return (
<noscript <noscript