I’m again with one other customTask
tip, however this time I’m exploring some new territory. Snowplow simply launched their newest model replace, which included (amongst different issues) an adapter for processing Google Analytics payloads. By no means heard of Snowplow? It’s a group of open-source libraries designed to allow you to construct your personal analytics pipeline, all the way in which from information assortment, via ETL (extract, remodel, load), utilizing customized enrichments and JSON schemas, and eventually into your personal information warehouse, the place you possibly can then analyze the information utilizing no matter instruments you discover preferable. The whole lot is designed to run over Amazon Internet Companies, so that you don’t have to put money into native server {hardware} or internet hosting companies.
In essence, it’s a full-service, do-it-yourself analytics answer. Snowplow has deservedly gained a number of momentum over the latest years, as an increasing number of firms have matured to the purpose the place they need full management of their information. And I don’t simply imply information possession, but additionally issues like controlling the aggregation schemas which have confirmed to be slightly inflexible in Google Analytics, and being in full cost when and the way the information is sampled and normalized.
Anyway, in some unspecified time in the future I’ll creator a correct article about Snowplow – one which it deserves. This time I’m simply going to point out you learn how to setup the Google Analytics duplicator / tracker, in an effort to begin gathering hits in your Snowplow pipeline by merely leveraging the payload generated and picked up by Google Analytics.
X
The Simmer E-newsletter
Subscribe to the Simmer publication to get the most recent information and content material from Simo Ahava into your electronic mail inbox!
Tip 70: Duplicate Google Analytics payload to Snowplow
If you happen to learn the launch announcement, you may need observed that the discharge is basically a Google Analytics plugin, which is straightforward so as to add if you happen to’re utilizing the analytics.js monitoring snippet.
Sadly, with Google Tag Supervisor there isn’t any dependable approach to load a plugin in your Google Analytics tags. Which means you’re left with clumsy workarounds, equivalent to
-
A Customized HTML tag which you utilize to load analytics.js and create a tracker with the plugin.
-
Some
customTask
hack the place you load the plugin mid-hit.
The primary one is unwieldy since you would then have to have all your tags use the identical tracker identify if you happen to needed all of them to duplicate the payloads to Google Analytics.
The second merely doesn’t work. Even if you happen to do handle to load the plugin within the tracker, Google Analytics wouldn’t cease to attend for the plugin to be registered, however would merely ship the hit earlier than the plugin has had time to connect and modify the tracker object itself.
So on this tip, we’re simply going to skip the plugin altogether, and replicate its performance utilizing customTask
.
To make all of it work, create a brand new Customized JavaScript variable, identify it one thing like {{customTask – Snowplow duplicator}}, and add the next code inside:
perform() {
// Add your snowplow collector endpoint right here
var endpoint = 'https://collector.simoahava.com/';
return perform(mannequin) {
var vendor = 'com.google.analytics';
var model = 'v1';
var path = ((endpoint.substr(-1) !== '/') ? endpoint + '/' : endpoint) + vendor + '/' + model;
var globalSendTaskName = '_' + mannequin.get('trackingId') + '_sendHitTask';
var originalSendHitTask = window[globalSendTaskName] = window[globalSendTaskName] || mannequin.get('sendHitTask');
mannequin.set('sendHitTask', perform(sendModel) {
var payload = sendModel.get('hitPayload');
originalSendHitTask(sendModel);
var request = new XMLHttpRequest();
request.open('POST', path, true);
request.setRequestHeader('Content material-type', 'textual content/plain; charset=UTF-8');
request.ship(payload);
});
};
}
Then it is advisable edit each single Google Analytics tag whose information you additionally wish to ship to Snowplow.
At this level, if you happen to haven’t finished so but, it’s a good suggestion to utilize the Google Analytics Settings variable. As an alternative of getting to switch each single tag, you solely have to make the mandatory change (see under) within the GAS variable, after which you’ll add that GAS variable to all of your Google Analytics tags. Helpful!
Anyway, the change it is advisable make is below Extra Settings / Fields to set of your Google Analytics tags or the Google Analytics Settings variable. If you happen to’re modifying tags straight, you’ll have to test the “Allow overriding settings on this tag” choice to see the Extra Settings fields. Right here’s the sector it is advisable add.
Discipline identify: customTask
Worth: {{customTask – Snowplow duplicator}}
Bear in mind – the change must be finished in all the Google Analytics tags whose information you wish to fork to Snowplow.
Observe! On the time of writing, solely the Clojure Collector in Snowplow helps the Google Analytics adapter. Hopefully they’ll launch help for the Scala Stream Collector quickly, because it will provide you with entry to that candy, juicy Google Analytics real-time information! Be sure you comply with the Snowplow dialogue discussion board – it’s place as any to get data on the roadmap.
This can be a fairly candy addition to Snowplow, as a result of it helps you to function with parameters and values which can be acquainted to you, if you happen to’ve used Google Analytics earlier than. It additionally helps you to leverage present Google Analytics monitoring, so that you don’t have to rewrite the monitoring setup in your website simply emigrate to Snowplow.