customTask for Google Universal Analytics tag

Rookie Contributor


Has anyone ever worked with customTask in Tealium IQ? I'm trying to duplicate a hit send to Google Analytics, but for some reason it doesn't work.

Below the extension I wrote. I've mapped the variable custom_task in my Google Universal Analytics tag to the variable set.customTask:

b.custom_task = setCustomTask();
function setCustomTask() {
	// Replace newTrackingId value with the UA property to which you want to duplicate this tag
	var newTrackingId = b.ua_account_duplicate;
	var globalSendTaskName = '_' + newTrackingId + '_originalSendTask';
	return function(customModel) {
		window[globalSendTaskName] = window[globalSendTaskName] || customModel.get('sendHitTask');
		customModel.set('sendHitTask', function(sendModel) {
			var hitPayload = sendModel.get('hitPayload');
			var trackingId = new RegExp(sendModel.get('trackingId'), 'gi');
		        console.log('in duplication hit part');
		        sendModel.set('hitPayload', hitPayload.replace(trackingId, newTrackingId), true);

Hope someone knows how I can fix this.

Thanks in advance!


customTask for Google Universal Analytics tag

Bronze Contributor
Bronze Contributor

Hi @Stijn,

I've lookup into your problem. There are a few problems. To start with, your newTrackingId variable is scoped to your setCustomTask function only and therefore not available at the moment that the GA object if executing your customTask. You need to scope them to a Window variable: window['newTrackingId']

The next problem is that the default Universal Analytics template does not allow you to set values in the GA object which are a function. Here what happens in the tag template:


In the first image, you see that all the values in are inserted into a function utag.loader.GV(). That one does not allow function as a input type (see the second image). In the third image you can see that the function customTask is indeed defined in In the fourth image, you see a possible solution, you can change this in the UA tag template. In my case it works fine. 

I don't know why Tealium build in this function protection, maybe someone else know? This