问题
I have a Rails 4 App with the Google Analytics js right before the end of the body
to work with Turbolinks. However, unless I specifically reload the page I'm on, the Active Page always shows up as '/'. Is there any way to correct this?
回答1:
You can use the google-analytics-turbolinks gem and add the script as usual.
Update:
The only thing the gem does, is that it adds this coffeescript file into the assets folder:
if window.history?.pushState and window.history.replaceState
document.addEventListener 'page:change', (event) =>
# Google Analytics
if window.ga != undefined
ga('set', 'location', location.href.split('#')[0])
ga('send', 'pageview', {"title": document.title})
else if window._gaq != undefined
_gaq.push(['_trackPageview'])
else if window.pageTracker != undefined
pageTracker._trackPageview();
来源:https://stackoverflow.com/questions/24126060/google-analytics-not-showing-correct-active-page-in-rails-app