Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Chris Beardsley
Added: Jun 7, 2018 7:57 AM
Views: 29
Tags: no tags
Change tracking ID
  1. function() {
  2.   var newTrackingId = 'UA-2332505-20';  
  3.   var globalSendTaskName = '_' + newTrackingId + '_originalSendTask';
  4.   return function(customModel) {
  5.     window[globalSendTaskName] = window[globalSendTaskName] || customModel.get('sendHitTask');
  6.     customModel.set('sendHitTask', function(sendModel) {
  7.       var hitPayload = sendModel.get('hitPayload');
  8.       var trackingId = new RegExp(sendModel.get('trackingId'), 'gi');
  9.       window[globalSendTaskName](sendModel);
  10.       sendModel.set('hitPayload', hitPayload.replace(trackingId, newTrackingId), true);
  11.       window[globalSendTaskName](sendModel);
  12.     });
  13.   };
  14. }