Skip to content

Instantly share code, notes, and snippets.

@jsn789
Created May 16, 2019 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsn789/31d64913ce34dccd7ebffccfdc2efc93 to your computer and use it in GitHub Desktop.
Save jsn789/31d64913ce34dccd7ebffccfdc2efc93 to your computer and use it in GitHub Desktop.
customTask to duplicate hits for a specific domain
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