简体   繁体   English

Google Analytics跟踪代码无效

[英]Google Analytics Tracking Code is Not Working

I setup a Google Analytics account and I setup the website and got the Analytics code which is: 我设置了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-4XXXXXXX-1', 'mydomain.com');
      ga('send', 'pageview');
 </script>

I pasted into the Header of all my pages but Analytics keeps saying "Tracking Not Installed". 我粘贴到我所有页面的标题中,但Google Analytics不断说“未安装跟踪”。

I viewed and verified the source code is within the header of the home page and the code is there. 我查看并验证了源代码在主页的标题内,代码就在那里。 The site is built on Classic ASP (default.asp) and I have several other sites setup in GA and they worked fine. 该网站建立在经典ASP(default.asp)上,我在GA中设置了其他几个网站,它们运行良好。 So I don't know why this isn't working. 所以我不知道为什么这不起作用。 The code above was provided by GA. 上述代码由GA提供。

Can someone please tell me why this isn't working? 有人可以告诉我为什么这不起作用?

Give this a try. 试一试。

<script>
    var _gaq = _gaq || [];  
    _gaq.push(['_setAccount', 'UA-4XXXXXXX-1']);  
    _gaq.push(['_trackPageview']);

    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
</script>

If you just set this up, you should be able to see analytics in the "Realtime" panel. 如果您只是设置它,您应该能够在“实时”面板中看到分析。 Many of the other panels can take over a day before analytics are visible. 在分析可见之前,许多其他小组可能需要一天时间。

If you're using Google Chrome, you might also try the tag debugger plugin by ObservePoint or the Official Tag assistant plugin by Google 如果您使用的是谷歌浏览器,您也可以尝试使用ObservePoint的标签调试器插件或谷歌官方标签助手插件

Have you tried using a tool like HTTPFox (firefox) Google's Google Analytics Debugger (chrome) to monitor http requests? 您是否尝试使用HTTPFox (firefox)Google的Google Analytics Debugger (chrome)等工具来监控http请求? This will tell you if it's firing or not. 这将告诉你它是否正在开火。 If it is, check the real-time reports as mentioned in the comments. 如果是,请检查评论中提到的实时报告。 If it's not, then it's an issue with the code or your page. 如果不是,则代码或页面出现问题。

I figured out what the problem was. 我弄清楚问题是什么。 I setup an Account with GA using there new Beta Feature and I guess the account wouldn't work with the code they gave me. 我使用新的测试版功能在GA中设置了一个帐户,我猜这个帐户无法使用他们给我的代码。 So I deleted that account and recreated a Classic Account and took the code I posted above and it worked fine. 所以我删除了该帐户并重新创建了一个经典帐户并获取了我在上面发布的代码并且工作正常。 Thank you all for your help!! 谢谢大家的帮助!!

New Analytics Means New APIs 新分析意味着新的API

You are using the "Universal Analytics" snippet which is Google's new system they are trying to transition everyone over to. 您使用的是“Google Analytics(分析)”代码段,这是Google正在尝试将所有人转移到的新系统。 Some of the APIs have changed including event tracking. 一些API已经改变,包括事件跟踪。

Make sure you are using this: 确保您使用此:

ga('send', 'event', category, action, label);

Instead of this: 而不是这个:

_gaq.push(['_trackEvent', category, action, label]);

For event tracking. 用于事件跟踪。 Here is a thorough blog post on the subject http://blog.tylerbuchea.com/tracking-events-in-googles-new-universal-analytics/ 这是一篇关于该主题的完整博客文章http://blog.tylerbuchea.com/tracking-events-in-googles-new-universal-analytics/

I had a similar issue, I was hitting the wrong url, so I am redirecting somedomain.com to www.somedomain.com 我有一个类似的问题,我打错了网址,所以我将somedomain.com重定向到www.somedomain.com

see: https://support.google.com/tagmanager/answer/6103683?vid=1-635771588228302150-2080886913&rd=1 请参阅: https//support.google.com/tagmanager/answer/6103683?vid = 1-635771588228302150-2080886913&rd = 1

Make sure that you have published your tag, and that your trigger is formed properly to allow it to fire on the page you are testing. 确保您已发布标记,并且您的触发器已正确形成,以允许它在您正在测试的页面上触发。 Note that it can take a few seconds for the container to publish, and that you should do a hard refresh (eg ctrl+F5) of the page to see the changes. 请注意,容器可能需要几秒钟才能发布,并且您应该对页面进行硬刷新(例如ctrl + F5)以查看更改。

Check that your trigger isn't unnecessarily specific. 检查您的触发器是否具有不必要的特定性。 For example, if you define a URL based trigger and begin the URL with " http://www.example.com ", the tag will not fire for URLs " https://www.example.com " (using "https") and " http://example.com " (without the "www"). 例如,如果您定义基于URL的触发器并使用“ http://www.example.com ”开始URL,则不会触发标记“ https://www.example.com ”的标记(使用“https” )和“ http://example.com ”(没有“www”)。

Google Tag Manager can only fire tags within the capabilities of the browser. Google跟踪代码管理器只能在浏览器功能内触发代码。 Most browsers will not open more than six to eight HTTP requests to a single domain at a time. 大多数浏览器一次不会向单个域打开超过六到八个HTTP请求。 If you have a high number of tags on the same domain firing under the same conditions, tags will only fire within this browser limitation. 如果在相同的条件下同一个域上有大量标签,则标签只会在此浏览器限制内触发。

Just ran into a new version of the "not tracking" issue. 刚刚遇到了“不跟踪”问题的新版本。

Apparently now with the new Google Site Tag (gtag.js) tracking code, Analytics will only start tracking if you're signed up to Google Tag Manager as well and enable the domain there. 显然,现在使用新的Google网站代码(gtag.js)跟踪代码,只有在您注册Google跟踪代码管理器并在那里启用域名时,Google Analytics才会开始跟踪。

My new Analytics property didn't track for half a day after I added the tracking code. 添加跟踪代码后,我的新Google Analytics资产未跟踪半天。 After enabling the domain in Google Tag Manager, it started tracking instantly. 在Google跟踪代码管理器中启用域后,它立即开始跟踪。

I think this is probably a bug. 我想这可能是一个错误。 Hopefully they will fix. 希望他们能解决。

I found out in my case that my content blocker (Wipr on Safari) was blocking the tracking request. 我发现我的内容拦截器(Safari上的Wipr)阻止了跟踪请求。 Disabling the content blocker fixed this. 禁用内容拦截器修复此问题。

add a type="text/javascript" to your code 在代码中添加一个type =“text / javascript”

  <script type="text/javascript" >
    (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-XXXXXXXX-X', 'auto');
    ga('send', 'pageview');
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM