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