javascript 谷歌分析实时不显示结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25677259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Analytics Real-Time not showing results
提问by Jay Gray
The following script is not generating activity when cross-checked in Google Analytics
: Real-Time
section : Content
section --
以下脚本在交叉签入时不会生成活动Google Analytics
:Real-Time
部分:Content
部分-
<script>
(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', 'UA-475021xx-x', 'auto');
ga('send', 'pageview');
</script>
where xx-x
masks the real account code.
其中xx-x
掩盖了真实帐户代码。
The script is placed just before </head>
脚本放在之前 </head>
We have upgraded our account to Universal Analytics
. Google tells us that this is the script to use; directly copied and pasted here (with the masked account code).
我们已将帐户升级到Universal Analytics
。Google 告诉我们这是要使用的脚本;直接复制粘贴到这里(带屏蔽账号)。
On the Google Analytics page, the test page is loaded as an ACTIVE PAGE
. I click links on the test page to trigger ga
.
在 Google Analytics 页面上,测试页面作为ACTIVE PAGE
. 我单击测试页上的链接以触发ga
.
Is there an error in this script? For example, I see on other Stackoverflow posts that 'auto'
is replaced with the real domain
. But I don't see Google instructions to make that substitution.
这个脚本有错误吗?例如,我在其他 Stackoverflow 帖子上看到'auto'
被真正的domain
. 但我没有看到谷歌说明进行这种替换。
Am I doing something else wrong?
我做错了什么吗?
采纳答案by nyuen
You can check the health of your tag using Google tag assistant, and also check with developer tools whether you can see data being sent to your GA account. Also look in your account under Property > Tracking Info > Tracking Code for the status of your tracking code. But if you are not seeing Real Time data then something could be wrong.
您可以使用 Google 标签助手检查标签的健康状况,还可以使用开发人员工具检查是否可以看到发送到您的 GA 帐户的数据。还可以在“属性”>“跟踪信息”>“跟踪代码”下的帐户中查看跟踪代码的状态。但是,如果您没有看到实时数据,则可能有问题。
The third parameter in the 'create' method sets the cookie domain. It is optional and with 'auto', it sets the cookie domain to the highest domain level possible. Without it, the cookie domain will be set to the website domain without the www. prefix.
'create' 方法中的第三个参数设置 cookie 域。它是可选的,使用 'auto',它将 cookie 域设置为可能的最高域级别。如果没有它,cookie 域将被设置为没有 www 的网站域。字首。
回答by Zaenille
I did the same thing as you back then.
当年我和你做了同样的事情。
Mine started showing data in about 12-24 hours after I put the Google Analytics code.
在我放置 Google Analytics 代码后大约 12-24 小时,我的开始显示数据。
I suggest waiting for another day then checking if data comes up.
我建议再等一天,然后检查数据是否出现。
Given that this answer can only be verified until we wait for a certain amount of time, please hold off setting this as the correct answer until then.
鉴于此答案只能在我们等待一定时间后才能验证,请在此之前将其设置为正确答案。
回答by tylerlindell
For me, the issue was a dunce move. I have the Google Analytics Opt-out Add-on for Chrome enabled.
对我来说,这个问题是愚蠢的举动。我已启用 Chrome 的 Google Analytics Opt-out Add-on。
What I had to do was go to chrome://extensions/, scroll down to the Extension "Google Analytics Opt-out Add-on (by Google)" and uncheck the box that says, "Enable".
我必须做的是转到 chrome://extensions/,向下滚动到扩展程序“Google Analytics Opt-out Add-on (by Google)”并取消选中“启用”框。
I hope this helps someone.
我希望这可以帮助别人。
回答by Zhenya
Here is what my issue was. I'm using google analytics with wordpress. I tried configuring google analytics for my website using plugin called Google Analytics Dashboard for WP (GADWP). This plugin generated a google analytics snippet that looks similarly to the one described in the question:
这是我的问题。我在 wordpress 中使用谷歌分析。我尝试使用名为 Google Analytics Dashboard for WP (GADWP) 的插件为我的网站配置 Google Analytics。该插件生成了一个与问题中描述的类似的谷歌分析片段:
<script>
(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', 'UA-475021xx-x', 'auto');
ga('send', 'pageview');
</script>
However, in Google Analytics console, the suggested snippet looked like this:
但是,在 Google Analytics 控制台中,建议的代码段如下所示:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-110984887-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-475021xx-x');
</script>
It looks like this gtag.js is a new format for the google analytics snippet. So I disabled that wordpress plugin and I manually added the script suggested by Google Analytics to the page.
看起来这个 gtag.js 是谷歌分析代码段的新格式。因此,我禁用了该 wordpress 插件,并手动将 Google Analytics 建议的脚本添加到页面中。
回答by ZacKenichi
I have recently fixed the same issue. Please login to your admin dashboard and check the filters.
我最近解决了同样的问题。请登录您的管理仪表板并检查过滤器。
What I did was to make sure my valid host name filter was the correct one.
我所做的是确保我的有效主机名过滤器是正确的。
If you have copied the custom dashboard from another project or if you had an error in the filter then this would be worth your time to check out.
如果您从另一个项目复制了自定义仪表板,或者您在过滤器中有错误,那么这值得您花时间检查一下。
I have placed the value "domain.com" in the included host names filter.
我在包含的主机名过滤器中放置了值“domain.com”。
Let me know if this fixed the issue for you.
让我知道这是否为您解决了问题。