Categories: googleanalytics

How to create a Rollup property with Google Analytics Universal tracking code – (General and Event Tracking)

A client requested a Rollup account to aggregate all the stats into one property from multiple sites. The general context was that each region (e.g. UK, Spain, France, Australia, South Africa, Canada, US etc) were given a regionalized page (each with a unique property ID in GA) and all general metrics as well as Custom Event tracking for all assets will be “rolled-up”/aggregated into one main property to make reporting easier.

A diagram of the general concept is below:

 

I don’t want to go into the basics (property setup) as there is nothing really unique about the actual administration of the account, but rather, I want to focus more on a working example of the JS code required to get this to work with GA’s Universal Analytics code.

But as starters, my “Landing Page Account” (i.e. the general account) contained the following properties (I’ve cut the number down to 2 properties for simplicity sake, but I had 13 regions pushing to the rollup when it was live):

  • Main Rollup Property – (UA-XXXXXXXX-1)
  • UK’s Page Property – (UA-XXXXXXXX-2)
  • Canada’s Page Property – (UA-XXXXXXXX-3)

Please note that the rollup property had a fictitious URL in the “Default URL” in my property settings (the Rollup property, in actuality, is virtual and has no URL as it just aggregates data). This did not affect data collection at all.

What I need to do – General Tracking

The key to tracking multiple properties with the same GA snippet is to create a second tracker and assign a new name to reference it (I called this tracker “t_global”). Once the reference is created, you can then call functions with this tracker name (Line 10).

As you can see, the following code was posted on the “UK” website. On Line 8, it just associates the default tracker with “UA-XXXXXXXX-2” (UK’s unique GA property ID) and assigns the Rollup property “UA-XXXXXXXX-1” (the rollup’s GA property ID) to a tracker named “t_global” (Line 7).

  1. <script>
  2. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  3. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  4. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  5. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  6.  
  7. ga('create', 'UA-XXXXXXXX-1', {'name': 't_global'});
  8. ga('create', 'UA-XXXXXXXX-2');
  9.  
  10. ga('t_global.send', 'pageview');
  11. ga('send', 'pageview');
  12.  
  13. </script>

That’s it for one property. If we wanted to add Canada’s site to the rollup we’d change Line 8 to “UA-XXXXXXXX-3” (Canada’s unique GA property ID)

  1. <script>
  2. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  3. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  4. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  5. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  6.  
  7. ga('create', 'UA-XXXXXXXX-1', {'name': 't_global'});
  8. ga('create', 'UA-XXXXXXXX-3');
  9.  
  10. ga('t_global.send', 'pageview');
  11. ga('send', 'pageview');
  12.  
  13. </script>

From there the sites should be sending data in to their regional property as well as the aggregated rollup account.

What I need to do – Event Tracking

My actual implementation on the live sites was far more complex and I had to create a custom library to manage all the content, links and assets, but the general idea around how we’d implement event tracking is below.

There is nothing really special beyond using the default and “t_global” tracker references to call the typical event tracking functions, but to make it a bit more concrete. If we wanted to track a PDF that opened up in a new window we’d have the following code:

Sample HTML link on a page:

  1. <a href="http://mysite.com/myfile.pdf" target="_blank" onclick="trackEvent('thecategory','theaction','labelofthepdf')">Read my PDF</a>

JavaScript function that will call GA’s event tracking function:

  1. <script>
  2. function trackEvent(category, action, label){
  3. ga('send', 'event', category, action, label);
  4. ga('t_global.send', 'event', category, action, label);
  5. }
  6. </script>

It’s as easy as that. I’d recommend attaching these events programmatically (maybe with the help of jQuery or your favorite JS framework or selector engine to get the job done) and also doing some checks to ensure that GA is loaded before calling these functions. Nevertheless, at heart, all that is needed is a reference to the “t_global” tracker as well as the default one and call both function to send the corresponding data to each property.

The previous JS snippet can be placed on every regional site without having the need to be modified. This is because the GA code is already customized for each region and rollup property (i.e. has the unique ID assigned to the default tracker and the rollup property ID attached to “t_global” – recall the UK and Canada snippets we produced earlier).

References: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#name and https://developers.google.com/analytics/devguides/collection/analyticsjs/events

Farmer

Share
Published by
Farmer

Recent Posts

Changing the Facebook “tr” endpoint to send Facebook Events to another URL (GTM Server-Side – Conversion API)

As a caveat this is an **unofficial** way of achieving this as of this article's…

3 years ago

Facebook Business Manager Verification – “Start Verification” Button Disabled!?

There are many benefits to verify your Business Manager on Facebook; however, it is not…

5 years ago

Adding the Facebook Pixel to a GTM AMP Container

One issue when adding the Facebook pixel to a Google Tag Manager AMP container is…

6 years ago

Installing dependencies to get Puppeteer 1.0 running on Ubuntu 16.04

When trying to run Puppeteer 1.0 within your Node.JS scripts on an Ubuntu 16.04 box and…

6 years ago

API Rate-Limiting with Lumen 5.6 and Illuminate Routing/ThrottleRequests Class

Off the back of this article, there could be some potential improvements to make the…

6 years ago

How to use the Facebook img tag to fire pixel events

Before implementing the img tag, the previous article should be reviewed: it discusses some of…

6 years ago