新手问题 Turblinks 下, GA 统计数据有偏差

hzy_zzz · January 08, 2020 · Last by hzy_zzz replied at January 08, 2020 · 1974 hits

通过 turbolinks 跳转的页面,在 GA 中显示的链接是上一个页面的链接。

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '<%= key %>', 'auto');
ga('send', 'pageview');

解决了。 参考: https://reed.github.io/turbolinks-compatibility/google_analytics.html

ga('create', '<%= key %>', 'auto');
ga('send', location.pathname);
hzy_zzz closed this topic. 08 Jan 22:37
You need to Sign in before reply, if you don't have an account, please Sign up first.