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