简体   繁体   中英

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:

 <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".

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. So I don't know why this isn't working. The code above was provided by 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

Have you tried using a tool like HTTPFox (firefox) Google's Google Analytics Debugger (chrome) to monitor http requests? 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. 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

You are using the "Universal Analytics" snippet which is Google's new system they are trying to transition everyone over to. Some of the APIs have changed including event tracking.

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/

I had a similar issue, I was hitting the wrong url, so I am redirecting somedomain.com to www.somedomain.com

see: 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.

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").

Google Tag Manager can only fire tags within the capabilities of the browser. Most browsers will not open more than six to eight HTTP requests to a single domain at a time. 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.

My new Analytics property didn't track for half a day after I added the tracking code. After enabling the domain in Google Tag Manager, it started tracking instantly.

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. Disabling the content blocker fixed this.

add a to your code

  <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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