-
Notifications
You must be signed in to change notification settings - Fork 0
/
ga4.js
67 lines (57 loc) · 1.7 KB
/
ga4.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
66
67
(function () {
console.info("[tito][ga4]", "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][ga4]", "tracking registration started");
const items = [];
registration.line_items.forEach(function (item) {
items.push({
item_id: item.id,
item_name: item.title,
price: item.price,
item_category: registration.event.title,
item_brand: registration.account.name,
affiliation: registration.source,
});
});
const eventData = {
items: items,
coupon: registration.discount_code,
value: registration.total,
currency: registration.currency,
};
gtag("event", "begin_checkout", eventData);
});
tito("on:registration:finished", function (registration) {
console.info("[tito][ga4]", "tracking registration finished");
const items = [];
registration.line_items.forEach(function (item) {
items.push({
item_id: item.id,
item_name: item.title,
price: item.price,
category: registration.event.title,
brand: registration.account.name,
affiliation: registration.source,
});
});
const eventData = {
transaction_id: registration.slug,
tax: registration.tax,
coupon: registration.discount_code,
transaction_id: registration.slug,
value: registration.total,
currency: registration.currency,
items: items,
};
gtag("event", "purchase", eventData);
});
})();