@blotoutio/providers-snapchat-sdk 1.68.2 → 1.69.1

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 (4) hide show
  1. package/index.cjs.js +742 -14
  2. package/index.js +742 -14
  3. package/index.mjs +742 -14
  4. package/package.json +1 -1
package/index.mjs CHANGED
@@ -34,7 +34,725 @@ const STANDARD_SNAPCHAT_EVENTS = new Set([
34
34
  'CUSTOM_EVENT_5',
35
35
  ]);
36
36
 
37
- // eslint-disable-next-line @nx/enforce-module-boundaries
37
+ const keyPrefix = `_worker`;
38
+
39
+ const getProductIdFromMapping = (item, productIdMapping) => {
40
+ if (productIdMapping === '1' && item['variantId']) {
41
+ return item['variantId'];
42
+ }
43
+ if (productIdMapping === '2' && item['sku']) {
44
+ return item['sku'];
45
+ }
46
+ return item['id'];
47
+ };
48
+
49
+ const initKey = `${keyPrefix}StoreMultiple`;
50
+ const getData = (destination, persistType, key = initKey) => {
51
+ let data;
52
+ if (persistType === 'session') {
53
+ data = getSession(key);
54
+ }
55
+ else {
56
+ data = getLocal(key);
57
+ }
58
+ return (data === null || data === void 0 ? void 0 : data[destination]) || {};
59
+ };
60
+ const getLocal = (key) => {
61
+ try {
62
+ if (!localStorage) {
63
+ return {};
64
+ }
65
+ const data = localStorage.getItem(key);
66
+ if (!data) {
67
+ return {};
68
+ }
69
+ return JSON.parse(data) || {};
70
+ }
71
+ catch {
72
+ return {};
73
+ }
74
+ };
75
+ const getSession = (key) => {
76
+ try {
77
+ if (!sessionStorage) {
78
+ return {};
79
+ }
80
+ const data = sessionStorage.getItem(key);
81
+ if (!data) {
82
+ return {};
83
+ }
84
+ return JSON.parse(data) || {};
85
+ }
86
+ catch {
87
+ return {};
88
+ }
89
+ };
90
+
91
+ /**
92
+ * Known ad-network click ID query parameters and the human-readable provider
93
+ * label each one maps to. Used by the CDN worker to resolve `inSessionTouch`
94
+ * and by the analytics API to classify paid-media touch sessions.
95
+ *
96
+ * Keep this list in sync with `defaultParams` in queryParams.ts when new
97
+ * click ID providers are added.
98
+ */
99
+ const CLICK_IDS = [
100
+ { param: 'fbclid', label: 'Facebook' }, // Facebook Ads
101
+ { param: 'gclid', label: 'Google' }, // Google Ads (click)
102
+ { param: 'gbraid', label: 'Google' }, // Google Ads (iOS app)
103
+ { param: 'wbraid', label: 'Google' }, // Google Ads (iOS web)
104
+ { param: 'msclkid', label: 'Bing' }, // Microsoft Bing Ads
105
+ { param: 'ttclid', label: 'TikTok' }, // TikTok Ads
106
+ { param: 'ScCid', label: 'Snapchat' }, // Snapchat Ads
107
+ { param: 'epik', label: 'Pinterest' }, // Pinterest Ads
108
+ { param: 'li_fat_id', label: 'LinkedIn' }, // LinkedIn Ads
109
+ { param: 'twclid', label: 'Twitter' }, // X (Twitter) Ads
110
+ { param: 'rdt_cid', label: 'Reddit' }, // Reddit Ads
111
+ { param: 'aleid', label: 'AppLovin' }, // AppLovin
112
+ { param: 'tabclid', label: 'Taboola' }, // Taboola
113
+ { param: 'obclid', label: 'Outbrain' }, // Outbrain
114
+ { param: 'trybe', label: 'Trybe' }, // Trybe
115
+ { param: '_kx', label: 'Klaviyo' }, // Klaviyo email campaigns
116
+ { param: 'mc_eid', label: 'Mailchimp' }, // Mailchimp email campaigns
117
+ { param: 'ttd_id', label: 'The Trade Desk' }, // The Trade Desk programmatic
118
+ { param: 'evsclid', label: 'EvoSearch' }, // EvoSearch
119
+ { param: 'li_did', label: 'Live Intent' }, // LiveIntent device-level ad
120
+ { param: '_raclid', label: 'Rumble' }, // Rumble Ads
121
+ { param: 'ref_id', label: 'StackAdapt' }, // StackAdapt programmatic
122
+ { param: 'duel_a', label: 'Duel' }, // Duel referral/advocacy
123
+ ];
124
+
125
+ const expand = (str) => str.split(',').flatMap((entry) => {
126
+ if (!entry.includes('-')) {
127
+ return entry;
128
+ }
129
+ const result = [];
130
+ const [start, end] = entry.split('-').map(Number);
131
+ for (let i = start; i <= end; i++) {
132
+ result.push(i.toString());
133
+ }
134
+ return result;
135
+ });
136
+ /**
137
+ * Exported from https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes
138
+ *
139
+ * In Dev Tools, select the `tbody` element containing the area codes and run the following code,
140
+ * replacing the emdash character with a simple endash:
141
+ *
142
+ * ```ts
143
+ * [...$0.querySelectorAll('td:first-child')]
144
+ * .filter(cell => cell.firstChild.nodeName != 'A')
145
+ * .map(cell => cell.textContent.trim()).join(',')
146
+ * ```
147
+ */
148
+ const invalidNANPAreaCodes = new Set([
149
+ ...expand('200,211,221,222,230,232,233,235,237-238,241,243,244,245,247,255,257,258-259,261,265,266,271,273,274,275,277,278,280,282,283,285-287,288,290-299'),
150
+ ...expand('300,311,322,324,327,328,333,335,338,342,344,348-349,353,355,356,357-359,362,366,369,370-379,381,382,383-384,387,388,389,390-399'),
151
+ ...expand('400,411,420,421-422,426-427,428,429,433,439,444,446,449,451-454,455,456,457,459,460,461-462,465,466,467,471,476,477,481-483,485-486,487,488,489,490-499'),
152
+ ...expand('511,532,535,536,537,538,542-543,545-547,549-550,552-554,555,556,558,560,565,568,569,576,578,583,589,590-599'),
153
+ ...expand('611,621,624,625,627,632,633,634-635,637-638,642-643,644,648,652-654,655,663,665,666,668,673-676,677,679,685,686,687,688,690-699'),
154
+ ...expand('711,722,723,729,733,735-736,739,741,744,745-746,748,749-751,752,755,756,759,761,764,766,768,776,777,783,788,789,790-799'),
155
+ ...expand('811,821,822,823-824,827,834,836,841-842,846,851,852-853,871,874-875,879,880-887,889,890-899'),
156
+ ...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'),
157
+ ]);
158
+ const isValidZone1AreaCode = (num) => {
159
+ if (!/^[2-9]\d{2}$/.test(num)) {
160
+ return false;
161
+ }
162
+ return !invalidNANPAreaCodes.has(num);
163
+ };
164
+
165
+ // North America; assume local numbers as NANP
166
+ const ZONE_1 = /^[+]1([2-9][0-8][0-9])[2-9][0-9]{6}$/;
167
+ // Africa
168
+ const ZONE_2 = /^[+]2([07][0-9]{4,13}|(1[12368]|[234][0-9]|5[0-8]|6[0-9]|9[01789])[0-9]{4,12})$/;
169
+ // Europe
170
+ const EU_TWO_DIGIT = `(3[0-469]|4[013-9])[0-9]{4,15}`;
171
+ const EU_THREE_DIGIT = `((3[578]|42)[0-9])[0-9]{4,12}`;
172
+ const ZONE_3_4 = new RegExp(`^[+](${EU_TWO_DIGIT}|${EU_THREE_DIGIT})$`);
173
+ // South America
174
+ const ZONE_5 = /^[+]5([1-8][0-9]{4,13}|[09][0-9][0-9]{4,12})$/;
175
+ // Southeast Asia & Oceania
176
+ const ZONE_6 = /^[+]6([0-6][0-9]{4,13}|(7[02-9]|8[0-35-9]|9[0-2])[0-9]{4,12})$/;
177
+ // Russia & Kazakhstan
178
+ const ZONE_7 = /^[+]7([1-9])[0-9]{4,13}$/;
179
+ // East & South Asia
180
+ const ZONE_8 = /^[+]8([1246][0-9]{4,13}|(0[08]|5[02356]|70|8[0-36])[0-9]{4,12})$/;
181
+ // Middle East, West & Central Asia, South Asia, Eastern Europe
182
+ const ZONE_9 = /^[+]9([0123458][0-9]{4,13}|(6[0-8]|7[0-79]|9[2-8])[0-9]{4,12})$/;
183
+ const checkers = [
184
+ (num) => {
185
+ const match = num.match(ZONE_1);
186
+ if (!match) {
187
+ return false;
188
+ }
189
+ return isValidZone1AreaCode(match[1]);
190
+ },
191
+ (num) => ZONE_2.test(num),
192
+ (num) => ZONE_3_4.test(num),
193
+ (num) => ZONE_5.test(num),
194
+ (num) => ZONE_6.test(num),
195
+ (num) => ZONE_7.test(num),
196
+ (num) => ZONE_8.test(num),
197
+ (num) => ZONE_9.test(num),
198
+ ];
199
+ /**
200
+ * Returns a boolean indicating whether or not a phone number conforms to a
201
+ * plausible E.164 phone number. It does not guarantee validity as each national
202
+ * operator may have various phone number lengths per area code or national
203
+ * scheme. It only validates currently active country codes and length
204
+ * restrictions.
205
+ *
206
+ * > *NOTE:* `E.164` format requires a leading plus sign, so you must set
207
+ * > `keepPlus` to `true` when normalising numbers:
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * const number = isPlausibleE164Number(normalizePhoneNumber(str, true))
212
+ * ```
213
+ */
214
+ const isPlausibleE164Number = (str) => str.startsWith('+') && checkers.some((check) => check(str));
215
+ const INTL_PREFIX = /^00|[+]+/;
216
+ /**
217
+ * Attempts to convert a given phone number string into an E.164 formatted
218
+ * number. In order to check whether the number is plausibly a real number, it
219
+ * must be checked with `isPlausibleE164Number` after normalising.
220
+ */
221
+ const normalizePhoneNumber = (str, keepPlus = false) => {
222
+ if (!str) {
223
+ return '';
224
+ }
225
+ let normalized = str;
226
+ // assume non-international numbers are US numbers
227
+ if (!INTL_PREFIX.test(normalized)) {
228
+ normalized = `+1${normalized}`;
229
+ }
230
+ normalized = normalized.replace(/[^+0-9]/g, '').replace(INTL_PREFIX, '+');
231
+ return keepPlus ? normalized : normalized.slice(1);
232
+ };
233
+
234
+ /**
235
+ * ISO-3166 2-leter country codes and their names
236
+ * @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
237
+ */
238
+ const isoCountries = new Map([
239
+ ['AD', 'Andorra'],
240
+ ['AE', 'United Arab Emirates'],
241
+ ['AF', 'Afghanistan'],
242
+ ['AG', 'Antigua and Barbuda'],
243
+ ['AI', 'Anguilla'],
244
+ ['AL', 'Albania'],
245
+ ['AM', 'Armenia'],
246
+ ['AO', 'Angola'],
247
+ ['AQ', 'Antarctica'],
248
+ ['AR', 'Argentina'],
249
+ ['AS', 'American Samoa'],
250
+ ['AT', 'Austria'],
251
+ ['AU', 'Australia'],
252
+ ['AW', 'Aruba'],
253
+ ['AX', 'Åland Islands'],
254
+ ['AZ', 'Azerbaijan'],
255
+ ['BA', 'Bosnia and Herzegovina'],
256
+ ['BB', 'Barbados'],
257
+ ['BD', 'Bangladesh'],
258
+ ['BE', 'Belgium'],
259
+ ['BF', 'Burkina Faso'],
260
+ ['BG', 'Bulgaria'],
261
+ ['BH', 'Bahrain'],
262
+ ['BI', 'Burundi'],
263
+ ['BJ', 'Benin'],
264
+ ['BL', 'Saint Barthélemy'],
265
+ ['BM', 'Bermuda'],
266
+ ['BN', 'Brunei Darussalam'],
267
+ ['BO', 'Bolivia, Plurinational State of'],
268
+ ['BQ', 'Bonaire, Sint Eustatius and Saba'],
269
+ ['BR', 'Brazil'],
270
+ ['BS', 'Bahamas'],
271
+ ['BT', 'Bhutan'],
272
+ ['BV', 'Bouvet Island'],
273
+ ['BW', 'Botswana'],
274
+ ['BY', 'Belarus'],
275
+ ['BZ', 'Belize'],
276
+ ['CA', 'Canada'],
277
+ ['CC', 'Cocos (Keeling) Islands'],
278
+ ['CD', 'Congo, Democratic Republic of the'],
279
+ ['CF', 'Central African Republic'],
280
+ ['CG', 'Congo'],
281
+ ['CH', 'Switzerland'],
282
+ ['CI', "Côte d'Ivoire"],
283
+ ['CK', 'Cook Islands'],
284
+ ['CL', 'Chile'],
285
+ ['CM', 'Cameroon'],
286
+ ['CN', 'China'],
287
+ ['CO', 'Colombia'],
288
+ ['CR', 'Costa Rica'],
289
+ ['CU', 'Cuba'],
290
+ ['CV', 'Cabo Verde'],
291
+ ['CW', 'Curaçao'],
292
+ ['CX', 'Christmas Island'],
293
+ ['CY', 'Cyprus'],
294
+ ['CZ', 'Czechia'],
295
+ ['DE', 'Germany'],
296
+ ['DJ', 'Djibouti'],
297
+ ['DK', 'Denmark'],
298
+ ['DM', 'Dominica'],
299
+ ['DO', 'Dominican Republic'],
300
+ ['DZ', 'Algeria'],
301
+ ['EC', 'Ecuador'],
302
+ ['EE', 'Estonia'],
303
+ ['EG', 'Egypt'],
304
+ ['EH', 'Western Sahara'],
305
+ ['ER', 'Eritrea'],
306
+ ['ES', 'Spain'],
307
+ ['ET', 'Ethiopia'],
308
+ ['EU', 'European Union'],
309
+ ['FI', 'Finland'],
310
+ ['FJ', 'Fiji'],
311
+ ['FK', 'Falkland Islands (Malvinas)'],
312
+ ['FM', 'Micronesia, Federated States of'],
313
+ ['FO', 'Faroe Islands'],
314
+ ['FR', 'France'],
315
+ ['GA', 'Gabon'],
316
+ ['GB', 'Great Britain'],
317
+ ['GD', 'Grenada'],
318
+ ['GE', 'Georgia'],
319
+ ['GF', 'French Guiana'],
320
+ ['GG', 'Guernsey'],
321
+ ['GH', 'Ghana'],
322
+ ['GI', 'Gibraltar'],
323
+ ['GL', 'Greenland'],
324
+ ['GM', 'Gambia'],
325
+ ['GN', 'Guinea'],
326
+ ['GP', 'Guadeloupe'],
327
+ ['GQ', 'Equatorial Guinea'],
328
+ ['GR', 'Greece'],
329
+ ['GS', 'South Georgia and the South Sandwich Islands'],
330
+ ['GT', 'Guatemala'],
331
+ ['GU', 'Guam'],
332
+ ['GW', 'Guinea-Bissau'],
333
+ ['GY', 'Guyana'],
334
+ ['HK', 'Hong Kong'],
335
+ ['HM', 'Heard Island and McDonald Islands'],
336
+ ['HN', 'Honduras'],
337
+ ['HR', 'Croatia'],
338
+ ['HT', 'Haiti'],
339
+ ['HU', 'Hungary'],
340
+ ['ID', 'Indonesia'],
341
+ ['IE', 'Ireland'],
342
+ ['IL', 'Israel'],
343
+ ['IM', 'Isle of Man'],
344
+ ['IN', 'India'],
345
+ ['IO', 'British Indian Ocean Territory'],
346
+ ['IQ', 'Iraq'],
347
+ ['IR', 'Iran, Islamic Republic of'],
348
+ ['IS', 'Iceland'],
349
+ ['IT', 'Italy'],
350
+ ['JE', 'Jersey'],
351
+ ['JM', 'Jamaica'],
352
+ ['JO', 'Jordan'],
353
+ ['JP', 'Japan'],
354
+ ['KE', 'Kenya'],
355
+ ['KG', 'Kyrgyzstan'],
356
+ ['KH', 'Cambodia'],
357
+ ['KI', 'Kiribati'],
358
+ ['KM', 'Comoros'],
359
+ ['KN', 'Saint Kitts and Nevis'],
360
+ ['KP', "Korea, Democratic People's Republic of"],
361
+ ['KR', 'Korea, Republic of'],
362
+ ['KW', 'Kuwait'],
363
+ ['KY', 'Cayman Islands'],
364
+ ['KZ', 'Kazakhstan'],
365
+ ['LA', "Lao People's Democratic Republic"],
366
+ ['LB', 'Lebanon'],
367
+ ['LC', 'Saint Lucia'],
368
+ ['LI', 'Liechtenstein'],
369
+ ['LK', 'Sri Lanka'],
370
+ ['LR', 'Liberia'],
371
+ ['LS', 'Lesotho'],
372
+ ['LT', 'Lithuania'],
373
+ ['LU', 'Luxembourg'],
374
+ ['LV', 'Latvia'],
375
+ ['LY', 'Libya'],
376
+ ['MA', 'Morocco'],
377
+ ['MC', 'Monaco'],
378
+ ['MD', 'Moldova, Republic of'],
379
+ ['ME', 'Montenegro'],
380
+ ['MF', 'Saint Martin (French part)'],
381
+ ['MG', 'Madagascar'],
382
+ ['MH', 'Marshall Islands'],
383
+ ['MK', 'North Macedonia'],
384
+ ['ML', 'Mali'],
385
+ ['MM', 'Myanmar'],
386
+ ['MN', 'Mongolia'],
387
+ ['MO', 'Macao'],
388
+ ['MP', 'Northern Mariana Islands'],
389
+ ['MQ', 'Martinique'],
390
+ ['MR', 'Mauritania'],
391
+ ['MS', 'Montserrat'],
392
+ ['MT', 'Malta'],
393
+ ['MU', 'Mauritius'],
394
+ ['MV', 'Maldives'],
395
+ ['MW', 'Malawi'],
396
+ ['MX', 'Mexico'],
397
+ ['MY', 'Malaysia'],
398
+ ['MZ', 'Mozambique'],
399
+ ['NA', 'Namibia'],
400
+ ['NC', 'New Caledonia'],
401
+ ['NE', 'Niger'],
402
+ ['NF', 'Norfolk Island'],
403
+ ['NG', 'Nigeria'],
404
+ ['NI', 'Nicaragua'],
405
+ ['NL', 'Netherlands, Kingdom of the'],
406
+ ['NO', 'Norway'],
407
+ ['NP', 'Nepal'],
408
+ ['NR', 'Nauru'],
409
+ ['NU', 'Niue'],
410
+ ['NZ', 'New Zealand'],
411
+ ['OM', 'Oman'],
412
+ ['PA', 'Panama'],
413
+ ['PE', 'Peru'],
414
+ ['PF', 'French Polynesia'],
415
+ ['PG', 'Papua New Guinea'],
416
+ ['PH', 'Philippines'],
417
+ ['PK', 'Pakistan'],
418
+ ['PL', 'Poland'],
419
+ ['PM', 'Saint Pierre and Miquelon'],
420
+ ['PN', 'Pitcairn'],
421
+ ['PR', 'Puerto Rico'],
422
+ ['PS', 'Palestine, State of'],
423
+ ['PT', 'Portugal'],
424
+ ['PW', 'Palau'],
425
+ ['PY', 'Paraguay'],
426
+ ['QA', 'Qatar'],
427
+ ['RE', 'Réunion'],
428
+ ['RO', 'Romania'],
429
+ ['RS', 'Serbia'],
430
+ ['RU', 'Russian Federation'],
431
+ ['RW', 'Rwanda'],
432
+ ['SA', 'Saudi Arabia'],
433
+ ['SB', 'Solomon Islands'],
434
+ ['SC', 'Seychelles'],
435
+ ['SD', 'Sudan'],
436
+ ['SE', 'Sweden'],
437
+ ['SG', 'Singapore'],
438
+ ['SH', 'Saint Helena, Ascension and Tristan da Cunha'],
439
+ ['SI', 'Slovenia'],
440
+ ['SJ', 'Svalbard and Jan Mayen'],
441
+ ['SK', 'Slovakia'],
442
+ ['SL', 'Sierra Leone'],
443
+ ['SM', 'San Marino'],
444
+ ['SN', 'Senegal'],
445
+ ['SO', 'Somalia'],
446
+ ['SR', 'Suriname'],
447
+ ['SS', 'South Sudan'],
448
+ ['ST', 'Sao Tome and Principe'],
449
+ ['SV', 'El Salvador'],
450
+ ['SX', 'Sint Maarten (Dutch part)'],
451
+ ['SY', 'Syrian Arab Republic'],
452
+ ['SZ', 'Eswatini'],
453
+ ['TC', 'Turks and Caicos Islands'],
454
+ ['TD', 'Chad'],
455
+ ['TF', 'French Southern Territories'],
456
+ ['TG', 'Togo'],
457
+ ['TH', 'Thailand'],
458
+ ['TJ', 'Tajikistan'],
459
+ ['TK', 'Tokelau'],
460
+ ['TL', 'Timor-Leste'],
461
+ ['TM', 'Turkmenistan'],
462
+ ['TN', 'Tunisia'],
463
+ ['TO', 'Tonga'],
464
+ ['TR', 'Türkiye'],
465
+ ['TT', 'Trinidad and Tobago'],
466
+ ['TV', 'Tuvalu'],
467
+ ['TW', 'Taiwan, Province of China'],
468
+ ['TZ', 'Tanzania, United Republic of'],
469
+ ['UA', 'Ukraine'],
470
+ ['UG', 'Uganda'],
471
+ ['UK', 'United Kingdom of Great Britain and Northern Ireland'],
472
+ ['UM', 'United States Minor Outlying Islands'],
473
+ ['US', 'United States of America'],
474
+ ['UY', 'Uruguay'],
475
+ ['UZ', 'Uzbekistan'],
476
+ ['VA', 'Holy See'],
477
+ ['VC', 'Saint Vincent and the Grenadines'],
478
+ ['VE', 'Venezuela, Bolivarian Republic of'],
479
+ ['VG', 'Virgin Islands (British)'],
480
+ ['VI', 'Virgin Islands (U.S.)'],
481
+ ['VN', 'Viet Nam'],
482
+ ['VU', 'Vanuatu'],
483
+ ['WF', 'Wallis and Futuna'],
484
+ ['WS', 'Samoa'],
485
+ ['YE', 'Yemen'],
486
+ ['YT', 'Mayotte'],
487
+ ['ZA', 'South Africa'],
488
+ ['ZM', 'Zambia'],
489
+ ['ZW', 'Zimbabwe'],
490
+ ]);
491
+ /**
492
+ * ISO-3166 US state ISO codes
493
+ * @see https://en.wikipedia.org/wiki/ISO_3166-2:US
494
+ * */
495
+ const usStates = new Map([
496
+ ['US-AL', 'Alabama'],
497
+ ['US-AK', 'Alaska'],
498
+ ['US-AZ', 'Arizona'],
499
+ ['US-AR', 'Arkansas'],
500
+ ['US-CA', 'California'],
501
+ ['US-CO', 'Colorado'],
502
+ ['US-CT', 'Connecticut'],
503
+ ['US-DE', 'Delaware'],
504
+ ['US-FL', 'Florida'],
505
+ ['US-GA', 'Georgia'],
506
+ ['US-HI', 'Hawaii'],
507
+ ['US-ID', 'Idaho'],
508
+ ['US-IL', 'Illinois'],
509
+ ['US-IN', 'Indiana'],
510
+ ['US-IA', 'Iowa'],
511
+ ['US-KS', 'Kansas'],
512
+ ['US-KY', 'Kentucky'],
513
+ ['US-LA', 'Louisiana'],
514
+ ['US-ME', 'Maine'],
515
+ ['US-MD', 'Maryland'],
516
+ ['US-MA', 'Massachusetts'],
517
+ ['US-MI', 'Michigan'],
518
+ ['US-MN', 'Minnesota'],
519
+ ['US-MS', 'Mississippi'],
520
+ ['US-MO', 'Missouri'],
521
+ ['US-MT', 'Montana'],
522
+ ['US-NE', 'Nebraska'],
523
+ ['US-NV', 'Nevada'],
524
+ ['US-NH', 'New Hampshire'],
525
+ ['US-NJ', 'New Jersey'],
526
+ ['US-NM', 'New Mexico'],
527
+ ['US-NY', 'New York'],
528
+ ['US-NC', 'North Carolina'],
529
+ ['US-ND', 'North Dakota'],
530
+ ['US-OH', 'Ohio'],
531
+ ['US-OK', 'Oklahoma'],
532
+ ['US-OR', 'Oregon'],
533
+ ['US-PA', 'Pennsylvania'],
534
+ ['US-RI', 'Rhode Island'],
535
+ ['US-SC', 'South Carolina'],
536
+ ['US-SD', 'South Dakota'],
537
+ ['US-TN', 'Tennessee'],
538
+ ['US-TX', 'Texas'],
539
+ ['US-UT', 'Utah'],
540
+ ['US-VT', 'Vermont'],
541
+ ['US-VA', 'Virginia'],
542
+ ['US-WA', 'Washington'],
543
+ ['US-WV', 'West Virginia'],
544
+ ['US-WI', 'Wisconsin'],
545
+ ['US-WY', 'Wyoming'],
546
+ ['US-DC', 'District of Columbia'],
547
+ ['US-AS', 'American Samoa'],
548
+ ['US-GU', 'Guam'],
549
+ ['US-MP', 'Northern Mariana Islands'],
550
+ ['US-PR', 'Puerto Rico'],
551
+ ['US-UM', 'United States Minor Outlying Islands'],
552
+ ['US-VI', 'Virgin Islands, U.S.'],
553
+ ]);
554
+ /**
555
+ * ISO 3166-2:CA province and territory codes, keyed `CA-XX` to mirror
556
+ * `usStates`. Used by the consent banner's Canada region to offer province
557
+ * selection (Québec is treated specially by the regional consent config).
558
+ */
559
+ const caProvinces = new Map([
560
+ ['CA-AB', 'Alberta'],
561
+ ['CA-BC', 'British Columbia'],
562
+ ['CA-MB', 'Manitoba'],
563
+ ['CA-NB', 'New Brunswick'],
564
+ ['CA-NL', 'Newfoundland and Labrador'],
565
+ ['CA-NS', 'Nova Scotia'],
566
+ ['CA-NT', 'Northwest Territories'],
567
+ ['CA-NU', 'Nunavut'],
568
+ ['CA-ON', 'Ontario'],
569
+ ['CA-PE', 'Prince Edward Island'],
570
+ ['CA-QC', 'Quebec'],
571
+ ['CA-SK', 'Saskatchewan'],
572
+ ['CA-YT', 'Yukon'],
573
+ ]);
574
+ new Set([
575
+ ...isoCountries.keys(),
576
+ ...usStates.keys(),
577
+ ...caProvinces.keys(),
578
+ ]);
579
+
580
+ /**
581
+ * Exact utm_source normalization (lowercase key → canonical name).
582
+ *
583
+ * Use exact match when the key is short, generic, or must not accidentally
584
+ * absorb variant spellings (e.g. "impact" must not match "impact_radius").
585
+ *
586
+ * Ordering: Paid (search/social → ad networks → affiliates) →
587
+ * Organic (AI/discovery) → Retention (email → SMS → push → post-purchase)
588
+ */
589
+ const UTM_SOURCE_EXACT = {
590
+ // ── Paid – Search & Social ────────────────────────────────────────────────
591
+ google: 'Google',
592
+ adwords: 'Google',
593
+ youtube: 'Google',
594
+ yt: 'Google',
595
+ meta: 'Facebook',
596
+ facebook: 'Facebook',
597
+ instagram: 'Facebook',
598
+ ig: 'Facebook',
599
+ igshopping: 'Facebook',
600
+ threads: 'Facebook',
601
+ twitter: 'Twitter',
602
+ snapchat: 'Snapchat',
603
+ pinterest: 'Pinterest',
604
+ bing: 'Bing',
605
+ microsoft: 'Bing',
606
+ tiktok: 'TikTok',
607
+ // ── Paid – Ad Networks ───────────────────────────────────────────────────
608
+ rtbhouse: 'RTB House',
609
+ applovin: 'AppLovin',
610
+ ttd: 'The Trade Desk',
611
+ amazondsp: 'Amazon DSP',
612
+ axon: 'Axon',
613
+ duel: 'Duel',
614
+ // ── Paid – Affiliates ────────────────────────────────────────────────────
615
+ awin: 'Awin',
616
+ 'affiliate-cj': 'CJ Affiliate',
617
+ impact: 'Impact',
618
+ rakuten: 'Rakuten',
619
+ superfiliate: 'Superfiliate',
620
+ // ── Organic – AI & Discovery ─────────────────────────────────────────────
621
+ perplexity: 'Perplexity',
622
+ chatgpt: 'ChatGPT',
623
+ 'chatgpt.com': 'ChatGPT',
624
+ openai: 'ChatGPT',
625
+ 'copilot.com': 'Microsoft Copilot',
626
+ copilot: 'Microsoft Copilot',
627
+ applenews: 'Apple News',
628
+ whatsapp: 'WhatsApp',
629
+ podcast: 'Podcast',
630
+ // ── Retention – Email ────────────────────────────────────────────────────
631
+ mailchimp: 'Mailchimp',
632
+ omnisend: 'Omnisend',
633
+ iterable: 'Iterable',
634
+ listrak: 'Listrak',
635
+ sailthru: 'Sailthru',
636
+ // ── Retention – Push ─────────────────────────────────────────────────────
637
+ pushowl: 'PushOwl',
638
+ // ── Retention – Post-purchase / Payment ──────────────────────────────────
639
+ narvar: 'Narvar',
640
+ shop_app: 'Shop App',
641
+ salesforce: 'Salesforce',
642
+ yotpo: 'Yotpo',
643
+ };
644
+ /**
645
+ * Partial utm_source normalization (startsWith prefix check, lowercase).
646
+ *
647
+ * Checked after exact match so short exact keys (e.g. "ig", "yt") win first.
648
+ */
649
+ const UTM_SOURCE_PARTIAL = [
650
+ // ── Paid – Social ─────────────────────────────────────────────────────────
651
+ { prefix: 'tiktok', name: 'TikTok' },
652
+ // ── Paid – Ad Networks ───────────────────────────────────────────────────
653
+ { prefix: 'criteo', name: 'Criteo' },
654
+ // ── Retention – Email ────────────────────────────────────────────────────
655
+ { prefix: 'klaviyo', name: 'Klaviyo' },
656
+ // ── Retention – SMS ──────────────────────────────────────────────────────
657
+ { prefix: 'attentive', name: 'Attentive' },
658
+ { prefix: 'postscript', name: 'Postscript' },
659
+ // ── Retention – Post-purchase / Payment ──────────────────────────────────
660
+ { prefix: 'afterpay', name: 'Afterpay' },
661
+ { prefix: 'klarna', name: 'Klarna' },
662
+ ];
663
+ const ORGANIC_SEARCH_ENGINES = [
664
+ { match: 'google', name: 'Google' },
665
+ { match: 'bing', name: 'Bing' },
666
+ { match: 'yahoo', name: 'Yahoo' },
667
+ { match: 'duckduckgo', name: 'DuckDuckGo' },
668
+ { match: 'baidu', name: 'Baidu' },
669
+ { match: 'yandex', name: 'Yandex' },
670
+ { match: 'brave', name: 'Brave' },
671
+ ];
672
+ const KNOWN_REFERRAL_PLATFORMS = [
673
+ { match: 'facebook', name: 'Facebook' },
674
+ { match: 'instagram', name: 'Facebook' },
675
+ { match: 'twitter', name: 'Twitter' },
676
+ { match: 'x.com', name: 'Twitter' },
677
+ { match: 'tiktok', name: 'TikTok' },
678
+ { match: 'pinterest', name: 'Pinterest' },
679
+ { match: 'linkedin', name: 'LinkedIn' },
680
+ { match: 'youtube', name: 'YouTube' },
681
+ { match: 'chatgpt', name: 'ChatGPT' },
682
+ { match: 'claude', name: 'Claude' },
683
+ { match: 'perplexity', name: 'Perplexity' },
684
+ { match: 'shop.app', name: 'Shop App' },
685
+ { match: 'amazon', name: 'Amazon' },
686
+ { match: 'attentive', name: 'Attentive' },
687
+ ];
688
+ const OFFLINE_TOUCH = 'Blotout_Offline';
689
+ new Set([
690
+ ...CLICK_IDS.map((c) => c.label),
691
+ ...Object.values(UTM_SOURCE_EXACT),
692
+ ...UTM_SOURCE_PARTIAL.map((e) => e.name),
693
+ ...ORGANIC_SEARCH_ENGINES.map((e) => `Organic Search - ${e.name}`),
694
+ ...KNOWN_REFERRAL_PLATFORMS.map((e) => `Referral - ${e.name}`),
695
+ 'Referral - Other',
696
+ 'Direct Traffic',
697
+ 'Other',
698
+ OFFLINE_TOUCH,
699
+ ]);
700
+
701
+ const getString = (kv, key) => {
702
+ const value = kv === null || kv === void 0 ? void 0 : kv[key];
703
+ return typeof value === 'string' && value ? value : undefined;
704
+ };
705
+ /**
706
+ * Maps session KV onto the params Snap's tag accepts on `init`. Everything goes
707
+ * across raw: the tag strips the phone to digits and lowercases the rest before
708
+ * hashing it in the browser.
709
+ *
710
+ * `gender` and `dateOfBirth` are deliberately left out. Snap transmits gender
711
+ * unhashed, and it parses `db` as an integer age bounded to 0-130, so a
712
+ * YYYYMMDD date is rejected.
713
+ */
714
+ const buildIdentity = (kv, userId) => {
715
+ const identity = {};
716
+ const email = getString(kv, 'email');
717
+ if (email) {
718
+ identity['user_email'] = email;
719
+ }
720
+ const phone = getString(kv, 'phone');
721
+ if (phone && isPlausibleE164Number(normalizePhoneNumber(phone, true))) {
722
+ // Snap normalizes before hashing, so the raw value goes across. The guard
723
+ // only keeps junk from being sent as a hash that matches nobody.
724
+ identity['user_phone_number'] = phone;
725
+ }
726
+ const firstName = getString(kv, 'firstName');
727
+ if (firstName) {
728
+ identity['firstname'] = firstName;
729
+ }
730
+ const lastName = getString(kv, 'lastName');
731
+ if (lastName) {
732
+ identity['lastname'] = lastName;
733
+ }
734
+ const city = getString(kv, 'city');
735
+ if (city) {
736
+ identity['geo_city'] = city;
737
+ }
738
+ const state = getString(kv, 'state');
739
+ if (state) {
740
+ identity['geo_region'] = state;
741
+ }
742
+ const zip = getString(kv, 'zip');
743
+ if (zip) {
744
+ identity['geo_postal_code'] = zip;
745
+ }
746
+ const country = getString(kv, 'country');
747
+ if (country) {
748
+ identity['geo_country'] = country;
749
+ }
750
+ if (userId) {
751
+ identity['external_id'] = userId;
752
+ }
753
+ return identity;
754
+ };
755
+
38
756
  const snippet = () => {
39
757
  if (!window || !document || window.snaptr) {
40
758
  return;
@@ -55,7 +773,7 @@ const snippet = () => {
55
773
  script.parentNode.insertBefore(element, script);
56
774
  }
57
775
  };
58
- const init = ({ manifest }) => {
776
+ const init = ({ manifest, userId, destination }) => {
59
777
  if (!manifest.variables ||
60
778
  !manifest.variables['pixelId'] ||
61
779
  manifest.variables['enableBrowser'] !== '1') {
@@ -65,17 +783,8 @@ const init = ({ manifest }) => {
65
783
  if (!window.snaptr) {
66
784
  return;
67
785
  }
68
- window.snaptr('init', manifest.variables['pixelId']);
69
- };
70
-
71
- const getProductIdFromMapping = (item, productIdMapping) => {
72
- if (productIdMapping === '1' && item['variantId']) {
73
- return item['variantId'];
74
- }
75
- if (productIdMapping === '2' && item['sku']) {
76
- return item['sku'];
77
- }
78
- return item['id'];
786
+ const identity = buildIdentity(getData(destination, 'session')['kv'], userId);
787
+ window.snaptr('init', manifest.variables['pixelId'], identity);
79
788
  };
80
789
 
81
790
  // eslint-disable-next-line @nx/enforce-module-boundaries
@@ -176,7 +885,7 @@ const getSnapEventName = (name) => {
176
885
  return name.toUpperCase();
177
886
  };
178
887
  const tag = ({ data, eventName, manifestVariables, eventId, executionContext, }) => {
179
- const result = { sdkVersion: "1.68.2" };
888
+ const result = { sdkVersion: "1.69.1" };
180
889
  if (executionContext.get('pixelFired')) {
181
890
  return result;
182
891
  }
@@ -200,11 +909,30 @@ const tag = ({ data, eventName, manifestVariables, eventId, executionContext, })
200
909
  return result;
201
910
  };
202
911
 
912
+ const user = ({ userId, manifestVariables, destination }) => {
913
+ if (!window ||
914
+ !window.snaptr ||
915
+ !manifestVariables['pixelId'] ||
916
+ manifestVariables['enableBrowser'] !== '1') {
917
+ return;
918
+ }
919
+ // KV is read rather than `data` because `data` carries only what just
920
+ // changed, and saveKV has already merged it in by the time this runs.
921
+ const identity = buildIdentity(getData(destination, 'session')['kv'], userId);
922
+ if (!Object.keys(identity).length) {
923
+ return;
924
+ }
925
+ // A second init on the same pixel merges the new params over the stored ones
926
+ // and skips the first-init side effects, so nothing re-registers or re-fires.
927
+ window.snaptr('init', manifestVariables['pixelId'], identity);
928
+ };
929
+
203
930
  // eslint-disable-next-line @nx/enforce-module-boundaries
204
931
  const data = {
205
932
  name: packageName,
206
933
  tag,
207
934
  init,
935
+ user,
208
936
  };
209
937
  try {
210
938
  if (window) {