段。io的分析。page ' not send to谷歌Analytics in Rails

时间:2021-10-07 13:52:45

I'm following Segment's quickstart guide at: https://segment.com/docs/libraries/analytics.js/quickstart/

下面是部分的quickstart指南:https://segment.com/docs/libraries/analytics.js/quickstart/

Basically, Google Analytics is not receiving any page views from Segment and I can't figure out why...

基本上,谷歌分析没有从段接收任何页面视图,我不知道为什么……

In my layouts/application file, I have:

在我的布局/应用文件中,我有:

:javascript
  !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.1.0";
    analytics.load('#{ENV["SEGMENT_WRITE_KEY"]}');
    analytics.page();
  }}();

Other notes:

另注:

  • It is properly pulling in my write key environment variable
  • 它正确地拉入我的写入键环境变量
  • The integration is set up on my Segment dashboard (enabled, with the correct website tracking id supplied)
  • 集成设置在我的分段仪表板上(启用,提供正确的网站跟踪id)
  • The analytics.load integration seems to be working because, in my debugger console, analytics.Integrations["Google Analytics"] is properly initialized
  • 分析。加载集成似乎可以工作,因为在我的调试器控制台,分析。集成[“谷歌分析”]被正确地初始化

Page views are showing up in the Segment dashboard's Debugger page (with the path, title, etc default properties all set), but views are not being transmitted to Google Analytics.

页面视图显示在段仪表板的调试器页面中(设置了路径、标题等默认属性),但是视图没有传输到谷歌Analytics。

I don't believe it's because any arguments are missing, because Google's pageview only requires either a page or location property, both of which are supplied by default through Segment's page() method.

我不认为这是因为任何参数都丢失了,因为谷歌的pageview只需要一个页面或位置属性,这两个属性都是通过段的page()方法默认提供的。

1 个解决方案

#1


2  

As it turns out, we had another script that was loading the same google analytics javascript file. I have no idea why having a duplicate script tag created the issue, but there it is. Removing the duplicate fixed the problem.

事实证明,我们有另一个脚本加载相同的谷歌分析javascript文件。我不知道为什么会有一个重复的脚本标记来创建问题,但它确实存在。删除副本修复了问题。

<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>
<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>

#1


2  

As it turns out, we had another script that was loading the same google analytics javascript file. I have no idea why having a duplicate script tag created the issue, but there it is. Removing the duplicate fixed the problem.

事实证明,我们有另一个脚本加载相同的谷歌分析javascript文件。我不知道为什么会有一个重复的脚本标记来创建问题,但它确实存在。删除副本修复了问题。

<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>
<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>