Google Analytics

Internal Campaign Tracking With Google Analytics

Learn how to implement internal website campaign tracking with Google Analytics

Many sites nowdays self promote content deep within from the home page. In many ways this should be considered an internal campaign. On larger websites with multiple stakeholders involved, it becomes even more important to measure how successful internal campaigns are peforming. By default Google Analytics has the ability to track external campaign links pointing to your website, however it does not come with built in functionality to track internal campaigns.

One solution is to use custom variables to track internal campaigns. By using these campaign variables, you can slice and dice your visitor's movement on your website easier. If you're not familiar with campaign link tagging I suggest you click through a couple links in your RSS feeds (Slashdot, specifically uses them) and you'll notice that there are several query strings appended to each link.

Example Tagged Link:

http://science.slashdot.org/story/10/07/14/2222239/The-Chicken-May-Have-Come-Before-the-Egg?from=rss&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Slashdot%2Fslashdot+%28Slashdot%29&utm_content=Google+Reader

Each of these query strings translates into a dimension in Google Analytics. Below is the anatomy of our URL:

&utm_source=feedburner &utm_medium=feed &utm_campaign=Feed%3A+Slashdot%2Fslashdot+%28Slashdot%29 &utm_content=Google

I'm not going to go into too much depth on the built in external campaign tracking for Google Analytics since that's been covered by every blogger in existence already. Google provides an quick and easy form with explanations for each query string value here anyway - http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55578

Using utm_* Query Strings For Internal Campaign Tracking?

NO! Never do this! I suspect many people first consider this when attempting to track internal campaigns but here's why you shouldn't. Each of these query strings is written to a cookie within Google Analytics. If a user searches "Internet Explorer hacks" on Google the following would happen:

utm_source = google.com utm_medium = google / organic If you custom 'tagged' an internal link you'd essentially overwrite the existing utm_source & utm_medium data with your new data thus loosing the original source of the users visit. This is very very bad.

Enough Already, Just Tell Me How To Do This!?!?

Ok, sorry for the long intro but I needed to get that out of the way before moving any further. Instead of using utm_* query strings let's use our own custom query strings, say one that starts with int_

The Following URL:

http://www.yourdomain.com/landingpage/?utm_source=advertiser.com&utm_medium=bannerad&utm_campaign=summerpromotion&utm_content=horizontal

Becomes:

http://www.yourdomain.com/landingpage/?int_source=advertiser.com&int_medium=bannerad&int_campaign=summerpromotion&int_content=horizontal

Hidding Query Strings Within Google Analytics

Next, configure the Google Analytics profile to exclude these new query strings. Otherwise the URLs are going to look different within the reports depending on the refering page and it will render your stats very useless.

  1. Navigate to Analytics Settings > Profile Settings > Edit Profile Information
  2. Under 'Exclude URL Query Parameters:' include the following query strings int_source, int_campaign, int_medium, int_content (or your own)
Hidding Query Strings Within Google Analytics

Configuring Your Google Analytics Tracking Code For Internal Campaigns

Finally, you'll need to slightly modify your tracking code to send these custom variables to Google. This uses Google's pageTracker._setCustomVar function. The names (i.e. Internal%20Campaign) can be named to whatever you like.

<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-XXXXXX-X"); <?php if(isset($_GET["int_campaign"])) echo 'pageTracker._setCustomVar(1,"Internal%20Campaign","'.$_GET["int_campaign"].'",1);'; if(isset($_GET["int_source"])) echo 'pageTracker._setCustomVar(2,"Internal%20Source","'.$_GET["int_source"].'",1);'; if(isset($_GET["int_medium"])) echo 'pageTracker._setCustomVar(3,"Internal%20Medium","'.$_GET["int_medium"].'",1);'; if(isset($_GET["int_content"])) echo 'pageTracker._setCustomVar(4,"Internal%20Content","'.$_GET["int_content"].'",1);'; ?> pageTracker._initData(); pageTracker._trackPageview(); </script>

Further Reading