-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook.js
59 lines (58 loc) · 1.63 KB
/
facebook.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
(function () {
console.info("[tito][facebook]", "plugin loaded");
if (!window.fbq)
console.info(
"[tito][facebook]",
"unable to detect facebook object i.e. window.fbq"
);
tito("on:registration:started", function (registration) {
console.info(
"[tito][facebook]",
"tracking registration started",
registration
);
var num_items = 0;
registration.line_items.forEach(function (line_item) {
num_items = num_items + line_item.quantity;
if (window.fbq) {
fbq("track", "AddToCart", {
content_type: "product",
content_ids: [line_item.release_slug],
content_name: line_item.title,
value: line_item.price,
currency: registration.currency,
});
}
});
if (window.fbq) {
fbq("track", "InitiateCheckout", {
value: registration.total,
num_items: num_items,
currency: registration.currency,
});
}
});
tito("on:registration:finished", function (registration) {
console.info(
"[tito][facebook]",
"tracking registration finished",
registration
);
var num_items = 0;
var content_ids = [];
registration.line_items.forEach(function (line_item) {
num_items = num_items + line_item.quantity;
content_ids.push(line_item.release_slug);
});
if (window.fbq) {
fbq("track", "Purchase", {
value: registration.total,
content_name: registration.event.title,
content_type: "product",
content_ids: content_ids,
num_items: num_items,
currency: registration.currency,
});
}
});
})();