Rafael Almeida
Rafael Almeida

Reputation: 2397

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);
})();

Upvotes: 15

Views: 35940

Answers (6)

pualien
pualien

Reputation: 168

You could use this free chrome extension called Trackie

Upvotes: 0

Gustavo
Gustavo

Reputation: 11

You will also have to make sure that your tag is inserted in all of your pages. Here's a free service that can do that: http://www.tagcheckr.com Hope this helps.

Upvotes: 0

mattdlockyer
mattdlockyer

Reputation: 7314

In Chrome:

  • Right Click anywhere on page
  • Inspect Element
  • Click Network Tab
  • Reload Page

Look for:

  • Type 'image/gif'
  • Method: 'GET'
  • Name (starts with): _utm.gif?

Upvotes: 2

Dave
Dave

Reputation: 19

You can take a look at James for Chrome it's simple and free, we wrote is to debug our internal tool but made it available to all

Upvotes: 0

Rafael Almeida
Rafael Almeida

Reputation: 2397

Using google analytics tracking code debugger which @mike pointed out I was able to figure out that, although http://support.google.com/analytics/bin/answer.py?hl=en&answer=1136920 tells us to use

var myTracker=_gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent', 'Outbound Links', label, link.href ]);

does not longer work, and one should use

_gaq.push(['_trackEvent', 'Outbound Links', label, link.href ]);

instead.

Upvotes: 0

mike
mike

Reputation: 7167

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

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

Upvotes: 20

Related Questions