Wednesday, February 6, 2013

How to Track Outbound Links using Google Analytics

Outbound Links Tracking For sure you have some outbound links in your website going to other websites for various reasons. We sometimes cite other websites as sources of fun, information, or attribution, etc. You can track which outbound links are clicked by your users by adding a short, simple code in your Google Analytics Tracking code. Where are you Going? For sure you'd like to see where your visitors are headed to after they've been through your website. Tracking where all your outbound traffic is headed can tell you which outbound links are doing well in your website and which are not. Here's the code to track all outbound links in your website:
<script type="text/javascript"> var a = document.getElementsByTagName('a'); for(i = 0; i < a.length; i++){ if (a[i].href.indexOf(location.host) == -1 && a[i].href.match(/^http:///i)){ a[i].onclick = function(){ _gaq.push(['_trackEvent', 'outgoing_links', this.href.replace(/^http:///i, '')]); } } } </script>
What this code does is it gets all your <a> tags (which is what your links are made out of) and appends an onClick function to it. The onClick function will create an Event Category which will be outgoing_links, and the event action will be the URL. Put this below your Google Analytics Tracking code like this (highlighted in blue):
<!--THIS IS YOUR GOOGLE ANALYTICS TRACKING CODE--> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']); _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> <!--START RECORD OUTBOUND LINKS CODE--> <script type="text/javascript"> var a = document.getElementsByTagName('a'); for(i = 0; i < a.length; i++){ if (a[i].href.indexOf(location.host) == -1 && a[i].href.match(/^http:///i)){ a[i].onclick = function(){ _gaq.push(['_trackEvent', 'outgoing_links', this.href.replace(/^http:///i, '')]); } } } </script> <!--END RECORD OUTBOUND LINKS CODE-->
This should track all your outbound links. You can check this at the Content -> Events section when you go to your Google Analytics account. Google Analytics Events Tracking You will be able to see something like this:

Events Results (Click the Image to Enlarge)

Event Category is the name of the event. In this example, it is the name of my outbound links - if you noticed, I customized my Events Categories giving them names like 'SEO Services SB', 'SEO School SB', 'Facebook Group SB', etc. You can also customize your Event Categories by using the onClick function for Google Analytics Events tracking here. Total Events is the times the Event occurred - in this case, it's the number of times my outbound link was clicked by a user. Unique Events is the times the Event occurred for a Unique IP address - in this case, it's the number of times my outbound link was clicked by a Unique user. Event Value and Avg Value can be set on Goals Settings. As of now, we will not use these. Where are You Going? If you check out my Event Categories, I name my links to my understanding. For example, I append an 'SB' label to my sidebar links to see if they are clicked more often than their in-content or image counterparts. For this timeframe, it strongly suggests that my sidebar links are the most clicked links - particularly my SEO Services link and SEO School link. Most Clicked Links If you want to check your outbound links without the categories simply click the 'outbound-article' Event Category and it should take you to the raw URLs of your outbound links. Outbound Article The results should look like this: Google Analytics Outbound LinksTracking all your outbound links should be a piece of cake. One More Trick When you're tracking site-wide outbound links, you can check which pages prove most effective in compelling your users to click-through. Simply add a secondary dimension like this: Outbound Links Landing Page Dimension Then filter the results such that it won't show you anything but your site-wide links (you should manually put a customized onClick Events Tracking code in your Site-wide links to effectively track them.) First, click on the Advanced Filter link: Google Analytics Advanced Filtering Then Exclude all non site-wide links (Event Category) in my case it is labeled as an 'outbound-article' and an 'outbound-menu' : Advanced Filter for Outbound Links Your Google Analytics should show you data that looks like this: Sitewide Links Landing Page This data tells me on which landing page has any of my site-wide links have been clicked. This is especially helpful if you are testing sidebar ads, banners, links or email signup forms. Tips for Keeps: Implementing this Google Analytics Outbound Links Tracking code is a piece of cake - paste the code beside your Google Analytics Tracking code to start gathering your outbound user activity data. via seo-hacker.com

Posted via email from h3sean's posterous

No comments:

Post a Comment