Automatically Tracking Downloads and Outbound Links

The following post outlines one method for achieving automatic download and outbound link tracking for Google Analytics.

Although manually tagging files and links is the best way to track your downloads and outbound links, it is not very practical. Tagging more than a handful of links becomes painful.

Okay, so what are the downsides to automatic tracking?

  • The JavaScript required to modify the links is going to add to the loading time of your site.
  • If you have many, many files or links on a page it is going to take time for the script to run through your page and apply the tags to each file or link.


Quick steps:
  1. Download the following file (gatag.zip), unzip it and upload it to your server (in this example we have uploaded it into a folder called /javascript/).
  2. Place the following code above your Google Analytics Tracking Code:
<script src="/javascript/gatag.js" type="text/javascript"></script> 

This script only works for the ga.js Google Analytics Tracking Code, if you are still using urchin.js you will need to update this first.

This script was originally developed by Goodwebpractices.com with the help of ShoreTel, MerryMan and Colm McBarron. Our version has had some slight modification from VKI Studios and ourselves, Mangold Sengers.

Your Google Analytics Tracking Code should now look something like this:

<script src="/javascript/gatag.js" type="text/javascript"></script> 
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-123456-1");
pageTracker._trackPageview();
} catch(err) {}
</script>

Check your Google Analytics reports in 12 to 24 hours to ensure that file downloads and outbound links are tracking correctly. You should see your downloads and links being tracked into the Top Content and Content Drilldown reports e.g. /downloads/path-to-file/file.pdf and /outbound/www.externalsite.com/index.html

(Please note that this post outlines the tracking required for a standard Google Analytics installation, if you are tracking multiple domains or doing any advanced tracking you should consult your Google Analytics provider or get professional Google Analytics support.)

Labels: ,

Share

Google Analytics and SEO

Fixing Campaign Tagged URLs for Improved SEO

While attending the 2008 GAAC Summit at the Googleplex Robbin Steif of Lunametrics raised an interesting point regarding URLs that have Google Analytics campaign tags. Robbin pointed out that campaign tagged URLs can adversely effect SEO (Search Engine Optimization) as a result of duplicate content and that the _setAllowAnchor(true) function can be used to alleviate the problem.

Google Analytics and SEO Search Results

Okay, great, but can you repeat that in English?

Basically, Google sees a page on your site and campaigned tagged URL for the same page as actually being two separate pages. Then when we come to SEO, websites and pages can be given lower priority if there is duplicate content.

We have a landing page about being a Google Analytics Authorized Consultant: www.mangoldsengers.com/google-analytics-authorized-consultant

And we have a campaign tagged link to the same page on the Google Analytics partner page that looks like this: www.mangoldsengers.com/google-analytics-authorized-consultant?utm_source=gaac-listing&utm_medium=referal&utm_campaign=google-analytics

Although these are the same page Google sees them as two separate pages, so now the question is how do I fix the problem?

How to Fix Campaign Tagged URLs for SEO

Luckily, Google doesn't index anything after a # in a URL, so basically we need to change this: www.mangoldsengers.com/google-analytics-authorized-consultant?utm_source=gaac-listing&utm_medium=referal&utm_campaign=google-analytics to this: www.mangoldsengers.com/google-analytics-authorized-consultant#utm_source=gaac-listing&utm_medium=referal&utm_campaign=google-analytics

Google does not index anything after a destination anchor (i.e. the #), so now: www.mangoldsengers.com/google-analytics-authorized-consultant and www.mangoldsengers.com/google-analytics-authorized-consultant#utm_source=gaac-listing&utm_medium=referal&utm_campaign=google-analytics will be seen as the same page by Google. No more duplicate content!

Now that you have fixed the URLs, we need to get the campaign variables into Google Analytics. This is simply achieved by using the _setAllowAnchor(true) function that Robbin mentioned at the summit.

Your GATC (Google Analytics Tracking Code) will need to be modified (you will need to replace UA-XXXXXXX-X with your Google Analytics profile ID):

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._setAllowAnchor(true);
pageTracker._trackPageview();
} catch(err) {}</script>

If you have any questions or need help implementing SEO friendly campaign tags for Google Analytics then please get in touch!

Labels: , , ,

Share

Updated Google Analytics tracking code (ga.js)

Google has updated the ga.js tracking code due to a number of problems Google Analytics users were experiencing. The initial release of the new Google Analytics Tracking Code (GATC) prevented websites from validating, did not publish correctly within Blogger templates and the new code did not work with ASP websites. The updated tracking code solves these problems.

Updated version of the ga.js tracking code:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXX-XX");
pageTracker._initData();
pageTracker._trackPageview();
</script>


This updated tracking code does not validate for XHTML Strict websites, however adding CDATA tags solves this problem.

XHTML compliant version of the updated ga.js tracking code:

<script type="text/javascript">
//<![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//]]>
</script>
<script type="text/javascript">
//<!--[CDATA[
var pageTracker = _gat._getTracker("UA-XXXX-XX");
pageTracker._initData();
pageTracker._trackPageview();
//]]-->
</script>


Here is a copy of the tracking code before the update for those of you who are interested.

Previous version of the tracking code:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write("\
\<\/script>" );
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXX-XX");
pageTracker._initData();
pageTracker._trackPageview();
</script>


Thank you to Justin Cutroni who posted about the updated ga.js tracking code and Jason Green who provided the XHTML Strict solution.

Labels: , ,

Share

New Google Analytics Tracking Code (ga.js) released

The new Google Analytics Tracking Code (ga.js) is now live. The new tracking code will give you access to new features as they are released, the first new feature will be Event Tracking.

Key features:
  • Smaller tracking code = faster loading speed
  • Easier to use
  • Automatic detection of HTTPS
  • Required for new features

You will have to replace the legacy tracking code (urchin.js) with the new tracking code on your website. Google has stated that the legacy tracking code will continue to function for at least 12 months from the release of the new tracking code.

The following steps show you how to find the new Google Analytics Tracking Code:

Step 1

Click 'Edit' next to the desired profile.

New Google Analytics Tracking Code ga.js

Step 2

Click 'Check Status' on the Profile Settings page.

New Google Analytics Tracking Code ga.js

Step 3

Replace the tracking code on your website with the new ga.js tracking code.

New Google Analytics Tracking Code ga.js

Labels: , ,

Share