Google Analytics不能在Rails应用中显示正确的活动页面 [英] Google Analytics Not Showing Correct Active Page in Rails App

查看:98
本文介绍了Google Analytics不能在Rails应用中显示正确的活动页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

body 结束之前,我使用Google Analytics js的Rails 4应用程序与Turbolinks一起工作。但是,除非我专门重新加载了该页面,否则活动页面总是显示为/。有没有什么办法可以解决这个问题? shukydvir / google-analytics-turbolinksrel =nofollow> google-analytics-turbolinks gem 并像往常一样添加脚本。

更新:



宝石所做的唯一的事情就是它将这个咖啡脚本文件添加到资产文件夹中:

  if window.history?.pushState和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();


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?

解决方案

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();

这篇关于Google Analytics不能在Rails应用中显示正确的活动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆