- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
02-27-2018 05:52 AM
Hi,
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; console.log(newTrackingId); 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'); window[globalSendTaskName](sendModel); console.log('in duplication hit part'); sendModel.set('hitPayload', hitPayload.replace(trackingId, newTrackingId), true); window[globalSendTaskName](sendModel); }); }; }
Hope someone knows how I can fix this.
Thanks in advance!
02-28-2018 04:02 AM - last edited on 02-28-2018 06:25 AM by kathleen_jo
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 u.data.set 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 u.data.set. 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
Cheers,
Copyright All Rights Reserved © 2008-2023