-
-
Save paulca/b6f7ebf6fa31b4b142567787d76efbd4 to your computer and use it in GitHub Desktop.
Tito gtag.js plugin
This file contains 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
export default function () { | |
console.info("[tito][gtag]", "plugin loaded"); | |
window.dataLayer = window.dataLayer || []; | |
function gtag() { | |
dataLayer.push(arguments); | |
} | |
window.tito = | |
window.tito || | |
function () { | |
(tito.q = tito.q || []).push(arguments); | |
}; | |
tito("on:registration:started", function (registration) { | |
console.info("[tito][gtag]", "tracking registration started"); | |
const items = []; | |
registration.line_items.forEach(function (item) { | |
items.push({ | |
id: item.id, | |
name: item.title, | |
price: item.price, | |
category: registration.event.title, | |
brand: registration.account.name, | |
}); | |
}); | |
const eventData = { | |
items: items, | |
coupon: registration.discount_code, | |
}; | |
gtag("event", "begin_checkout", eventData); | |
}); | |
tito("on:registration:finished", function (registration) { | |
console.info("[tito][gtag]", "tracking registration finished"); | |
const items = []; | |
registration.line_items.forEach(function (item) { | |
items.push({ | |
id: item.id, | |
name: item.title, | |
price: item.price, | |
category: registration.event.title, | |
brand: registration.account.name, | |
}); | |
}); | |
const eventData = { | |
transaction_id: registration.slug, | |
affiliation: registration.source, | |
value: registration.total, | |
currency: registration.currency, | |
tax: registration.tax, | |
items: items, | |
}; | |
gtag("event", "purchase", eventData); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment