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