@blotoutio/edgetag-sdk-browser 0.70.1 → 0.72.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.
Files changed (2) hide show
  1. package/index.js +323 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -132,6 +132,292 @@
132
132
  ...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
133
133
  ]);
134
134
 
135
+ const isZeroPurchaseEvent = (payload) => {
136
+ var _a;
137
+ if (payload.eventName != 'Purchase') {
138
+ return false;
139
+ }
140
+ const value = parseFloat((_a = payload.data) === null || _a === void 0 ? void 0 : _a.value);
141
+ return value === 0;
142
+ };
143
+
144
+ /**
145
+ * ISO-3166 2-leter country codes and their names
146
+ * @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
147
+ */
148
+ const isoCountries = new Map([
149
+ ['AD', 'Andorra'],
150
+ ['AE', 'United Arab Emirates'],
151
+ ['AF', 'Afghanistan'],
152
+ ['AG', 'Antigua and Barbuda'],
153
+ ['AI', 'Anguilla'],
154
+ ['AL', 'Albania'],
155
+ ['AM', 'Armenia'],
156
+ ['AO', 'Angola'],
157
+ ['AQ', 'Antarctica'],
158
+ ['AR', 'Argentina'],
159
+ ['AS', 'American Samoa'],
160
+ ['AT', 'Austria'],
161
+ ['AU', 'Australia'],
162
+ ['AW', 'Aruba'],
163
+ ['AX', 'Åland Islands'],
164
+ ['AZ', 'Azerbaijan'],
165
+ ['BA', 'Bosnia and Herzegovina'],
166
+ ['BB', 'Barbados'],
167
+ ['BD', 'Bangladesh'],
168
+ ['BE', 'Belgium'],
169
+ ['BF', 'Burkina Faso'],
170
+ ['BG', 'Bulgaria'],
171
+ ['BH', 'Bahrain'],
172
+ ['BI', 'Burundi'],
173
+ ['BJ', 'Benin'],
174
+ ['BL', 'Saint Barthélemy'],
175
+ ['BM', 'Bermuda'],
176
+ ['BN', 'Brunei Darussalam'],
177
+ ['BO', 'Bolivia, Plurinational State of'],
178
+ ['BQ', 'Bonaire, Sint Eustatius and Saba'],
179
+ ['BR', 'Brazil'],
180
+ ['BS', 'Bahamas'],
181
+ ['BT', 'Bhutan'],
182
+ ['BV', 'Bouvet Island'],
183
+ ['BW', 'Botswana'],
184
+ ['BY', 'Belarus'],
185
+ ['BZ', 'Belize'],
186
+ ['CA', 'Canada'],
187
+ ['CC', 'Cocos (Keeling) Islands'],
188
+ ['CD', 'Congo, Democratic Republic of the'],
189
+ ['CF', 'Central African Republic'],
190
+ ['CG', 'Congo'],
191
+ ['CH', 'Switzerland'],
192
+ ['CI', "Côte d'Ivoire"],
193
+ ['CK', 'Cook Islands'],
194
+ ['CL', 'Chile'],
195
+ ['CM', 'Cameroon'],
196
+ ['CN', 'China'],
197
+ ['CO', 'Colombia'],
198
+ ['CR', 'Costa Rica'],
199
+ ['CU', 'Cuba'],
200
+ ['CV', 'Cabo Verde'],
201
+ ['CW', 'Curaçao'],
202
+ ['CX', 'Christmas Island'],
203
+ ['CY', 'Cyprus'],
204
+ ['CZ', 'Czechia'],
205
+ ['DE', 'Germany'],
206
+ ['DJ', 'Djibouti'],
207
+ ['DK', 'Denmark'],
208
+ ['DM', 'Dominica'],
209
+ ['DO', 'Dominican Republic'],
210
+ ['DZ', 'Algeria'],
211
+ ['EC', 'Ecuador'],
212
+ ['EE', 'Estonia'],
213
+ ['EG', 'Egypt'],
214
+ ['EH', 'Western Sahara'],
215
+ ['ER', 'Eritrea'],
216
+ ['ES', 'Spain'],
217
+ ['ET', 'Ethiopia'],
218
+ ['EU', 'European Union'],
219
+ ['FI', 'Finland'],
220
+ ['FJ', 'Fiji'],
221
+ ['FK', 'Falkland Islands (Malvinas)'],
222
+ ['FM', 'Micronesia, Federated States of'],
223
+ ['FO', 'Faroe Islands'],
224
+ ['FR', 'France'],
225
+ ['GA', 'Gabon'],
226
+ ['GB', 'United Kingdom of Great Britain and Northern Ireland'],
227
+ ['GD', 'Grenada'],
228
+ ['GE', 'Georgia'],
229
+ ['GF', 'French Guiana'],
230
+ ['GG', 'Guernsey'],
231
+ ['GH', 'Ghana'],
232
+ ['GI', 'Gibraltar'],
233
+ ['GL', 'Greenland'],
234
+ ['GM', 'Gambia'],
235
+ ['GN', 'Guinea'],
236
+ ['GP', 'Guadeloupe'],
237
+ ['GQ', 'Equatorial Guinea'],
238
+ ['GR', 'Greece'],
239
+ ['GS', 'South Georgia and the South Sandwich Islands'],
240
+ ['GT', 'Guatemala'],
241
+ ['GU', 'Guam'],
242
+ ['GW', 'Guinea-Bissau'],
243
+ ['GY', 'Guyana'],
244
+ ['HK', 'Hong Kong'],
245
+ ['HM', 'Heard Island and McDonald Islands'],
246
+ ['HN', 'Honduras'],
247
+ ['HR', 'Croatia'],
248
+ ['HT', 'Haiti'],
249
+ ['HU', 'Hungary'],
250
+ ['ID', 'Indonesia'],
251
+ ['IE', 'Ireland'],
252
+ ['IL', 'Israel'],
253
+ ['IM', 'Isle of Man'],
254
+ ['IN', 'India'],
255
+ ['IO', 'British Indian Ocean Territory'],
256
+ ['IQ', 'Iraq'],
257
+ ['IR', 'Iran, Islamic Republic of'],
258
+ ['IS', 'Iceland'],
259
+ ['IT', 'Italy'],
260
+ ['JE', 'Jersey'],
261
+ ['JM', 'Jamaica'],
262
+ ['JO', 'Jordan'],
263
+ ['JP', 'Japan'],
264
+ ['KE', 'Kenya'],
265
+ ['KG', 'Kyrgyzstan'],
266
+ ['KH', 'Cambodia'],
267
+ ['KI', 'Kiribati'],
268
+ ['KM', 'Comoros'],
269
+ ['KN', 'Saint Kitts and Nevis'],
270
+ ['KP', "Korea, Democratic People's Republic of"],
271
+ ['KR', 'Korea, Republic of'],
272
+ ['KW', 'Kuwait'],
273
+ ['KY', 'Cayman Islands'],
274
+ ['KZ', 'Kazakhstan'],
275
+ ['LA', "Lao People's Democratic Republic"],
276
+ ['LB', 'Lebanon'],
277
+ ['LC', 'Saint Lucia'],
278
+ ['LI', 'Liechtenstein'],
279
+ ['LK', 'Sri Lanka'],
280
+ ['LR', 'Liberia'],
281
+ ['LS', 'Lesotho'],
282
+ ['LT', 'Lithuania'],
283
+ ['LU', 'Luxembourg'],
284
+ ['LV', 'Latvia'],
285
+ ['LY', 'Libya'],
286
+ ['MA', 'Morocco'],
287
+ ['MC', 'Monaco'],
288
+ ['MD', 'Moldova, Republic of'],
289
+ ['ME', 'Montenegro'],
290
+ ['MF', 'Saint Martin (French part)'],
291
+ ['MG', 'Madagascar'],
292
+ ['MH', 'Marshall Islands'],
293
+ ['MK', 'North Macedonia'],
294
+ ['ML', 'Mali'],
295
+ ['MM', 'Myanmar'],
296
+ ['MN', 'Mongolia'],
297
+ ['MO', 'Macao'],
298
+ ['MP', 'Northern Mariana Islands'],
299
+ ['MQ', 'Martinique'],
300
+ ['MR', 'Mauritania'],
301
+ ['MS', 'Montserrat'],
302
+ ['MT', 'Malta'],
303
+ ['MU', 'Mauritius'],
304
+ ['MV', 'Maldives'],
305
+ ['MW', 'Malawi'],
306
+ ['MX', 'Mexico'],
307
+ ['MY', 'Malaysia'],
308
+ ['MZ', 'Mozambique'],
309
+ ['NA', 'Namibia'],
310
+ ['NC', 'New Caledonia'],
311
+ ['NE', 'Niger'],
312
+ ['NF', 'Norfolk Island'],
313
+ ['NG', 'Nigeria'],
314
+ ['NI', 'Nicaragua'],
315
+ ['NL', 'Netherlands, Kingdom of the'],
316
+ ['NO', 'Norway'],
317
+ ['NP', 'Nepal'],
318
+ ['NR', 'Nauru'],
319
+ ['NU', 'Niue'],
320
+ ['NZ', 'New Zealand'],
321
+ ['OM', 'Oman'],
322
+ ['PA', 'Panama'],
323
+ ['PE', 'Peru'],
324
+ ['PF', 'French Polynesia'],
325
+ ['PG', 'Papua New Guinea'],
326
+ ['PH', 'Philippines'],
327
+ ['PK', 'Pakistan'],
328
+ ['PL', 'Poland'],
329
+ ['PM', 'Saint Pierre and Miquelon'],
330
+ ['PN', 'Pitcairn'],
331
+ ['PR', 'Puerto Rico'],
332
+ ['PS', 'Palestine, State of'],
333
+ ['PT', 'Portugal'],
334
+ ['PW', 'Palau'],
335
+ ['PY', 'Paraguay'],
336
+ ['QA', 'Qatar'],
337
+ ['RE', 'Réunion'],
338
+ ['RO', 'Romania'],
339
+ ['RS', 'Serbia'],
340
+ ['RU', 'Russian Federation'],
341
+ ['RW', 'Rwanda'],
342
+ ['SA', 'Saudi Arabia'],
343
+ ['SB', 'Solomon Islands'],
344
+ ['SC', 'Seychelles'],
345
+ ['SD', 'Sudan'],
346
+ ['SE', 'Sweden'],
347
+ ['SG', 'Singapore'],
348
+ ['SH', 'Saint Helena, Ascension and Tristan da Cunha'],
349
+ ['SI', 'Slovenia'],
350
+ ['SJ', 'Svalbard and Jan Mayen'],
351
+ ['SK', 'Slovakia'],
352
+ ['SL', 'Sierra Leone'],
353
+ ['SM', 'San Marino'],
354
+ ['SN', 'Senegal'],
355
+ ['SO', 'Somalia'],
356
+ ['SR', 'Suriname'],
357
+ ['SS', 'South Sudan'],
358
+ ['ST', 'Sao Tome and Principe'],
359
+ ['SV', 'El Salvador'],
360
+ ['SX', 'Sint Maarten (Dutch part)'],
361
+ ['SY', 'Syrian Arab Republic'],
362
+ ['SZ', 'Eswatini'],
363
+ ['TC', 'Turks and Caicos Islands'],
364
+ ['TD', 'Chad'],
365
+ ['TF', 'French Southern Territories'],
366
+ ['TG', 'Togo'],
367
+ ['TH', 'Thailand'],
368
+ ['TJ', 'Tajikistan'],
369
+ ['TK', 'Tokelau'],
370
+ ['TL', 'Timor-Leste'],
371
+ ['TM', 'Turkmenistan'],
372
+ ['TN', 'Tunisia'],
373
+ ['TO', 'Tonga'],
374
+ ['TR', 'Türkiye'],
375
+ ['TT', 'Trinidad and Tobago'],
376
+ ['TV', 'Tuvalu'],
377
+ ['TW', 'Taiwan, Province of China'],
378
+ ['TZ', 'Tanzania, United Republic of'],
379
+ ['UA', 'Ukraine'],
380
+ ['UG', 'Uganda'],
381
+ ['UK', 'United Kingdom'],
382
+ ['UM', 'United States Minor Outlying Islands'],
383
+ ['US', 'United States of America'],
384
+ ['UY', 'Uruguay'],
385
+ ['UZ', 'Uzbekistan'],
386
+ ['VA', 'Holy See'],
387
+ ['VC', 'Saint Vincent and the Grenadines'],
388
+ ['VE', 'Venezuela, Bolivarian Republic of'],
389
+ ['VG', 'Virgin Islands (British)'],
390
+ ['VI', 'Virgin Islands (U.S.)'],
391
+ ['VN', 'Viet Nam'],
392
+ ['VU', 'Vanuatu'],
393
+ ['WF', 'Wallis and Futuna'],
394
+ ['WS', 'Samoa'],
395
+ ['YE', 'Yemen'],
396
+ ['YT', 'Mayotte'],
397
+ ['ZA', 'South Africa'],
398
+ ['ZM', 'Zambia'],
399
+ ['ZW', 'Zimbabwe'],
400
+ ]);
401
+ new Set(isoCountries.keys());
402
+ const parseCache = new Map();
403
+ const doesGeoRequestMatchList = (requestRegion, isEUCountry, geoRegions) => {
404
+ if (!requestRegion || !geoRegions) {
405
+ return true;
406
+ }
407
+ let parsedRegions = parseCache.get(geoRegions);
408
+ if (!parsedRegions) {
409
+ parsedRegions = new Set((geoRegions !== null && geoRegions !== void 0 ? geoRegions : '').split(','));
410
+ parseCache.set(geoRegions, parsedRegions);
411
+ }
412
+ if (parsedRegions.size == 0) {
413
+ return true;
414
+ }
415
+ if (isEUCountry && parsedRegions.has('EU')) {
416
+ return true;
417
+ }
418
+ return parsedRegions.has(requestRegion);
419
+ };
420
+
135
421
  // eslint-disable-next-line @nx/enforce-module-boundaries
136
422
  let edgeTagSettings;
137
423
  const initSettings = (destination, options) => {
@@ -144,6 +430,8 @@
144
430
  stubs: [],
145
431
  browserPackages: [],
146
432
  channels: new Map(),
433
+ geoRegion: null,
434
+ isEURequest: false,
147
435
  ...options,
148
436
  };
149
437
  };
@@ -182,6 +470,7 @@
182
470
  .filter((pkg) => pkg.package === packageId)
183
471
  .map((pkg) => ({
184
472
  tagName: pkg.tagName,
473
+ geoRegions: pkg.geoRegions || null,
185
474
  variableSet: pkg.variables || {},
186
475
  })) || []);
187
476
  };
@@ -563,7 +852,7 @@
563
852
  referrer: getReferrer(destination),
564
853
  search: getSearch(destination),
565
854
  locale: getLocale(),
566
- sdkVersion: "0.70.1" ,
855
+ sdkVersion: "0.72.0" ,
567
856
  ...(payload || {}),
568
857
  };
569
858
  let storage = {};
@@ -730,9 +1019,15 @@
730
1019
  }
731
1020
  const providerPackages = getSetting(destination, 'browserPackages');
732
1021
  const configuredTags = getSetting(destination, 'channels');
1022
+ const skipZeroPurchaseEvent = getSetting(destination, 'skipZeroPurchaseEvent') || false;
1023
+ const requestRegion = getSetting(destination, 'geoRegion') || null;
1024
+ const isEURequest = getSetting(destination, 'isEURequest') || false;
733
1025
  const userId = getUserId$1(destination);
734
1026
  const providerData = {};
735
1027
  const consent = getConsent$1(destination);
1028
+ if (skipZeroPurchaseEvent && isZeroPurchaseEvent({ eventName, data })) {
1029
+ return;
1030
+ }
736
1031
  const conversion = preparePayloadWithConversion(JSON.parse(JSON.stringify(data)), getSetting(destination, 'currency'));
737
1032
  for (const pkg of providerPackages) {
738
1033
  if (!pkg || !pkg.name || !pkg.tag) {
@@ -754,6 +1049,10 @@
754
1049
  logger.log(`Consent is missing (${pkg.name}: ${variable.tagName})`);
755
1050
  continue;
756
1051
  }
1052
+ if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
1053
+ logger.log('GEO request region does not match the filter, skiping');
1054
+ continue;
1055
+ }
757
1056
  const payload = ((_a = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
758
1057
  ((_b = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _b === void 0 ? void 0 : _b.includes(pkg.name))
759
1058
  ? conversion.payload
@@ -835,6 +1134,8 @@
835
1134
  const configuredTags = getSetting(destination, 'channels');
836
1135
  const userId = getUserId$1(destination);
837
1136
  const consent = getConsent$1(destination);
1137
+ const requestRegion = getSetting(destination, 'geoRegion') || null;
1138
+ const isEURequest = getSetting(destination, 'isEURequest') || false;
838
1139
  for (const pkg of providerPackages) {
839
1140
  if (!pkg || !pkg.user || !pkg.name) {
840
1141
  continue;
@@ -853,6 +1154,10 @@
853
1154
  logger.log(`Consent is missing for ${pkg.name} (${variable.tagName})`);
854
1155
  continue;
855
1156
  }
1157
+ if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
1158
+ logger.log(`GEO request region does not match list, skipping`);
1159
+ continue;
1160
+ }
856
1161
  pkg.user({
857
1162
  userId,
858
1163
  data,
@@ -913,6 +1218,8 @@
913
1218
  const userId = getUserId$1(destination);
914
1219
  const providerPackages = getSetting(destination, 'browserPackages');
915
1220
  const executionContext = new Map();
1221
+ const requestRegion = getSetting(destination, 'geoRegion') || null;
1222
+ const isEURequest = getSetting(destination, 'isEURequest') || false;
916
1223
  /* Calling Init for all provider instances based on consent check */
917
1224
  for (const pkg of providerPackages) {
918
1225
  if (!pkg || !pkg.name || !pkg.init) {
@@ -924,6 +1231,9 @@
924
1231
  if (!hasConsent) {
925
1232
  continue;
926
1233
  }
1234
+ if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
1235
+ continue;
1236
+ }
927
1237
  pkg.init({
928
1238
  userId,
929
1239
  isNewUser: false,
@@ -932,6 +1242,7 @@
932
1242
  tagName: variable.tagName,
933
1243
  variables: variable.variableSet,
934
1244
  package: pkg.name,
1245
+ geoRegions: variable.geoRegions,
935
1246
  },
936
1247
  sendTag: sendTag.bind(null, destination),
937
1248
  sendEdgeData: processData.bind(null, destination),
@@ -1130,7 +1441,8 @@
1130
1441
  if (pkg && pkg.name && pkg.init) {
1131
1442
  /* this defines if the consent is given for a specific instance of a provider */
1132
1443
  const hasConsent = hasUserConsent(getSetting(destination, 'consent'), pkg.name, provider.tagName);
1133
- if (hasConsent) {
1444
+ if (hasConsent &&
1445
+ doesGeoRequestMatchList(response.geoRegion, response.isEURequest, provider.geoRegions)) {
1134
1446
  pkg.init({
1135
1447
  userId,
1136
1448
  isNewUser: !!response.isNewUser,
@@ -1225,6 +1537,9 @@
1225
1537
  browserPackages: Object.values(providers),
1226
1538
  storageId: result.storageId,
1227
1539
  currency: result.currency,
1540
+ skipZeroPurchaseEvent: result.skipZeroPurchaseEvent,
1541
+ geoRegion: result.geoRegion,
1542
+ isEURequest: result.isEURequest,
1228
1543
  });
1229
1544
  if (result.storageId != null) {
1230
1545
  savePerKey(preferences.edgeURL, 'local', tagStorage, result.storageId, storageIdKey);
@@ -1257,6 +1572,8 @@
1257
1572
  const configuredTags = getSetting(destination, 'channels');
1258
1573
  const consent = getConsent$1(destination);
1259
1574
  const userId = getUserId$1(destination);
1575
+ const requestRegion = getSetting(destination, 'geoRegion') || null;
1576
+ const isEURequest = getSetting(destination, 'isEURequest') || false;
1260
1577
  for (const pkg of providerPackages) {
1261
1578
  if (!pkg || !pkg.name || !pkg.user) {
1262
1579
  continue;
@@ -1275,6 +1592,10 @@
1275
1592
  logger.log(`User do not have consent for ${pkg.name} (${variable.tagName})`);
1276
1593
  continue;
1277
1594
  }
1595
+ if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
1596
+ logger.log(`GEO request region does not match list, skipping`);
1597
+ continue;
1598
+ }
1278
1599
  pkg.user({
1279
1600
  userId,
1280
1601
  data: { [key]: value },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.70.1",
3
+ "version": "0.72.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",