Set up an Universal Analytics roll-up property using Javascript

Antoine Tissier
3 min readNov 29, 2021

What is a roll-up property ?

Imagine you have to implement analytics for an international customer. It owns several hundred of websites (one website / analytics property / domain name per country).

It will be interesting to analyze the aggregated data to see global performance metrics, and drill down to compare brand performance among countries.

This is the purpose of roll-up properties. A roll-up property aggregates data from multiple account properties.

If you track a website set up for serveral european countries (with serveral dedicated domains),it may be really interisting to set up a roll up property in order to aggregates analytics data from all the european properties.
If you track a website set up for serveral european countries (with serveral dedicated domains),it may be really interisting to set up a roll up property in order to aggregates analytics data from all the european properties.

Roll-up properties exist in other Digital Analytics solutions (such as Adobe Analytics).

If you want to set up a standard roll-up property using Google Analytics 360, you can have a look at the Google Analytics official documentation.

Why should I set up a roll-up property in javascript ?

Using Google Analytics, you can officially only set up a roll-up property if you have Google Analytics 360. Indeed, users of the free version cannot set up such a property the standard way.

Moreover, roll-up properties cannot aggregate hits that do not belong to the same Google Analytics account.

How to implement a roll-up with Javascript ?

You need to declare a function that will enable you to forward all your GA hits to the roll-up property. This is the intent of the “gaRollup” function bellow :

window.gaRollUp = function() { 
var b = arguments[0] , e = arguments, c = arguments;
e[0] = "Local." + b;
window.ga.apply(window, e);
c[0] = "International." + b;
window.ga.apply(window, c);
};

Before any use of this function, you will have to create the trackers. In this example, the markers had been named”Local” (for the local property), and the “International” property (the roll-up property).

ga('create', 'UA-XXXXX-Y', 'auto', {name='Local'});
ga('create', 'UA-XXXXX-Y', 'auto', {name='International'});

Rather than using the usual “ga” function, you will have to use the “gaRollUp” function to send GA hits to these two properties.

For instance, the javascript code below :

gaRollUp('set', 'dimension1', 'homepage');
gaRollUp('send', 'event', 'lorem', 'ipsum', {eventValue:2});
gaRollUp('send', 'pageview');

will send Javascript hits to both the “local” property and the “international” (roll-up) property.

Mind the property configuration : dimensions, metrics, content grouping should be set up exactly the same in the different properties.

There is another method for this : you can also write your own roll-up plugin. This trick has been explained in the great blog post of Simo Ahava.

And with Google Tag Manager ?

Usual way

It is very easy to set-up if you use custom HTML tags.

Thus, it not that easy to set-up a roll-up propery using the official Universal Analytics Tags. Moreover, you cannot set up a custom analytics plugin inside Universal Analytics tags of GTM.

Sometimes, people duplicate Universal Analytics tags (pageview, events…) to create a roll-up,but in my opinion, the setup is then harder to maintain. I do not recommend it.

Using the new API task

A new API has been released recently, to redefine the behavior of analytics.js (for instance, the way GA hits are sent).

This API can be used with Universal Analytics tags in Google Tag Manager.

For this, you have to declare a custom javascript variable. I named it “GA sendHitTask Rollup”.

function() {
return function(model) {
var originalSendTask = model.get('sendHitTask');
model.set('sendHitTask', function(sendModel) {
originalSendTask(sendModel);
sendModel.set('hitPayload', sendModel.get('hitPayload').replace({{gaProperty}}, {{gaRollupProperty}}), true);
originalSendTask(sendModel);
});
}
}

“gaProperty” et “gaRollupProperty” variables contains respectively the property identifier (UA-XXXX-Y) of the local property and the roll-up property.

This function will send the google analytics hits to the local property, and then to the roll-up property.

To be honest, this code has been copied and paste from a blog post of Simo Ahava.

Once the “GA sendHitTask Rollup” variable has been created, you need to set up the “Google Analytics settings” variable and assign customTask” to the “GA sendHitTask Rollup” function.

The reguired GTM setting to implement the roll-up
The reguired GTM setting to implement the roll-up

Now all the Universal Analytics hits will be sent to two different properties : the usual (local) one, and the roll-up property.

--

--