@blotoutio/providers-pinterest-sdk 0.9.2

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.
Files changed (3) hide show
  1. package/README.md +3 -0
  2. package/index.js +153 -0
  3. package/package.json +21 -0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # EdgeTag Pinterest adapter
2
+
3
+ More info on https://app.edgetag.io/docs/pinterest
package/index.js ADDED
@@ -0,0 +1,153 @@
1
+ var ProvidersPinterestSdk = (function () {
2
+ 'use strict';
3
+
4
+ const snippet = () => {
5
+ if (!window || !document || window.pintrk) {
6
+ return;
7
+ }
8
+ window.pintrk = function () {
9
+ var _a, _b;
10
+ // eslint-disable-next-line prefer-rest-params
11
+ (_b = (_a = window.pintrk) === null || _a === void 0 ? void 0 : _a.queue) === null || _b === void 0 ? void 0 : _b.push(
12
+ // eslint-disable-next-line
13
+ Array.prototype.slice.call(arguments));
14
+ };
15
+ const n = window.pintrk;
16
+ n.queue = [];
17
+ n.version = '3.0';
18
+ const element = document.createElement('script');
19
+ element.async = !0;
20
+ element.src = 'https://s.pinimg.com/ct/core.js';
21
+ const script = document.getElementsByTagName('script')[0];
22
+ if (script && script.parentNode) {
23
+ script.parentNode.insertBefore(element, script);
24
+ }
25
+ };
26
+ const init = ({ manifest }) => {
27
+ if (!manifest.variables || !manifest.variables['pixelId']) {
28
+ return;
29
+ }
30
+ const firstLoad = !window.pintrk;
31
+ snippet();
32
+ if (!firstLoad || !window.pintrk) {
33
+ return;
34
+ }
35
+ window.pintrk('load', manifest.variables['pixelId']);
36
+ };
37
+
38
+ const getPinterestEventName = (name) => {
39
+ switch (name) {
40
+ case 'Purchase': {
41
+ return 'checkout';
42
+ }
43
+ case 'PageView': {
44
+ return 'pagevisit';
45
+ }
46
+ case 'ViewContent': {
47
+ return 'viewcategory';
48
+ }
49
+ case 'AddToCart': {
50
+ return 'addtocart';
51
+ }
52
+ case 'Search': {
53
+ return 'search';
54
+ }
55
+ case 'Lead': {
56
+ return 'lead';
57
+ }
58
+ case 'SignUp': {
59
+ return 'signup';
60
+ }
61
+ case 'WatchVideo': {
62
+ return 'watchvideo';
63
+ }
64
+ }
65
+ return name;
66
+ };
67
+ const prepareData = (data) => {
68
+ const payload = {};
69
+ if (data['currency']) {
70
+ payload['currency'] = data['currency'];
71
+ }
72
+ if (data['value']) {
73
+ payload['value'] = data['value'];
74
+ }
75
+ if (data['search']) {
76
+ payload['search_query'] = data['search'];
77
+ }
78
+ if (data['orderId']) {
79
+ payload['order_id'] = data['orderId'];
80
+ }
81
+ if (data['video_title']) {
82
+ payload['video_title'] = data['video_title'];
83
+ }
84
+ if (data['promo_code']) {
85
+ payload['promo_code'] = data['promo_code'];
86
+ }
87
+ if (data['lead_type']) {
88
+ payload['lead_type'] = data['lead_type'];
89
+ }
90
+ if (data['contents'] && Array.isArray(data['contents'])) {
91
+ payload['line_items'] = data['contents'].map((item) => {
92
+ const product = {};
93
+ if (item.id) {
94
+ product.product_id = item.id;
95
+ }
96
+ if (item.category) {
97
+ product.product_category = item.category;
98
+ }
99
+ if (item.item_price) {
100
+ product.product_price = item.item_price;
101
+ }
102
+ if (item.quantity) {
103
+ product.product_quantity = item.quantity;
104
+ }
105
+ if (item.variantId) {
106
+ product.product_variant_id = item.variantId;
107
+ }
108
+ if (item.brand) {
109
+ product.product_brand = item.brand;
110
+ }
111
+ if (item.title) {
112
+ product.product_name = item.title;
113
+ }
114
+ if (item.variant) {
115
+ product.product_variant = item.variant;
116
+ }
117
+ return product;
118
+ });
119
+ let orderQuantity = 0;
120
+ data['contents'].map((product) => {
121
+ orderQuantity += product.quantity;
122
+ });
123
+ payload['order_quantity'] = orderQuantity;
124
+ }
125
+ return payload;
126
+ };
127
+ const tag = ({ data, eventName, manifestVariables, eventId }) => {
128
+ if (!window.pintrk || !manifestVariables['pixelId']) {
129
+ return;
130
+ }
131
+ window.pintrk('track', getPinterestEventName(eventName), Object.assign(Object.assign({}, prepareData(data)), { event_id: eventId.toString() }));
132
+ };
133
+
134
+ const data = {
135
+ name: 'pinterest',
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 (_a) {
148
+ // No window
149
+ }
150
+
151
+ return data;
152
+
153
+ })();
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@blotoutio/providers-pinterest-sdk",
3
+ "version": "0.9.2",
4
+ "description": "Pinterest Browser SDK for EdgeTag",
5
+ "author": "Blotout",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/blotoutio/edgetag-sdk",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "main": "./index.js",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/blotoutio/edgetag-sdk.git"
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "package.json",
19
+ "README.md"
20
+ ]
21
+ }