@blotoutio/providers-snapchat-sdk 0.26.4 → 0.26.6

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 ADDED
@@ -0,0 +1,203 @@
1
+ 'use strict';
2
+
3
+ const snippet = () => {
4
+ if (!window || !document || window.snaptr) {
5
+ return;
6
+ }
7
+ const a = (window.snaptr = function () {
8
+ a['handleRequest']
9
+ ? // eslint-disable-next-line prefer-spread,prefer-rest-params
10
+ a['handleRequest'].apply(a, arguments)
11
+ : // eslint-disable-next-line prefer-rest-params
12
+ a['queue'].push(arguments);
13
+ });
14
+ a['queue'] = [];
15
+ const element = document.createElement('script');
16
+ element.async = !0;
17
+ element.src = 'https://sc-static.net/scevent.min.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['enableBrowser'] !== '1') {
25
+ return;
26
+ }
27
+ snippet();
28
+ if (!window.snaptr) {
29
+ return;
30
+ }
31
+ window.snaptr('init', manifest.variables['pixelId']);
32
+ };
33
+
34
+ const STANDARD_SNAPCHAT_EVENTS = new Set([
35
+ 'PURCHASE',
36
+ 'SAVE',
37
+ 'START_CHECKOUT',
38
+ 'ADD_CART',
39
+ 'VIEW_CONTENT',
40
+ 'ADD_BILLING',
41
+ 'SIGN_UP',
42
+ 'SEARCH',
43
+ 'PAGE_VIEW',
44
+ 'SUBSCRIBE',
45
+ 'AD_CLICK',
46
+ 'AD_VIEW',
47
+ 'COMPLETE_TUTORIAL',
48
+ 'LEVEL_COMPLETE',
49
+ 'INVITE',
50
+ 'LOGIN',
51
+ 'SHARE',
52
+ 'RESERVE',
53
+ 'ACHIEVEMENT_UNLOCKED',
54
+ 'ADD_TO_WISHLIST',
55
+ 'SPENT_CREDITS',
56
+ 'RATE',
57
+ 'START_TRIAL',
58
+ 'LIST_VIEW',
59
+ 'APP_INSTALL',
60
+ 'APP_OPEN',
61
+ 'CUSTOM_EVENT_1',
62
+ 'CUSTOM_EVENT_2',
63
+ 'CUSTOM_EVENT_3',
64
+ 'CUSTOM_EVENT_4',
65
+ 'CUSTOM_EVENT_5',
66
+ ]);
67
+ const prepareData = (data) => {
68
+ const payload = {};
69
+ if (data['currency']) {
70
+ payload['currency'] = data['currency'];
71
+ }
72
+ if (data['search']) {
73
+ payload['search_string'] = data['search'];
74
+ }
75
+ if (data['description']) {
76
+ payload['description'] = data['description'];
77
+ }
78
+ if (data['orderId']) {
79
+ payload['transaction_id'] = data['orderId'];
80
+ }
81
+ if (data['success']) {
82
+ payload['success'] = data['success'];
83
+ }
84
+ if (data['sign_up_method']) {
85
+ payload['sign_up_method'] = data['sign_up_method'];
86
+ }
87
+ if (data['payment_info_available']) {
88
+ payload['payment_info_available'] = data['payment_info_available'];
89
+ }
90
+ if (data['contents'] && Array.isArray(data['contents'])) {
91
+ payload['number_items'] = data['contents']
92
+ .map((content) => content.quantity)
93
+ .join(';');
94
+ payload['item_ids'] = data['contents']
95
+ .map((content) => content.id)
96
+ .join(';');
97
+ payload['item_category'] = data['contents'].map((content) => content.category);
98
+ payload['price'] = data['contents']
99
+ .map((content) => parseFloat(content.item_price))
100
+ .join(';');
101
+ }
102
+ return payload;
103
+ };
104
+ const getSnapEventName = (name) => {
105
+ switch (name) {
106
+ case 'InitiateCheckout': {
107
+ return 'START_CHECKOUT';
108
+ }
109
+ case 'AddToCart': {
110
+ return 'ADD_CART';
111
+ }
112
+ case 'ViewContent': {
113
+ return 'VIEW_CONTENT';
114
+ }
115
+ case 'AddPaymentInfo': {
116
+ return 'ADD_BILLING';
117
+ }
118
+ case 'AddToWishlist': {
119
+ return 'ADD_TO_WISHLIST';
120
+ }
121
+ case 'CompleteRegistration': {
122
+ return 'SIGN_UP';
123
+ }
124
+ case 'PageView': {
125
+ return 'PAGE_VIEW';
126
+ }
127
+ case 'StartTrial': {
128
+ return 'START_TRIAL';
129
+ }
130
+ case 'AdClick': {
131
+ return 'AD_CLICK';
132
+ }
133
+ case 'AdView': {
134
+ return 'AD_VIEW';
135
+ }
136
+ case 'CompleteTutorial': {
137
+ return 'COMPLETE_TUTORIAL';
138
+ }
139
+ case 'ListView': {
140
+ return 'LIST_VIEW';
141
+ }
142
+ case 'SpentCredits': {
143
+ return 'SPENT_CREDITS';
144
+ }
145
+ case 'AppInstall': {
146
+ return 'APP_INSTALL';
147
+ }
148
+ case 'AppOpen': {
149
+ return 'APP_OPEN';
150
+ }
151
+ case 'AchievementUnlocked': {
152
+ return 'ACHIEVEMENT_UNLOCKED';
153
+ }
154
+ case 'LevelComplete': {
155
+ return 'LEVEL_COMPLETE';
156
+ }
157
+ }
158
+ if (name.startsWith('CustomEvent')) {
159
+ return `CUSTOM_EVENT_${name[name.length - 1]}`;
160
+ }
161
+ return name.toUpperCase();
162
+ };
163
+ const tag = ({ data, eventName, manifestVariables, eventId, executionContext, }) => {
164
+ const result = { sdkVersion: "0.26.6" };
165
+ if (executionContext.get('pixelFired')) {
166
+ return result;
167
+ }
168
+ if (window.snaptr && manifestVariables['enableBrowser'] === '1') {
169
+ const event = data['skipTransformation'] === true
170
+ ? eventName
171
+ : getSnapEventName(eventName);
172
+ const eventData = data['skipTransformation'] === true ? data : prepareData(data);
173
+ delete eventData['skipTransformation'];
174
+ if (STANDARD_SNAPCHAT_EVENTS.has(event)) {
175
+ executionContext.set('pixelFired', true);
176
+ window.snaptr('track', event, {
177
+ ...eventData,
178
+ client_dedup_id: eventId.toString(),
179
+ integration: 'blotout',
180
+ });
181
+ }
182
+ }
183
+ return result;
184
+ };
185
+
186
+ const data = {
187
+ name: 'snapchat',
188
+ tag,
189
+ init,
190
+ };
191
+ try {
192
+ if (window) {
193
+ if (!window.edgetagProviders) {
194
+ window.edgetagProviders = [];
195
+ }
196
+ window.edgetagProviders.push(data);
197
+ }
198
+ }
199
+ catch {
200
+ // No window
201
+ }
202
+
203
+ module.exports = data;
package/index.js CHANGED
@@ -162,7 +162,7 @@ var ProvidersSnapchatSdk = (function () {
162
162
  return name.toUpperCase();
163
163
  };
164
164
  const tag = ({ data, eventName, manifestVariables, eventId, executionContext, }) => {
165
- const result = { sdkVersion: "0.26.4" };
165
+ const result = { sdkVersion: "0.26.6" };
166
166
  if (executionContext.get('pixelFired')) {
167
167
  return result;
168
168
  }
package/index.mjs ADDED
@@ -0,0 +1,201 @@
1
+ const snippet = () => {
2
+ if (!window || !document || window.snaptr) {
3
+ return;
4
+ }
5
+ const a = (window.snaptr = function () {
6
+ a['handleRequest']
7
+ ? // eslint-disable-next-line prefer-spread,prefer-rest-params
8
+ a['handleRequest'].apply(a, arguments)
9
+ : // eslint-disable-next-line prefer-rest-params
10
+ a['queue'].push(arguments);
11
+ });
12
+ a['queue'] = [];
13
+ const element = document.createElement('script');
14
+ element.async = !0;
15
+ element.src = 'https://sc-static.net/scevent.min.js';
16
+ const script = document.getElementsByTagName('script')[0];
17
+ if (script && script.parentNode) {
18
+ script.parentNode.insertBefore(element, script);
19
+ }
20
+ };
21
+ const init = ({ manifest }) => {
22
+ if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
23
+ return;
24
+ }
25
+ snippet();
26
+ if (!window.snaptr) {
27
+ return;
28
+ }
29
+ window.snaptr('init', manifest.variables['pixelId']);
30
+ };
31
+
32
+ const STANDARD_SNAPCHAT_EVENTS = new Set([
33
+ 'PURCHASE',
34
+ 'SAVE',
35
+ 'START_CHECKOUT',
36
+ 'ADD_CART',
37
+ 'VIEW_CONTENT',
38
+ 'ADD_BILLING',
39
+ 'SIGN_UP',
40
+ 'SEARCH',
41
+ 'PAGE_VIEW',
42
+ 'SUBSCRIBE',
43
+ 'AD_CLICK',
44
+ 'AD_VIEW',
45
+ 'COMPLETE_TUTORIAL',
46
+ 'LEVEL_COMPLETE',
47
+ 'INVITE',
48
+ 'LOGIN',
49
+ 'SHARE',
50
+ 'RESERVE',
51
+ 'ACHIEVEMENT_UNLOCKED',
52
+ 'ADD_TO_WISHLIST',
53
+ 'SPENT_CREDITS',
54
+ 'RATE',
55
+ 'START_TRIAL',
56
+ 'LIST_VIEW',
57
+ 'APP_INSTALL',
58
+ 'APP_OPEN',
59
+ 'CUSTOM_EVENT_1',
60
+ 'CUSTOM_EVENT_2',
61
+ 'CUSTOM_EVENT_3',
62
+ 'CUSTOM_EVENT_4',
63
+ 'CUSTOM_EVENT_5',
64
+ ]);
65
+ const prepareData = (data) => {
66
+ const payload = {};
67
+ if (data['currency']) {
68
+ payload['currency'] = data['currency'];
69
+ }
70
+ if (data['search']) {
71
+ payload['search_string'] = data['search'];
72
+ }
73
+ if (data['description']) {
74
+ payload['description'] = data['description'];
75
+ }
76
+ if (data['orderId']) {
77
+ payload['transaction_id'] = data['orderId'];
78
+ }
79
+ if (data['success']) {
80
+ payload['success'] = data['success'];
81
+ }
82
+ if (data['sign_up_method']) {
83
+ payload['sign_up_method'] = data['sign_up_method'];
84
+ }
85
+ if (data['payment_info_available']) {
86
+ payload['payment_info_available'] = data['payment_info_available'];
87
+ }
88
+ if (data['contents'] && Array.isArray(data['contents'])) {
89
+ payload['number_items'] = data['contents']
90
+ .map((content) => content.quantity)
91
+ .join(';');
92
+ payload['item_ids'] = data['contents']
93
+ .map((content) => content.id)
94
+ .join(';');
95
+ payload['item_category'] = data['contents'].map((content) => content.category);
96
+ payload['price'] = data['contents']
97
+ .map((content) => parseFloat(content.item_price))
98
+ .join(';');
99
+ }
100
+ return payload;
101
+ };
102
+ const getSnapEventName = (name) => {
103
+ switch (name) {
104
+ case 'InitiateCheckout': {
105
+ return 'START_CHECKOUT';
106
+ }
107
+ case 'AddToCart': {
108
+ return 'ADD_CART';
109
+ }
110
+ case 'ViewContent': {
111
+ return 'VIEW_CONTENT';
112
+ }
113
+ case 'AddPaymentInfo': {
114
+ return 'ADD_BILLING';
115
+ }
116
+ case 'AddToWishlist': {
117
+ return 'ADD_TO_WISHLIST';
118
+ }
119
+ case 'CompleteRegistration': {
120
+ return 'SIGN_UP';
121
+ }
122
+ case 'PageView': {
123
+ return 'PAGE_VIEW';
124
+ }
125
+ case 'StartTrial': {
126
+ return 'START_TRIAL';
127
+ }
128
+ case 'AdClick': {
129
+ return 'AD_CLICK';
130
+ }
131
+ case 'AdView': {
132
+ return 'AD_VIEW';
133
+ }
134
+ case 'CompleteTutorial': {
135
+ return 'COMPLETE_TUTORIAL';
136
+ }
137
+ case 'ListView': {
138
+ return 'LIST_VIEW';
139
+ }
140
+ case 'SpentCredits': {
141
+ return 'SPENT_CREDITS';
142
+ }
143
+ case 'AppInstall': {
144
+ return 'APP_INSTALL';
145
+ }
146
+ case 'AppOpen': {
147
+ return 'APP_OPEN';
148
+ }
149
+ case 'AchievementUnlocked': {
150
+ return 'ACHIEVEMENT_UNLOCKED';
151
+ }
152
+ case 'LevelComplete': {
153
+ return 'LEVEL_COMPLETE';
154
+ }
155
+ }
156
+ if (name.startsWith('CustomEvent')) {
157
+ return `CUSTOM_EVENT_${name[name.length - 1]}`;
158
+ }
159
+ return name.toUpperCase();
160
+ };
161
+ const tag = ({ data, eventName, manifestVariables, eventId, executionContext, }) => {
162
+ const result = { sdkVersion: "0.26.6" };
163
+ if (executionContext.get('pixelFired')) {
164
+ return result;
165
+ }
166
+ if (window.snaptr && manifestVariables['enableBrowser'] === '1') {
167
+ const event = data['skipTransformation'] === true
168
+ ? eventName
169
+ : getSnapEventName(eventName);
170
+ const eventData = data['skipTransformation'] === true ? data : prepareData(data);
171
+ delete eventData['skipTransformation'];
172
+ if (STANDARD_SNAPCHAT_EVENTS.has(event)) {
173
+ executionContext.set('pixelFired', true);
174
+ window.snaptr('track', event, {
175
+ ...eventData,
176
+ client_dedup_id: eventId.toString(),
177
+ integration: 'blotout',
178
+ });
179
+ }
180
+ }
181
+ return result;
182
+ };
183
+
184
+ const data = {
185
+ name: 'snapchat',
186
+ tag,
187
+ init,
188
+ };
189
+ try {
190
+ if (window) {
191
+ if (!window.edgetagProviders) {
192
+ window.edgetagProviders = [];
193
+ }
194
+ window.edgetagProviders.push(data);
195
+ }
196
+ }
197
+ catch {
198
+ // No window
199
+ }
200
+
201
+ export { data as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-snapchat-sdk",
3
- "version": "0.26.4",
3
+ "version": "0.26.6",
4
4
  "description": "Snapchat 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
  ]