Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test if a google analytics code works?

I made slight changes to the code described here in order to track outbound link clicks. This is my code:

function recordOutboundLink(link, label) {
  try {
    var myTracker=_gat._getTrackerByName();
    _gaq.push(['myTracker._trackEvent', 'Outbound Links', label, link.href ]);
    setTimeout('document.location = "' + link.href + '"', 100)
  }catch(err){}
}

Then I added it to my href tags like so:

<a href="http://example.com/user/5" onclick="recordOutboundLink(this, 'example.com');return false"></a>

I think it's not working, though. It's really hard to check if it works or not. How do I check if it's working or not?

EDIT: Using google analytics debugger for chrome I was able to see what's going on. It displays:

Account ID               : UA-XXXXX-X

It's odd because normal page tracking is working as expected. This is how I set up google analytics code:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'my-id']);
_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);
})();
like image 438
Rafael Almeida Avatar asked Oct 19 '12 15:10

Rafael Almeida


People also ask

How do I check Google Analytics script?

To see if Google Analytics is firing on your page, go to any page on your site in your Chrome Browser and right-click. Click on Inspect. Then go to the Network tab. Hit refresh on your browser and watch to see the different content and scripts loading on the page.

How do you check if Google Analytics have been successfully installed?

Use Your Debug View Once you have it set up, open your website. Click on the Google Analytics Debugger icon at the top of your browser. Then click “Ctrl-Shift-J” to open the Chrome Javascript console. You can then click “Console” to see information about your Google Analytics code to make sure it's entered correctly.

How do I test events in Google Analytics?

The simplest way to do this is to trigger the event yourself. Then, check Google Analytics to see if the event showed up. You can view your tracked events by clicking “Behavior” in the sidebar and scrolling down to “Events.” Your tracked events can be found under “Behavior” in Google Analytics.

How do you verify that Google Analytics is working immediately after installation?

You want to verify that Google Analytics is working immediately after installation by verifying with Google. Plug-ins such as Yoast SEO on WordPress make this especially easy to execute. If the tag installation process is not working, Google Support recommends using the Tag Assistant to verify the setup.


1 Answers

Look for the __utm.gif tracking pixel request. A few different ways of doing this are:

  • A web debugging proxy like Fiddler (my preference)
  • The Network tab in Firebug or Chrome Developer Tools.
  • The Google Analytics debugging script ga_debug.js will log tracking requests & errors.
  • Google Analytics Tracking Code Debugger is a Chrome extension that enables ga_debug.js.

The analytics code on the page probably has a _trackPageview, so as the page loads you'll see an initial __utm.gif.

When _trackEvent fires, there should be a new __utm.gif request being made. Parameters to examine in __utm.gif URL are:

  • utme=5(Outbound Linkslabellink.href) -- _trackEvent parameters
  • utmac=UA-1234567-8 -- the analytics UID

Also, (as pointed out by @Eduardo), take a look at Google Analytics Basic Debugging

like image 63
mike Avatar answered Oct 14 '22 21:10

mike