SEO Friendly Google Analytics Campaign tracking with Hash Marks

by Peter Voynov on August 16, 2012

hash-mark-campaign-trackingWhen it comes to campaign tracking, Google Analytics is very good at doing that.  Campaign tracking is relatively easy, but in some cases campaign tracking parameters may cause duplicated content problems, so in order to prevent duplicated content problem I recommend adding hash marks.

Original URL: 

http://www.example.com/road-bike.html
URL with campaign tracking parameters
http://www.example.com/road-bike.html?utm_source=google&utm_medium=banner&utm_term=bicycle&utm_content=road&utm_campaign=bike-campaign


The question mark right after the .html makes campaign tracking URL crawlable and if this page is not protected it will get crawled and indexed by all major search engines once it gets exposed.

In order to prevent duplicated content I recommend using a hash mark (#) in the query parameter, instead of a question mark (?). When Google finds a URL with a hash mark (#), it ignores everything after the hash.

Updated Campaign tracking URL
http://www.example.com/road-bike.html#utm_source=google&utm_medium=banner&utm_term=bicycle&utm_content=road&utm_campaign=bike-campaign

Google Analytics to interpret this change correctly you also need to enable Anchor tracking by adding the following line of code to your tracking code

_gaq.push(['_setAllowAnchor',true],['_trackPageview']);

Live example:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
  _gaq.push(['_setAllowAnchor',true],['_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>

If you need help building search engine friendly campaign tracking URLs i recommend using Campaign Tracking URL Builder

About Peter Voynov


Technical SEO & Web Analytics Specialist @ Medseek.com Peter Voynov LinkedIn

  • Sergey Lucktinov

    Great tool, thanks a lot!

  • http://www.facebook.com/lisa.agostoni.5 Lisa Agostoni

    Peter. Great article. So you’re saying that if I use the campaign parameters, I won’t see anything if I don’t modify my GA code onsite? Seems pretty cumbersome.

Previous post:

Next post: