google-analytics-turbolinks
google-analytics-turbolinks copied to clipboard
skip `ga('send', 'pageview'` when normal access
if you copied snippet from document of google analytics (and i think it is expected),
ga('send', 'pageview')
called twice when acceess normaly,
because of both html and page:change event will call it.
so I add variable to check page:change
is called from turbolinks or not.
if you expect html does not contain ga('send', 'pageview')
,
you should care browsers that can't use history.pushState like this.
if window.history?.pushState and window.history.replaceState
document.addEventListener 'page:change', (event) =>
if window.ga != undefined
...
else
if window.ga != undefined
ga('send', 'pageview')
else if window._gaq != undefined
...
@masarakki - Are you successfully using this on production apps with the current Google Analytics implementation?
It works when I sent this patch, but now I don't know it works with latest GA. and I can't try it again because I already gave up to use turbolinks.
:+1: Looks like it's working for me, cheers!