Created
September 13, 2018 10:06
-
-
Save DimaSamodurov/127c39244d0b411bfb474a8102a83497 to your computer and use it in GitHub Desktop.
Using gtag with Turbolinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Global site tag (gtag.js) - Google Analytics --> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag() { | |
dataLayer.push(arguments); | |
} | |
document.addEventListener('turbolinks:load', function (event) { | |
if (typeof gtag === 'function') { | |
gtag('js', new Date()); | |
gtag('config', 'GA_TRACKING_ID', { | |
'page_location': event.data.url | |
}); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had problem with this implementation and AdWords. Paid traffic in Google Analytics had too many sessions/user and very high bounce rate, because Analytics was somehow reseting session of paid traffic. Finally I found code that worked: