@blotoutio/providers-pinterest-sdk 0.30.1 → 0.32.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 +31 -10
- package/index.js +31 -10
- package/index.mjs +31 -10
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -64,7 +64,22 @@ const getPinterestEventName = (name) => {
|
|
|
64
64
|
}
|
|
65
65
|
return name;
|
|
66
66
|
};
|
|
67
|
-
const
|
|
67
|
+
const getProductIds = (item, productIdMapping) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
if (productIdMapping === '1') {
|
|
70
|
+
return {
|
|
71
|
+
productId: (_a = item['variantId']) !== null && _a !== void 0 ? _a : item['id'],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (productIdMapping === '2') {
|
|
75
|
+
return { productId: (_b = item['sku']) !== null && _b !== void 0 ? _b : item['id'] };
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
productId: item['id'],
|
|
79
|
+
productVariantId: item['variantId'],
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const prepareData = (data, idMapping) => {
|
|
68
83
|
const payload = {};
|
|
69
84
|
if (data['currency']) {
|
|
70
85
|
payload['currency'] = data['currency'];
|
|
@@ -93,8 +108,9 @@ const prepareData = (data) => {
|
|
|
93
108
|
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
94
109
|
payload['line_items'] = data['contents'].map((item) => {
|
|
95
110
|
const product = {};
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
const { productId, productVariantId } = getProductIds(item, idMapping);
|
|
112
|
+
if (productId) {
|
|
113
|
+
product.product_id = productId;
|
|
98
114
|
}
|
|
99
115
|
if (item.category) {
|
|
100
116
|
product.product_category = item.category;
|
|
@@ -105,8 +121,8 @@ const prepareData = (data) => {
|
|
|
105
121
|
if (item.quantity) {
|
|
106
122
|
product.product_quantity = item.quantity;
|
|
107
123
|
}
|
|
108
|
-
if (
|
|
109
|
-
product.product_variant_id = item.
|
|
124
|
+
if (productVariantId) {
|
|
125
|
+
product.product_variant_id = item.productVariantId;
|
|
110
126
|
}
|
|
111
127
|
if (item.brand) {
|
|
112
128
|
product.product_brand = item.brand;
|
|
@@ -127,21 +143,26 @@ const prepareData = (data) => {
|
|
|
127
143
|
}
|
|
128
144
|
return payload;
|
|
129
145
|
};
|
|
130
|
-
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
146
|
+
const tag = ({ data, eventName, manifestVariables, eventId, executionContext, }) => {
|
|
147
|
+
const result = { sdkVersion: "0.32.0" };
|
|
148
|
+
if (executionContext.get('pixelFired')) {
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
131
151
|
if (window.pintrk && manifestVariables['pixelId']) {
|
|
132
152
|
const name = data['skipTransformation']
|
|
133
153
|
? eventName
|
|
134
154
|
: getPinterestEventName(eventName);
|
|
135
|
-
const eventData = data['skipTransformation']
|
|
155
|
+
const eventData = data['skipTransformation']
|
|
156
|
+
? data
|
|
157
|
+
: prepareData(data, manifestVariables['productIdMapping']);
|
|
136
158
|
delete eventData['skipTransformation'];
|
|
159
|
+
executionContext.set('pixelFired', true);
|
|
137
160
|
window.pintrk('track', name, {
|
|
138
161
|
...eventData,
|
|
139
162
|
event_id: eventId.toString(),
|
|
140
163
|
});
|
|
141
164
|
}
|
|
142
|
-
return
|
|
143
|
-
sdkVersion: "0.30.1" ,
|
|
144
|
-
};
|
|
165
|
+
return result;
|
|
145
166
|
};
|
|
146
167
|
|
|
147
168
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
package/index.js
CHANGED
|
@@ -65,7 +65,22 @@ var ProvidersPinterestSdk = (function () {
|
|
|
65
65
|
}
|
|
66
66
|
return name;
|
|
67
67
|
};
|
|
68
|
-
const
|
|
68
|
+
const getProductIds = (item, productIdMapping) => {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
if (productIdMapping === '1') {
|
|
71
|
+
return {
|
|
72
|
+
productId: (_a = item['variantId']) !== null && _a !== void 0 ? _a : item['id'],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (productIdMapping === '2') {
|
|
76
|
+
return { productId: (_b = item['sku']) !== null && _b !== void 0 ? _b : item['id'] };
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
productId: item['id'],
|
|
80
|
+
productVariantId: item['variantId'],
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const prepareData = (data, idMapping) => {
|
|
69
84
|
const payload = {};
|
|
70
85
|
if (data['currency']) {
|
|
71
86
|
payload['currency'] = data['currency'];
|
|
@@ -94,8 +109,9 @@ var ProvidersPinterestSdk = (function () {
|
|
|
94
109
|
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
95
110
|
payload['line_items'] = data['contents'].map((item) => {
|
|
96
111
|
const product = {};
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
const { productId, productVariantId } = getProductIds(item, idMapping);
|
|
113
|
+
if (productId) {
|
|
114
|
+
product.product_id = productId;
|
|
99
115
|
}
|
|
100
116
|
if (item.category) {
|
|
101
117
|
product.product_category = item.category;
|
|
@@ -106,8 +122,8 @@ var ProvidersPinterestSdk = (function () {
|
|
|
106
122
|
if (item.quantity) {
|
|
107
123
|
product.product_quantity = item.quantity;
|
|
108
124
|
}
|
|
109
|
-
if (
|
|
110
|
-
product.product_variant_id = item.
|
|
125
|
+
if (productVariantId) {
|
|
126
|
+
product.product_variant_id = item.productVariantId;
|
|
111
127
|
}
|
|
112
128
|
if (item.brand) {
|
|
113
129
|
product.product_brand = item.brand;
|
|
@@ -128,21 +144,26 @@ var ProvidersPinterestSdk = (function () {
|
|
|
128
144
|
}
|
|
129
145
|
return payload;
|
|
130
146
|
};
|
|
131
|
-
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
147
|
+
const tag = ({ data, eventName, manifestVariables, eventId, executionContext, }) => {
|
|
148
|
+
const result = { sdkVersion: "0.32.0" };
|
|
149
|
+
if (executionContext.get('pixelFired')) {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
132
152
|
if (window.pintrk && manifestVariables['pixelId']) {
|
|
133
153
|
const name = data['skipTransformation']
|
|
134
154
|
? eventName
|
|
135
155
|
: getPinterestEventName(eventName);
|
|
136
|
-
const eventData = data['skipTransformation']
|
|
156
|
+
const eventData = data['skipTransformation']
|
|
157
|
+
? data
|
|
158
|
+
: prepareData(data, manifestVariables['productIdMapping']);
|
|
137
159
|
delete eventData['skipTransformation'];
|
|
160
|
+
executionContext.set('pixelFired', true);
|
|
138
161
|
window.pintrk('track', name, {
|
|
139
162
|
...eventData,
|
|
140
163
|
event_id: eventId.toString(),
|
|
141
164
|
});
|
|
142
165
|
}
|
|
143
|
-
return
|
|
144
|
-
sdkVersion: "0.30.1" ,
|
|
145
|
-
};
|
|
166
|
+
return result;
|
|
146
167
|
};
|
|
147
168
|
|
|
148
169
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
package/index.mjs
CHANGED
|
@@ -62,7 +62,22 @@ const getPinterestEventName = (name) => {
|
|
|
62
62
|
}
|
|
63
63
|
return name;
|
|
64
64
|
};
|
|
65
|
-
const
|
|
65
|
+
const getProductIds = (item, productIdMapping) => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
if (productIdMapping === '1') {
|
|
68
|
+
return {
|
|
69
|
+
productId: (_a = item['variantId']) !== null && _a !== void 0 ? _a : item['id'],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (productIdMapping === '2') {
|
|
73
|
+
return { productId: (_b = item['sku']) !== null && _b !== void 0 ? _b : item['id'] };
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
productId: item['id'],
|
|
77
|
+
productVariantId: item['variantId'],
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const prepareData = (data, idMapping) => {
|
|
66
81
|
const payload = {};
|
|
67
82
|
if (data['currency']) {
|
|
68
83
|
payload['currency'] = data['currency'];
|
|
@@ -91,8 +106,9 @@ const prepareData = (data) => {
|
|
|
91
106
|
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
92
107
|
payload['line_items'] = data['contents'].map((item) => {
|
|
93
108
|
const product = {};
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
const { productId, productVariantId } = getProductIds(item, idMapping);
|
|
110
|
+
if (productId) {
|
|
111
|
+
product.product_id = productId;
|
|
96
112
|
}
|
|
97
113
|
if (item.category) {
|
|
98
114
|
product.product_category = item.category;
|
|
@@ -103,8 +119,8 @@ const prepareData = (data) => {
|
|
|
103
119
|
if (item.quantity) {
|
|
104
120
|
product.product_quantity = item.quantity;
|
|
105
121
|
}
|
|
106
|
-
if (
|
|
107
|
-
product.product_variant_id = item.
|
|
122
|
+
if (productVariantId) {
|
|
123
|
+
product.product_variant_id = item.productVariantId;
|
|
108
124
|
}
|
|
109
125
|
if (item.brand) {
|
|
110
126
|
product.product_brand = item.brand;
|
|
@@ -125,21 +141,26 @@ const prepareData = (data) => {
|
|
|
125
141
|
}
|
|
126
142
|
return payload;
|
|
127
143
|
};
|
|
128
|
-
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
144
|
+
const tag = ({ data, eventName, manifestVariables, eventId, executionContext, }) => {
|
|
145
|
+
const result = { sdkVersion: "0.32.0" };
|
|
146
|
+
if (executionContext.get('pixelFired')) {
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
129
149
|
if (window.pintrk && manifestVariables['pixelId']) {
|
|
130
150
|
const name = data['skipTransformation']
|
|
131
151
|
? eventName
|
|
132
152
|
: getPinterestEventName(eventName);
|
|
133
|
-
const eventData = data['skipTransformation']
|
|
153
|
+
const eventData = data['skipTransformation']
|
|
154
|
+
? data
|
|
155
|
+
: prepareData(data, manifestVariables['productIdMapping']);
|
|
134
156
|
delete eventData['skipTransformation'];
|
|
157
|
+
executionContext.set('pixelFired', true);
|
|
135
158
|
window.pintrk('track', name, {
|
|
136
159
|
...eventData,
|
|
137
160
|
event_id: eventId.toString(),
|
|
138
161
|
});
|
|
139
162
|
}
|
|
140
|
-
return
|
|
141
|
-
sdkVersion: "0.30.1" ,
|
|
142
|
-
};
|
|
163
|
+
return result;
|
|
143
164
|
};
|
|
144
165
|
|
|
145
166
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|