Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Last active October 28, 2020 19:43
Show Gist options
  • Save THEtheChad/1380b485650eb476d90bd0350de1714a to your computer and use it in GitHub Desktop.
Save THEtheChad/1380b485650eb476d90bd0350de1714a to your computer and use it in GitHub Desktop.
(function (w) {
var uuid = 'capture_xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'.replace(
/[xy]/g,
function (c) {
var r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
}
);
w[uuid] = function (cmd, data) {
if (!/test/.test(cmd)) return;
dataLayer.push({
event: 'purchase',
transactionId: data.id,
transactionTotal: data.cost,
transactionProducts: []
});
};
var matches = document.body.innerHTML.match(/ga\([^)]*\)/g);
var i = matches.length;
while (i--) {
var match = matches[i];
var code = match.replace(/^ga/, uuid);
eval(code);
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment