How to install UTM tracking code? (Uses ga.js)

The UTM (Urchin Traffic Monitor) tracking code is used to track traffic source, medium and campaign; and allows a businesses to track conversion funnel from referral site. With an introduction of Google Tag Manager, some folks are unclear how to implement UTM tracking codes into their HTML pages. The following two simple steps will guide you through installing the UTM javascript snippets into your web pages.

1. Add the classic Google Analytics library, ga.js from Google CDN.

<script src="//www.google-analytics.com/ga.js"></script>

2. Login to your Google Analytics account, and get your GA code snippet.

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-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>

Add ga.js and your Analytics tracking code at the bottom of your HTML page just before the closing </body> tag.

Note: The ga.js is an old classic Google Analytics library, which is different than the newer Universal Analytics (analytics.js). Including the ga.js on your page will not create UTM cookies, but including the latter GA code snippet (particularly ga('create', 'UA-XXXXX-Y', 'auto');)will cause it to create the UTM cookies in client's computer.

Comments

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.