Google Analytics Not Showing Correct Active Page in Rails App

核能气质少年 提交于 2019-12-22 13:32:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!