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);
})();
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.
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.
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.
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.
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:
Also, (as pointed out by @Eduardo), take a look at Google Analytics Basic Debugging
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With