Created
June 12, 2018 15:59
-
-
Save iosiuk/1024ea6acc471a4e03ba7989b072aeac to your computer and use it in GitHub Desktop.
This file contains hidden or 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 () { | |
return function(tracker) { | |
tracker.set('dimension1', tracker.get('clientId')); | |
var originalSendHitTask = tracker.get('sendHitTask'); | |
tracker.set('sendHitTask', function(model) { | |
originalSendHitTask(model); | |
var hitPayload = model.get('hitPayload'); | |
var cleanupKeys = ['_v', 'a', '_s', '_u', 'je', '_u', 'jid', 'gjid', '_gid', 'gtm', 'z', 'v', 'tid', '_r']; | |
var fbHitPayload = {}; | |
decodeURI(hitPayload).split('&').forEach(function(pair) { | |
var keyValue = pair.split('='); | |
if (cleanupKeys.indexOf(keyValue[0]) === -1) { | |
fbHitPayload[keyValue[0]] = decodeURIComponent(keyValue[1]); | |
} | |
}); | |
var fbEventName = fbHitPayload['t']; | |
delete fbHitPayload['t']; | |
if (fbEventName == 'pageview') { | |
fbq('trackSingle', {{FB Pixel ID}}, 'PageView', fbHitPayload); | |
} else { | |
fbq('trackSingleCustom', {{FB Pixel ID}}, 'GA_'+ fbEventName, fbHitPayload); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment