@blotoutio/providers-facebook-sdk 0.19.0 → 0.20.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.js +19 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -41,7 +41,20 @@ var ProvidersFacebookSdk = (function () {
|
|
|
41
41
|
window['fbq'].disablePushState = true;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
const
|
|
44
|
+
const getProductMappingModel = (productIdMapping, useVariantId) => {
|
|
45
|
+
const value = productIdMapping || useVariantId || '0';
|
|
46
|
+
return value && /^[012]$/.test(value) ? value : '0';
|
|
47
|
+
};
|
|
48
|
+
const getProductId = (productIdMapping, item) => {
|
|
49
|
+
if (productIdMapping === '1') {
|
|
50
|
+
return item.variantId;
|
|
51
|
+
}
|
|
52
|
+
if (productIdMapping === '2') {
|
|
53
|
+
return item.sku;
|
|
54
|
+
}
|
|
55
|
+
return item.id;
|
|
56
|
+
};
|
|
57
|
+
const prepareData = (data, productIdMapping) => {
|
|
45
58
|
const payload = {
|
|
46
59
|
app: 'Blotout',
|
|
47
60
|
};
|
|
@@ -75,13 +88,9 @@ var ProvidersFacebookSdk = (function () {
|
|
|
75
88
|
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
76
89
|
payload['contents'] = data['contents'].map((item) => {
|
|
77
90
|
const content = {};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
content['id'] = item.id || item.variantId;
|
|
84
|
-
}
|
|
91
|
+
const contentId = getProductId(productIdMapping, item);
|
|
92
|
+
if (contentId) {
|
|
93
|
+
content['id'] = contentId;
|
|
85
94
|
}
|
|
86
95
|
if (item.quantity) {
|
|
87
96
|
content['quantity'] = item.quantity;
|
|
@@ -111,10 +120,10 @@ var ProvidersFacebookSdk = (function () {
|
|
|
111
120
|
};
|
|
112
121
|
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
113
122
|
const payload = {
|
|
114
|
-
sdkVersion: "0.
|
|
123
|
+
sdkVersion: "0.20.0" ,
|
|
115
124
|
};
|
|
116
125
|
if (window.fbq && manifestVariables['enableBrowser'] === '1') {
|
|
117
|
-
window.fbq('trackSingle', manifestVariables['pixelId'], eventName, prepareData(data, manifestVariables['
|
|
126
|
+
window.fbq('trackSingle', manifestVariables['pixelId'], eventName, prepareData(data, getProductMappingModel(manifestVariables['productIdMapping'], manifestVariables['variantId'])), {
|
|
118
127
|
eventID: eventId,
|
|
119
128
|
});
|
|
120
129
|
}
|