@blotoutio/providers-facebook-sdk 0.26.5 → 0.27.0
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.cjs.js +153 -0
- package/index.js +1 -1
- package/index.mjs +151 -0
- package/package.json +5 -2
package/index.cjs.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const snippet = () => {
|
|
4
|
+
if (!window || !document || window.fbq) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const n = (window.fbq = function () {
|
|
8
|
+
n['callMethod']
|
|
9
|
+
? // eslint-disable-next-line prefer-spread,prefer-rest-params
|
|
10
|
+
n['callMethod'].apply(n, arguments)
|
|
11
|
+
: // eslint-disable-next-line prefer-rest-params
|
|
12
|
+
n['queue'].push(arguments);
|
|
13
|
+
});
|
|
14
|
+
if (!window._fbq) {
|
|
15
|
+
window._fbq = n;
|
|
16
|
+
}
|
|
17
|
+
n['push'] = n;
|
|
18
|
+
n['loaded'] = !0;
|
|
19
|
+
n['version'] = '2.0';
|
|
20
|
+
n['queue'] = [];
|
|
21
|
+
const element = document.createElement('script');
|
|
22
|
+
element.async = !0;
|
|
23
|
+
element.src = 'https://connect.facebook.net/en_US/fbevents.js';
|
|
24
|
+
const script = document.getElementsByTagName('script')[0];
|
|
25
|
+
if (script && script.parentNode) {
|
|
26
|
+
script.parentNode.insertBefore(element, script);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const init = ({ manifest, userId }) => {
|
|
30
|
+
if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
snippet();
|
|
34
|
+
if (!window.fbq) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
window['fbq']('init', manifest.variables['pixelId'], {
|
|
38
|
+
external_id: userId,
|
|
39
|
+
});
|
|
40
|
+
window['fbq'].disablePushState = true;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const getProductMappingModel = (productIdMapping, useVariantId) => {
|
|
44
|
+
const value = productIdMapping || useVariantId || '0';
|
|
45
|
+
return value && /^[012]$/.test(value) ? value : '0';
|
|
46
|
+
};
|
|
47
|
+
const getProductId = (productIdMapping, item) => {
|
|
48
|
+
if (productIdMapping === '1') {
|
|
49
|
+
return item.variantId;
|
|
50
|
+
}
|
|
51
|
+
if (productIdMapping === '2') {
|
|
52
|
+
return item.sku;
|
|
53
|
+
}
|
|
54
|
+
return item.id;
|
|
55
|
+
};
|
|
56
|
+
const prepareData = (data, productIdMapping) => {
|
|
57
|
+
const payload = {
|
|
58
|
+
app: 'Blotout',
|
|
59
|
+
};
|
|
60
|
+
if (data['value']) {
|
|
61
|
+
payload['value'] = data['value'];
|
|
62
|
+
}
|
|
63
|
+
if (data['currency']) {
|
|
64
|
+
payload['currency'] = data['currency'];
|
|
65
|
+
}
|
|
66
|
+
if (data['name']) {
|
|
67
|
+
payload['content_name'] = data['name'];
|
|
68
|
+
}
|
|
69
|
+
if (data['type']) {
|
|
70
|
+
payload['content_type'] = data['type'];
|
|
71
|
+
}
|
|
72
|
+
if (data['category']) {
|
|
73
|
+
payload['content_category'] = data['category'];
|
|
74
|
+
}
|
|
75
|
+
if (data['ids']) {
|
|
76
|
+
payload['content_ids'] = data['ids'];
|
|
77
|
+
}
|
|
78
|
+
if (data['search']) {
|
|
79
|
+
payload['search_string'] = data['search'];
|
|
80
|
+
}
|
|
81
|
+
if (data['status']) {
|
|
82
|
+
payload['status'] = data['status'];
|
|
83
|
+
}
|
|
84
|
+
if (data['predicted_ltv']) {
|
|
85
|
+
payload['predicted_ltv'] = data['predicted_ltv'];
|
|
86
|
+
}
|
|
87
|
+
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
88
|
+
payload['contents'] = data['contents'].map((item) => {
|
|
89
|
+
const content = {};
|
|
90
|
+
const contentId = getProductId(productIdMapping, item);
|
|
91
|
+
if (contentId) {
|
|
92
|
+
content['id'] = contentId;
|
|
93
|
+
}
|
|
94
|
+
if (item.quantity) {
|
|
95
|
+
content['quantity'] = item.quantity;
|
|
96
|
+
}
|
|
97
|
+
if (item.item_price) {
|
|
98
|
+
content['item_price'] = item.item_price;
|
|
99
|
+
}
|
|
100
|
+
if (item.category) {
|
|
101
|
+
content['category'] = item.category;
|
|
102
|
+
}
|
|
103
|
+
if (item.title) {
|
|
104
|
+
content['title'] = item.title;
|
|
105
|
+
}
|
|
106
|
+
return content;
|
|
107
|
+
});
|
|
108
|
+
if (data['contents'] && data['contents'][0] && data['contents'][0].type) {
|
|
109
|
+
payload['content_type'] = data['contents'][0].type;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (data['contents'] || data['ids']) {
|
|
113
|
+
const contents = data['contents'] || data['ids'];
|
|
114
|
+
if (Array.isArray(contents)) {
|
|
115
|
+
payload['num_items'] = contents.length;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return payload;
|
|
119
|
+
};
|
|
120
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
121
|
+
const payload = {
|
|
122
|
+
sdkVersion: "0.27.0" ,
|
|
123
|
+
};
|
|
124
|
+
if (window.fbq && manifestVariables['enableBrowser'] === '1') {
|
|
125
|
+
const eventData = data['skipTransformation'] === true
|
|
126
|
+
? data
|
|
127
|
+
: prepareData(data, getProductMappingModel(manifestVariables['productIdMapping'], manifestVariables['variantId']));
|
|
128
|
+
delete eventData['skipTransformation'];
|
|
129
|
+
window.fbq('trackSingle', manifestVariables['pixelId'], eventName, eventData, {
|
|
130
|
+
eventID: eventId,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return payload;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const data = {
|
|
137
|
+
name: 'facebook',
|
|
138
|
+
tag,
|
|
139
|
+
init,
|
|
140
|
+
};
|
|
141
|
+
try {
|
|
142
|
+
if (window) {
|
|
143
|
+
if (!window.edgetagProviders) {
|
|
144
|
+
window.edgetagProviders = [];
|
|
145
|
+
}
|
|
146
|
+
window.edgetagProviders.push(data);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// No window
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = data;
|
package/index.js
CHANGED
|
@@ -120,7 +120,7 @@ var ProvidersFacebookSdk = (function () {
|
|
|
120
120
|
};
|
|
121
121
|
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
122
122
|
const payload = {
|
|
123
|
-
sdkVersion: "0.
|
|
123
|
+
sdkVersion: "0.27.0" ,
|
|
124
124
|
};
|
|
125
125
|
if (window.fbq && manifestVariables['enableBrowser'] === '1') {
|
|
126
126
|
const eventData = data['skipTransformation'] === true
|
package/index.mjs
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const snippet = () => {
|
|
2
|
+
if (!window || !document || window.fbq) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
const n = (window.fbq = function () {
|
|
6
|
+
n['callMethod']
|
|
7
|
+
? // eslint-disable-next-line prefer-spread,prefer-rest-params
|
|
8
|
+
n['callMethod'].apply(n, arguments)
|
|
9
|
+
: // eslint-disable-next-line prefer-rest-params
|
|
10
|
+
n['queue'].push(arguments);
|
|
11
|
+
});
|
|
12
|
+
if (!window._fbq) {
|
|
13
|
+
window._fbq = n;
|
|
14
|
+
}
|
|
15
|
+
n['push'] = n;
|
|
16
|
+
n['loaded'] = !0;
|
|
17
|
+
n['version'] = '2.0';
|
|
18
|
+
n['queue'] = [];
|
|
19
|
+
const element = document.createElement('script');
|
|
20
|
+
element.async = !0;
|
|
21
|
+
element.src = 'https://connect.facebook.net/en_US/fbevents.js';
|
|
22
|
+
const script = document.getElementsByTagName('script')[0];
|
|
23
|
+
if (script && script.parentNode) {
|
|
24
|
+
script.parentNode.insertBefore(element, script);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const init = ({ manifest, userId }) => {
|
|
28
|
+
if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
snippet();
|
|
32
|
+
if (!window.fbq) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
window['fbq']('init', manifest.variables['pixelId'], {
|
|
36
|
+
external_id: userId,
|
|
37
|
+
});
|
|
38
|
+
window['fbq'].disablePushState = true;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getProductMappingModel = (productIdMapping, useVariantId) => {
|
|
42
|
+
const value = productIdMapping || useVariantId || '0';
|
|
43
|
+
return value && /^[012]$/.test(value) ? value : '0';
|
|
44
|
+
};
|
|
45
|
+
const getProductId = (productIdMapping, item) => {
|
|
46
|
+
if (productIdMapping === '1') {
|
|
47
|
+
return item.variantId;
|
|
48
|
+
}
|
|
49
|
+
if (productIdMapping === '2') {
|
|
50
|
+
return item.sku;
|
|
51
|
+
}
|
|
52
|
+
return item.id;
|
|
53
|
+
};
|
|
54
|
+
const prepareData = (data, productIdMapping) => {
|
|
55
|
+
const payload = {
|
|
56
|
+
app: 'Blotout',
|
|
57
|
+
};
|
|
58
|
+
if (data['value']) {
|
|
59
|
+
payload['value'] = data['value'];
|
|
60
|
+
}
|
|
61
|
+
if (data['currency']) {
|
|
62
|
+
payload['currency'] = data['currency'];
|
|
63
|
+
}
|
|
64
|
+
if (data['name']) {
|
|
65
|
+
payload['content_name'] = data['name'];
|
|
66
|
+
}
|
|
67
|
+
if (data['type']) {
|
|
68
|
+
payload['content_type'] = data['type'];
|
|
69
|
+
}
|
|
70
|
+
if (data['category']) {
|
|
71
|
+
payload['content_category'] = data['category'];
|
|
72
|
+
}
|
|
73
|
+
if (data['ids']) {
|
|
74
|
+
payload['content_ids'] = data['ids'];
|
|
75
|
+
}
|
|
76
|
+
if (data['search']) {
|
|
77
|
+
payload['search_string'] = data['search'];
|
|
78
|
+
}
|
|
79
|
+
if (data['status']) {
|
|
80
|
+
payload['status'] = data['status'];
|
|
81
|
+
}
|
|
82
|
+
if (data['predicted_ltv']) {
|
|
83
|
+
payload['predicted_ltv'] = data['predicted_ltv'];
|
|
84
|
+
}
|
|
85
|
+
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
86
|
+
payload['contents'] = data['contents'].map((item) => {
|
|
87
|
+
const content = {};
|
|
88
|
+
const contentId = getProductId(productIdMapping, item);
|
|
89
|
+
if (contentId) {
|
|
90
|
+
content['id'] = contentId;
|
|
91
|
+
}
|
|
92
|
+
if (item.quantity) {
|
|
93
|
+
content['quantity'] = item.quantity;
|
|
94
|
+
}
|
|
95
|
+
if (item.item_price) {
|
|
96
|
+
content['item_price'] = item.item_price;
|
|
97
|
+
}
|
|
98
|
+
if (item.category) {
|
|
99
|
+
content['category'] = item.category;
|
|
100
|
+
}
|
|
101
|
+
if (item.title) {
|
|
102
|
+
content['title'] = item.title;
|
|
103
|
+
}
|
|
104
|
+
return content;
|
|
105
|
+
});
|
|
106
|
+
if (data['contents'] && data['contents'][0] && data['contents'][0].type) {
|
|
107
|
+
payload['content_type'] = data['contents'][0].type;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (data['contents'] || data['ids']) {
|
|
111
|
+
const contents = data['contents'] || data['ids'];
|
|
112
|
+
if (Array.isArray(contents)) {
|
|
113
|
+
payload['num_items'] = contents.length;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return payload;
|
|
117
|
+
};
|
|
118
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
119
|
+
const payload = {
|
|
120
|
+
sdkVersion: "0.27.0" ,
|
|
121
|
+
};
|
|
122
|
+
if (window.fbq && manifestVariables['enableBrowser'] === '1') {
|
|
123
|
+
const eventData = data['skipTransformation'] === true
|
|
124
|
+
? data
|
|
125
|
+
: prepareData(data, getProductMappingModel(manifestVariables['productIdMapping'], manifestVariables['variantId']));
|
|
126
|
+
delete eventData['skipTransformation'];
|
|
127
|
+
window.fbq('trackSingle', manifestVariables['pixelId'], eventName, eventData, {
|
|
128
|
+
eventID: eventId,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return payload;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const data = {
|
|
135
|
+
name: 'facebook',
|
|
136
|
+
tag,
|
|
137
|
+
init,
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
if (window) {
|
|
141
|
+
if (!window.edgetagProviders) {
|
|
142
|
+
window.edgetagProviders = [];
|
|
143
|
+
}
|
|
144
|
+
window.edgetagProviders.push(data);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// No window
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { data as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blotoutio/providers-facebook-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Facebook Browser SDK for EdgeTag",
|
|
5
5
|
"author": "Blotout",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,13 +8,16 @@
|
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
|
-
"main": "./index.js",
|
|
11
|
+
"main": "./index.cjs.js",
|
|
12
|
+
"module": "./index.mjs",
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
14
15
|
"url": "git+https://github.com/blotoutio/edgetag-sdk.git"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"index.js",
|
|
19
|
+
"index.cjs.js",
|
|
20
|
+
"index.mjs",
|
|
18
21
|
"package.json",
|
|
19
22
|
"README.md"
|
|
20
23
|
]
|