-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtag.js
65 lines (56 loc) · 1.65 KB
/
gtag.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function () {
console.warn(
"The Google Analytics gtag plugin is deprecated. Please use the ga4 plugin instead.",
"https://ti.to/docs/api/widget/#tito-widget-v2-plugins"
);
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);
});
})();