google-analytics-turbolinks icon indicating copy to clipboard operation
google-analytics-turbolinks copied to clipboard

skip `ga('send', 'pageview'` when normal access

Open masarakki opened this issue 10 years ago • 3 comments

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 avatar Apr 16 '14 11:04 masarakki

@masarakki - Are you successfully using this on production apps with the current Google Analytics implementation?

batter avatar Oct 16 '14 16:10 batter

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.

masarakki avatar Oct 17 '14 07:10 masarakki

:+1: Looks like it's working for me, cheers!

batter avatar Oct 17 '14 13:10 batter