-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_analytics.js
78 lines (70 loc) · 2.12 KB
/
google_analytics.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
68
69
70
71
72
73
74
75
76
77
78
(function () {
console.warn(
"The Google Analytics plugin is deprecated. Please use the ga4 plugin instead.",
"https://ti.to/docs/api/widget/#tito-widget-v2-plugins"
);
console.info("[tito][google_analytics]", "plugin loaded");
window.ga =
window.ga ||
function () {
(ga.q = ga.q || []).push(arguments);
};
ga.l = ga.l || +new Date();
ga("require", "ec");
window.tito =
window.tito ||
function () {
(tito.q = tito.q || []).push(arguments);
};
tito("on:registration:started", function (registration) {
console.info("[tito][google_analytics]", "tracking registration started");
ga("set", "currencyCode", registration.currency);
registration.line_items.forEach(function (item) {
ga("ec:addProduct", {
id: item.id,
name: item.title,
price: item.price,
quantity: item.quantity,
});
ga("ec:setAction", "add");
});
ga(
"send",
"pageview",
`/tito/${registration.account.slug}/${registration.event.slug}/registrations/${registration.slug}`
);
ga("send", "event", "tito", "registration:started", "Started registering");
});
tito("on:registration:finished", function (registration) {
console.info("[tito][google_analytics]", "tracking registration finished");
ga("set", "currencyCode", registration.currency);
registration.line_items.forEach(function (item) {
ga("ec:addProduct", {
id: item.id,
name: item.title,
price: item.price,
quantity: item.quantity,
category: registration.event.title,
brand: registration.account.name,
});
});
ga("ec:setAction", "purchase", {
id: registration.slug,
revenue: registration.total,
tax: registration.receipt.tax,
coupon: registration.discount_code, // User added a coupon at checkout.
});
ga(
"send",
"pageview",
`/tito/${registration.account.slug}/${registration.event.slug}/registrations/${registration}.slug`
);
ga(
"send",
"event",
"tito",
"registration:finished",
"Registration finished"
);
});
})();