Created
May 16, 2019 09:44
-
-
Save jsn789/31d64913ce34dccd7ebffccfdc2efc93 to your computer and use it in GitHub Desktop.
customTask to duplicate hits for a specific domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function() { | |
//Credit to Simo Ahava | |
//https://www.simoahava.com | |
var url = {{Page URL}} | |
if(url == "specific domain you are interested in") | |
{ | |
// Replace newTrackingId value with the UA property to which you want to duplicate hits | |
var newTrackingId = 'UA-XXXXX-Y'; | |
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); | |
sendModel.set('hitPayload', hitPayload.replace(trackingId, newTrackingId), true); | |
window[globalSendTaskName](sendModel); | |
}); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment