@blotoutio/providers-pinterest-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 +162 -0
- package/index.js +1 -1
- package/index.mjs +160 -0
- package/package.json +5 -2
package/index.cjs.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const snippet = () => {
|
|
4
|
+
if (!window || !document || window.pintrk) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
window.pintrk = function () {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
// eslint-disable-next-line prefer-rest-params
|
|
10
|
+
(_b = (_a = window.pintrk) === null || _a === void 0 ? void 0 : _a.queue) === null || _b === void 0 ? void 0 : _b.push(
|
|
11
|
+
// eslint-disable-next-line
|
|
12
|
+
Array.prototype.slice.call(arguments));
|
|
13
|
+
};
|
|
14
|
+
const n = window.pintrk;
|
|
15
|
+
n.queue = [];
|
|
16
|
+
n.version = '3.0';
|
|
17
|
+
const element = document.createElement('script');
|
|
18
|
+
element.async = !0;
|
|
19
|
+
element.src = 'https://s.pinimg.com/ct/core.js';
|
|
20
|
+
const script = document.getElementsByTagName('script')[0];
|
|
21
|
+
if (script && script.parentNode) {
|
|
22
|
+
script.parentNode.insertBefore(element, script);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const init = ({ manifest }) => {
|
|
26
|
+
if (!manifest.variables || !manifest.variables['pixelId']) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
snippet();
|
|
30
|
+
if (!window.pintrk) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
window.pintrk('load', manifest.variables['pixelId']);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const getPinterestEventName = (name) => {
|
|
37
|
+
switch (name) {
|
|
38
|
+
case 'Purchase': {
|
|
39
|
+
return 'checkout';
|
|
40
|
+
}
|
|
41
|
+
case 'PageView': {
|
|
42
|
+
return 'pagevisit';
|
|
43
|
+
}
|
|
44
|
+
case 'ViewContent': {
|
|
45
|
+
return 'viewcategory';
|
|
46
|
+
}
|
|
47
|
+
case 'AddToCart': {
|
|
48
|
+
return 'addtocart';
|
|
49
|
+
}
|
|
50
|
+
case 'Search': {
|
|
51
|
+
return 'search';
|
|
52
|
+
}
|
|
53
|
+
case 'Lead': {
|
|
54
|
+
return 'lead';
|
|
55
|
+
}
|
|
56
|
+
case 'SignUp': {
|
|
57
|
+
return 'signup';
|
|
58
|
+
}
|
|
59
|
+
case 'WatchVideo': {
|
|
60
|
+
return 'watchvideo';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return name;
|
|
64
|
+
};
|
|
65
|
+
const prepareData = (data) => {
|
|
66
|
+
const payload = {};
|
|
67
|
+
if (data['currency']) {
|
|
68
|
+
payload['currency'] = data['currency'];
|
|
69
|
+
}
|
|
70
|
+
if (data['value']) {
|
|
71
|
+
payload['value'] = data['value'];
|
|
72
|
+
}
|
|
73
|
+
if (data['search']) {
|
|
74
|
+
payload['search_query'] = data['search'];
|
|
75
|
+
}
|
|
76
|
+
if (data['orderId']) {
|
|
77
|
+
payload['order_id'] = data['orderId'];
|
|
78
|
+
}
|
|
79
|
+
if (data['property']) {
|
|
80
|
+
payload['property'] = data['property'];
|
|
81
|
+
}
|
|
82
|
+
if (data['video_title']) {
|
|
83
|
+
payload['video_title'] = data['video_title'];
|
|
84
|
+
}
|
|
85
|
+
if (data['promo_code']) {
|
|
86
|
+
payload['promo_code'] = data['promo_code'];
|
|
87
|
+
}
|
|
88
|
+
if (data['lead_type']) {
|
|
89
|
+
payload['lead_type'] = data['lead_type'];
|
|
90
|
+
}
|
|
91
|
+
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
92
|
+
payload['line_items'] = data['contents'].map((item) => {
|
|
93
|
+
const product = {};
|
|
94
|
+
if (item.id) {
|
|
95
|
+
product.product_id = item.id;
|
|
96
|
+
}
|
|
97
|
+
if (item.category) {
|
|
98
|
+
product.product_category = item.category;
|
|
99
|
+
}
|
|
100
|
+
if (item.item_price) {
|
|
101
|
+
product.product_price = item.item_price;
|
|
102
|
+
}
|
|
103
|
+
if (item.quantity) {
|
|
104
|
+
product.product_quantity = item.quantity;
|
|
105
|
+
}
|
|
106
|
+
if (item.variantId) {
|
|
107
|
+
product.product_variant_id = item.variantId;
|
|
108
|
+
}
|
|
109
|
+
if (item.brand) {
|
|
110
|
+
product.product_brand = item.brand;
|
|
111
|
+
}
|
|
112
|
+
if (item.title) {
|
|
113
|
+
product.product_name = item.title;
|
|
114
|
+
}
|
|
115
|
+
if (item.variant) {
|
|
116
|
+
product.product_variant = item.variant;
|
|
117
|
+
}
|
|
118
|
+
return product;
|
|
119
|
+
});
|
|
120
|
+
let orderQuantity = 0;
|
|
121
|
+
data['contents'].map((product) => {
|
|
122
|
+
orderQuantity += product.quantity;
|
|
123
|
+
});
|
|
124
|
+
payload['order_quantity'] = orderQuantity;
|
|
125
|
+
}
|
|
126
|
+
return payload;
|
|
127
|
+
};
|
|
128
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
129
|
+
if (window.pintrk && manifestVariables['pixelId']) {
|
|
130
|
+
const name = data['skipTransformation']
|
|
131
|
+
? eventName
|
|
132
|
+
: getPinterestEventName(eventName);
|
|
133
|
+
const eventData = data['skipTransformation'] ? data : prepareData(data);
|
|
134
|
+
delete eventData['skipTransformation'];
|
|
135
|
+
window.pintrk('track', name, {
|
|
136
|
+
...eventData,
|
|
137
|
+
event_id: eventId.toString(),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
sdkVersion: "0.27.0" ,
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const data = {
|
|
146
|
+
name: 'pinterest',
|
|
147
|
+
tag,
|
|
148
|
+
init,
|
|
149
|
+
};
|
|
150
|
+
try {
|
|
151
|
+
if (window) {
|
|
152
|
+
if (!window.edgetagProviders) {
|
|
153
|
+
window.edgetagProviders = [];
|
|
154
|
+
}
|
|
155
|
+
window.edgetagProviders.push(data);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// No window
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = data;
|
package/index.js
CHANGED
package/index.mjs
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
const snippet = () => {
|
|
2
|
+
if (!window || !document || window.pintrk) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
window.pintrk = function () {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
// eslint-disable-next-line prefer-rest-params
|
|
8
|
+
(_b = (_a = window.pintrk) === null || _a === void 0 ? void 0 : _a.queue) === null || _b === void 0 ? void 0 : _b.push(
|
|
9
|
+
// eslint-disable-next-line
|
|
10
|
+
Array.prototype.slice.call(arguments));
|
|
11
|
+
};
|
|
12
|
+
const n = window.pintrk;
|
|
13
|
+
n.queue = [];
|
|
14
|
+
n.version = '3.0';
|
|
15
|
+
const element = document.createElement('script');
|
|
16
|
+
element.async = !0;
|
|
17
|
+
element.src = 'https://s.pinimg.com/ct/core.js';
|
|
18
|
+
const script = document.getElementsByTagName('script')[0];
|
|
19
|
+
if (script && script.parentNode) {
|
|
20
|
+
script.parentNode.insertBefore(element, script);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const init = ({ manifest }) => {
|
|
24
|
+
if (!manifest.variables || !manifest.variables['pixelId']) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
snippet();
|
|
28
|
+
if (!window.pintrk) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
window.pintrk('load', manifest.variables['pixelId']);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getPinterestEventName = (name) => {
|
|
35
|
+
switch (name) {
|
|
36
|
+
case 'Purchase': {
|
|
37
|
+
return 'checkout';
|
|
38
|
+
}
|
|
39
|
+
case 'PageView': {
|
|
40
|
+
return 'pagevisit';
|
|
41
|
+
}
|
|
42
|
+
case 'ViewContent': {
|
|
43
|
+
return 'viewcategory';
|
|
44
|
+
}
|
|
45
|
+
case 'AddToCart': {
|
|
46
|
+
return 'addtocart';
|
|
47
|
+
}
|
|
48
|
+
case 'Search': {
|
|
49
|
+
return 'search';
|
|
50
|
+
}
|
|
51
|
+
case 'Lead': {
|
|
52
|
+
return 'lead';
|
|
53
|
+
}
|
|
54
|
+
case 'SignUp': {
|
|
55
|
+
return 'signup';
|
|
56
|
+
}
|
|
57
|
+
case 'WatchVideo': {
|
|
58
|
+
return 'watchvideo';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return name;
|
|
62
|
+
};
|
|
63
|
+
const prepareData = (data) => {
|
|
64
|
+
const payload = {};
|
|
65
|
+
if (data['currency']) {
|
|
66
|
+
payload['currency'] = data['currency'];
|
|
67
|
+
}
|
|
68
|
+
if (data['value']) {
|
|
69
|
+
payload['value'] = data['value'];
|
|
70
|
+
}
|
|
71
|
+
if (data['search']) {
|
|
72
|
+
payload['search_query'] = data['search'];
|
|
73
|
+
}
|
|
74
|
+
if (data['orderId']) {
|
|
75
|
+
payload['order_id'] = data['orderId'];
|
|
76
|
+
}
|
|
77
|
+
if (data['property']) {
|
|
78
|
+
payload['property'] = data['property'];
|
|
79
|
+
}
|
|
80
|
+
if (data['video_title']) {
|
|
81
|
+
payload['video_title'] = data['video_title'];
|
|
82
|
+
}
|
|
83
|
+
if (data['promo_code']) {
|
|
84
|
+
payload['promo_code'] = data['promo_code'];
|
|
85
|
+
}
|
|
86
|
+
if (data['lead_type']) {
|
|
87
|
+
payload['lead_type'] = data['lead_type'];
|
|
88
|
+
}
|
|
89
|
+
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
90
|
+
payload['line_items'] = data['contents'].map((item) => {
|
|
91
|
+
const product = {};
|
|
92
|
+
if (item.id) {
|
|
93
|
+
product.product_id = item.id;
|
|
94
|
+
}
|
|
95
|
+
if (item.category) {
|
|
96
|
+
product.product_category = item.category;
|
|
97
|
+
}
|
|
98
|
+
if (item.item_price) {
|
|
99
|
+
product.product_price = item.item_price;
|
|
100
|
+
}
|
|
101
|
+
if (item.quantity) {
|
|
102
|
+
product.product_quantity = item.quantity;
|
|
103
|
+
}
|
|
104
|
+
if (item.variantId) {
|
|
105
|
+
product.product_variant_id = item.variantId;
|
|
106
|
+
}
|
|
107
|
+
if (item.brand) {
|
|
108
|
+
product.product_brand = item.brand;
|
|
109
|
+
}
|
|
110
|
+
if (item.title) {
|
|
111
|
+
product.product_name = item.title;
|
|
112
|
+
}
|
|
113
|
+
if (item.variant) {
|
|
114
|
+
product.product_variant = item.variant;
|
|
115
|
+
}
|
|
116
|
+
return product;
|
|
117
|
+
});
|
|
118
|
+
let orderQuantity = 0;
|
|
119
|
+
data['contents'].map((product) => {
|
|
120
|
+
orderQuantity += product.quantity;
|
|
121
|
+
});
|
|
122
|
+
payload['order_quantity'] = orderQuantity;
|
|
123
|
+
}
|
|
124
|
+
return payload;
|
|
125
|
+
};
|
|
126
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
127
|
+
if (window.pintrk && manifestVariables['pixelId']) {
|
|
128
|
+
const name = data['skipTransformation']
|
|
129
|
+
? eventName
|
|
130
|
+
: getPinterestEventName(eventName);
|
|
131
|
+
const eventData = data['skipTransformation'] ? data : prepareData(data);
|
|
132
|
+
delete eventData['skipTransformation'];
|
|
133
|
+
window.pintrk('track', name, {
|
|
134
|
+
...eventData,
|
|
135
|
+
event_id: eventId.toString(),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
sdkVersion: "0.27.0" ,
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const data = {
|
|
144
|
+
name: 'pinterest',
|
|
145
|
+
tag,
|
|
146
|
+
init,
|
|
147
|
+
};
|
|
148
|
+
try {
|
|
149
|
+
if (window) {
|
|
150
|
+
if (!window.edgetagProviders) {
|
|
151
|
+
window.edgetagProviders = [];
|
|
152
|
+
}
|
|
153
|
+
window.edgetagProviders.push(data);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// No window
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { data as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blotoutio/providers-pinterest-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Pinterest 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
|
]
|