Campaign Tracking in Google Analytics

Everyone attempts to market their blog. Some for money, some simply for personal satisfaction. While I’m really not serious about marketing my blog from a business perspective, I do have to say that the fact that I have had complete strangers comment on my blog has really been fun! And thus far, there have been some pretty good discussions!

Google Analytics — Tracking Website Visitors

With that said, most of us are tracking, to some degree or another, the people visiting our sites. And for most of us who don’t want to invest huge dollars into a custom analytics system, this means we’re using Google Analytics.

This tool is great. It tells me where my visitors come from (48 different countries over the past month), how long the average visitor spends on my site (around 2 minutes and 18 seconds) and what search keywords people are using to get here. It also tells me that 76% of my traffic is from people searching the Internet and just stumbling across my site. Plus, hundreds of other statistics that can be really useful of you know what you’re looking for.

Another key use for Google Analytics is to track advertising campaigns. Essentially, if you’re paying the big bucks to advertise your site, you want to know how many visitors are being generated by those ads. This allows you to track how much money you’re spending per click to your site.

Tracking Social Media Campaigns

So how does this apply to me? I’m not spending tons of money on advertising. However, I am attempting to spread the word about my new blog updates. Therefore, when I update my blog, I alert people on my Twitter channel. This is fine and I do know that some people are clicking on these links. However, how many people?

This is where Google Analytics comes in. If you include tracking information as arguments to the URL you spread around, you can track how many people are visiting and where they’re coming from.

For example, if a page has the original URL of: I could just pass this link around and watch the visitors roll in. However, looking through the Google Analytics Documentation, you find that you can write the link as follows:

This works great and will log the visit under the Campaign “Tweets”, log the Medium as “referral” and log the source as “twitter”. This makes it very easy for the blogger to see exactly where their traffic is coming from. But there are a couple issues here.

First, both of the above URLs given above link to the same page. This is very bad for search engines. They don’t like to see two URLs with the same content. What’s more, the search ranking for each page will be lower since it might be shared between two or more URLs. Really not good since this will make my pages rank even lower.

This problem doesn’t just apply to campaign tracking. WordPress, by default, has archives for posts sorted by Author, Category, Tag, etc… One post will appear in all of these different archives and, have a different URL depending on where it appears. Again, not good.

Canonical <Link /> Tag

Due to the above problems with search engines indexing duplicate content, Google recently published this article about a new tag being used to help solve this problem. The idea is that if you specify a canonical URL (the URL you want indexed), search bots have the option of indexing that URL instead of the problematic, argument riddled URLs.

Unfortunately, many search bots aren’t using these correctly. Dave Naylor, a leading SEO and web developer, noted this problem here. It seems that he’s having all sorts of indexing problems by Google, Bing and Yahoo — the big three search engines.

This isn’t good!

Solution Options

This isn’t a trivial problem for those attempting to perform any sort of Search Engine Optimization (SEO) on their site. The web design website jane and robot discusses the possible options in this post. This article does a much better (and more detailed) job of discussing all the possible issues and solutions.

My Solution: Hash Tags

So. What exactly is a hash tag? Essentially, hash tags allow a web designer to link directly to a specific location on a page. More information can be found here.

The beauty of this is that search engines don’t index hash tags since they are supposed to link within the page. Therefore, anything specified in a hash tag is completely ignored. Good for search engines, and in this case, good for us.

So, what I want is a URL that looks like this:

Notice the part in bold? Since all my tracking data is encapsulated in a hash tag, I no longer have to worry about whether or not the URL is indexed properly in search engines. However, there is the problem that Google Analytics doesn’t look at hash tags by default. Bummer!

The obvious solution is to write some form of Javascript to parse the hash tag and report the campaign information. However, I’m not that good with Javascript. So I did what I’m good at… reading. Looking through the Google documentation, there is an option to tell Google Analytics that it should read the hash tag! Could it really be this simple?

Google’s _setAllowAnchor Function

According to the Analytics documentation (here), it is possible to use the _setAllowAnchor() which “Allows the # sign to be used as a query string delimiter in campaign tracking.” Please note. As of writing this, their example on the help page is incorrect. It instructs the user to replace the ampersands with the ‘#’ operator. From what I’ve found, this doesn’t work. Instead, replace the initial ‘?’ with the hash sign and everything seems to work okay.

To implement this, find the following code on your site.

var pageTracker._gat._getTracker(’UA-xxxxxx-x’);

The ‘UA-xxxxxx-y’ string is your unique Analytics Key (identifier to tell Google what site is being tracked). Please note that on most WordPress themes this code is found in the footer code file. Change these lines to:

var pageTracker._gat._getTracker(’UA-xxxxxx-x’);

I’ve been experimenting with this now for a while and it appears everything works as expected! If I have any more issues (or successes), I’ll follow up this post with more details.

7 thoughts on “Campaign Tracking in Google Analytics”

  1. Advantageously, the article is really the greatest on this worthy topic. I concur with your conclusions and will thirstily look forward to your next updates. Saying thanks will not just be enough, for the tremendous clarity in your writing. I will directly grab your rss feed to stay informed of any updates. Genuine work and much success in your business efforts!

  2. Hi i read your article and found exactly what I was looking for. You go on to explain all details in a very clear manner. thank you. I Also know that this article was written well over 2 years ago, so not everything might still be valid. I was wondering whether your solution worked and if it is still valid. I would love some feedback.

Comments are closed.