@blotoutio/providers-facebook-sdk 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +122 -0
- package/package.json +2 -1
package/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var ProvidersFacebookSdk = (function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const snippet = () => {
|
|
5
|
+
if (!window || !document || window.fbq) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const n = (window.fbq = function () {
|
|
9
|
+
n['callMethod']
|
|
10
|
+
? // eslint-disable-next-line prefer-spread,prefer-rest-params
|
|
11
|
+
n['callMethod'].apply(n, arguments)
|
|
12
|
+
: // eslint-disable-next-line prefer-rest-params
|
|
13
|
+
n['queue'].push(arguments);
|
|
14
|
+
});
|
|
15
|
+
if (!window._fbq) {
|
|
16
|
+
window._fbq = n;
|
|
17
|
+
}
|
|
18
|
+
n['push'] = n;
|
|
19
|
+
n['loaded'] = !0;
|
|
20
|
+
n['version'] = '2.0';
|
|
21
|
+
n['queue'] = [];
|
|
22
|
+
const element = document.createElement('script');
|
|
23
|
+
element.async = !0;
|
|
24
|
+
element.src = 'https://connect.facebook.net/en_US/fbevents.js';
|
|
25
|
+
const script = document.getElementsByTagName('script')[0];
|
|
26
|
+
if (script && script.parentNode) {
|
|
27
|
+
script.parentNode.insertBefore(element, script);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const init = ({ manifest, userId }) => {
|
|
31
|
+
if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const firstLoad = !window.fbq;
|
|
35
|
+
snippet();
|
|
36
|
+
if (!firstLoad || !window.fbq) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
window.fbq('init', manifest.variables['pixelId'], {
|
|
40
|
+
external_id: userId,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const prepareData = (data) => {
|
|
45
|
+
const payload = {};
|
|
46
|
+
if (data['value']) {
|
|
47
|
+
payload['value'] = data['value'];
|
|
48
|
+
}
|
|
49
|
+
if (data['currency']) {
|
|
50
|
+
payload['currency'] = data['currency'];
|
|
51
|
+
}
|
|
52
|
+
if (data['name']) {
|
|
53
|
+
payload['content_name'] = data['name'];
|
|
54
|
+
}
|
|
55
|
+
if (data['type']) {
|
|
56
|
+
payload['content_type'] = data['type'];
|
|
57
|
+
}
|
|
58
|
+
if (data['category']) {
|
|
59
|
+
payload['content_category'] = data['category'];
|
|
60
|
+
}
|
|
61
|
+
if (data['ids']) {
|
|
62
|
+
payload['content_ids'] = data['ids'];
|
|
63
|
+
}
|
|
64
|
+
if (data['search']) {
|
|
65
|
+
payload['search_string'] = data['search'];
|
|
66
|
+
}
|
|
67
|
+
if (data['status']) {
|
|
68
|
+
payload['status'] = data['status'];
|
|
69
|
+
}
|
|
70
|
+
if (data['num_items']) {
|
|
71
|
+
payload['num_items'] = data['num_items'];
|
|
72
|
+
}
|
|
73
|
+
if (data['predicted_ltv']) {
|
|
74
|
+
payload['predicted_ltv'] = data['predicted_ltv'];
|
|
75
|
+
}
|
|
76
|
+
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
77
|
+
payload['contents'] = data['contents'].map((item) => {
|
|
78
|
+
const content = {};
|
|
79
|
+
if (item.id) {
|
|
80
|
+
content['id'] = item.id;
|
|
81
|
+
}
|
|
82
|
+
if (item.quantity) {
|
|
83
|
+
content['quantity'] = item.quantity;
|
|
84
|
+
}
|
|
85
|
+
if (item.item_price) {
|
|
86
|
+
content['item_price'] = item.item_price;
|
|
87
|
+
}
|
|
88
|
+
if (item.delivery_category) {
|
|
89
|
+
content['delivery_category'] = item.delivery_category;
|
|
90
|
+
}
|
|
91
|
+
return content;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return payload;
|
|
95
|
+
};
|
|
96
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
97
|
+
if (!window.fbq || manifestVariables['enableBrowser'] !== '1') {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
window.fbq('track', eventName, prepareData(data), {
|
|
101
|
+
eventID: eventId,
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
var index = {
|
|
106
|
+
tag,
|
|
107
|
+
init,
|
|
108
|
+
};
|
|
109
|
+
if (window) {
|
|
110
|
+
if (!window.edgetagPackages) {
|
|
111
|
+
window.edgetagPackages = [];
|
|
112
|
+
}
|
|
113
|
+
window.edgetagPackages.push({
|
|
114
|
+
name: 'facebook',
|
|
115
|
+
tag,
|
|
116
|
+
init,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return index;
|
|
121
|
+
|
|
122
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blotoutio/providers-facebook-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Facebook Browser SDK for EdgeTag",
|
|
5
5
|
"author": "Blotout",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
|
+
"main": "./index.js",
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
13
14
|
"url": "git+https://github.com/blotoutio/edgetag-sdk.git"
|