Skip to content

Instantly share code, notes, and snippets.

@iosiuk
Created June 12, 2018 15:59
Show Gist options
  • Save iosiuk/1024ea6acc471a4e03ba7989b072aeac to your computer and use it in GitHub Desktop.
Save iosiuk/1024ea6acc471a4e03ba7989b072aeac to your computer and use it in GitHub Desktop.
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