Simple Tracker Duplication For Universal Analytics


First of all, I’m sorry about the title. I should really stop throwing the word “simple” around, since people always tell me that the stuff I claim to be easy and straightforward is rarely so. But since this is my blog, I reserve the right to use whatever stupid and misleading terminology I want. I maintain that what follows IS quite simple, especially when considering the amount of complexity it reduces in your Universal Analytics setup.

Next, I want to direct your gaze to my latest Keynote / PowerPoint creation:

This piece of art is called “…while waiting for the cosmos”. Note the enigmatic ellipsis in the beginning, the lack of capitalization, and the fact that the title has nothing to do with the image. Yes, friend. This is post-post-modernism at its best!

So, I guess my amazing art kind of gave away what I want to show to you in this article. In short, it’s a simple little plugin I’ve been using in projects I work on, which duplicates all hits sent to a Google Analytics property. These duplicated hits are sent to another Google Analytics property, whose property ID you specify when initiating the plugin.

This tutorial uses a Universal Analytics plugin (d’oh), which, in turn, utilizies the Tasks API.

Before I proceed, I want to direct you to David Vallejo’s blog, where he and a bunch of other people are working together on an open-source project which does similar stuff, but on a WAY more configurable level. The plugin I’m about to walk you through will simply make an exact duplicate of the hit you sent, without letting you modify the payload one bit.

Why, you may ask? Well, a surprisingly large number of projects I work with have a need for a “rollup” property, which collects data from all sites in the organization. The data sent to the rollup often mirrors whatever is collected in the local sites. It’s quite a chore to duplicate send commands across all trackers, so if the project is fine with simple duplication, I use this plugin.

CAVEAT: This will best work with named trackers. Thus Google Tag Manager setting this up in Google Tag Manager is difficult, as you’ll have to mess with the Tracker name field. If you’re confident with your GTM implementation skills, feel free to do whatever you wish, of course. Nevertheless, in its current state, the plugin caters best to an on-page Universal Analytics implementation.


X


The Simmer Newsletter

Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava into your email inbox!

Modifying the tracking code

For this to work, you will need to make a small change to your Universal Analytics tracking code. Let’s say the code looks like this now:

script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-12345-1', 'auto');
  ga('send', 'pageview');
script>

You’ll need to add the following modification:

script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-12345-1', 'auto');

  // ADD THIS LINE:
  ga('require', 'simolatorDuplicator', {'newId' : 'UA-12345-2'});

  ga('send', 'pageview');
script>

There’s a single addition: ga('require', 'simolatorDuplicator', {'newId' : 'UA-12345-2'});. This line invokes a plugin called simolatorDuplicator (I know! The awesomest plugin name in the UNIVERSE!), after which you pass an object with a single key-value pair: {newId : newTrackerId}. In place of newTrackerId, you place a String with the Google Analytics property ID to which you want to duplicate all the hits.

The plugin itself

There are two quick and easy (sorry about those words again) ways to load the plugin. Either host it in its own JavaScript file which you then load with a

We will be happy to hear your thoughts

Leave a reply

Som2ny Network
Logo
Compare items
  • Total (0)
Compare
0