@blotoutio/edgetag-sdk-js 0.71.0 → 1.0.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.
- package/index.cjs.js +357 -36
- package/index.mjs +357 -36
- package/internal.d.ts +5 -1
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -42,25 +42,6 @@ const hasUserConsent = (consent, provider, tagName) => {
|
|
|
42
42
|
}
|
|
43
43
|
return allowed;
|
|
44
44
|
};
|
|
45
|
-
/**
|
|
46
|
-
* This function validates user consent for a given provider type, not based on tagName.
|
|
47
|
-
*/
|
|
48
|
-
const hasUserConsentForProvider = (consent, provider) => {
|
|
49
|
-
if (!isRecord(consent)) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
let allowed = isBool(consent.all) ? consent.all : false;
|
|
53
|
-
if (provider in consent) {
|
|
54
|
-
const providerSpecific = consent[provider];
|
|
55
|
-
if (isBool(providerSpecific)) {
|
|
56
|
-
allowed = providerSpecific;
|
|
57
|
-
}
|
|
58
|
-
else if (isRecord(providerSpecific)) {
|
|
59
|
-
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return allowed;
|
|
63
|
-
};
|
|
64
45
|
/**
|
|
65
46
|
* This function validates provider allowance for a given provider and tag name.
|
|
66
47
|
* It should not be used to validate `UserConsent`.
|
|
@@ -140,6 +121,283 @@ const isZeroPurchaseEvent = (payload) => {
|
|
|
140
121
|
return value === 0;
|
|
141
122
|
};
|
|
142
123
|
|
|
124
|
+
/**
|
|
125
|
+
* ISO-3166 2-leter country codes and their names
|
|
126
|
+
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
127
|
+
*/
|
|
128
|
+
const isoCountries = new Map([
|
|
129
|
+
['AD', 'Andorra'],
|
|
130
|
+
['AE', 'United Arab Emirates'],
|
|
131
|
+
['AF', 'Afghanistan'],
|
|
132
|
+
['AG', 'Antigua and Barbuda'],
|
|
133
|
+
['AI', 'Anguilla'],
|
|
134
|
+
['AL', 'Albania'],
|
|
135
|
+
['AM', 'Armenia'],
|
|
136
|
+
['AO', 'Angola'],
|
|
137
|
+
['AQ', 'Antarctica'],
|
|
138
|
+
['AR', 'Argentina'],
|
|
139
|
+
['AS', 'American Samoa'],
|
|
140
|
+
['AT', 'Austria'],
|
|
141
|
+
['AU', 'Australia'],
|
|
142
|
+
['AW', 'Aruba'],
|
|
143
|
+
['AX', 'Åland Islands'],
|
|
144
|
+
['AZ', 'Azerbaijan'],
|
|
145
|
+
['BA', 'Bosnia and Herzegovina'],
|
|
146
|
+
['BB', 'Barbados'],
|
|
147
|
+
['BD', 'Bangladesh'],
|
|
148
|
+
['BE', 'Belgium'],
|
|
149
|
+
['BF', 'Burkina Faso'],
|
|
150
|
+
['BG', 'Bulgaria'],
|
|
151
|
+
['BH', 'Bahrain'],
|
|
152
|
+
['BI', 'Burundi'],
|
|
153
|
+
['BJ', 'Benin'],
|
|
154
|
+
['BL', 'Saint Barthélemy'],
|
|
155
|
+
['BM', 'Bermuda'],
|
|
156
|
+
['BN', 'Brunei Darussalam'],
|
|
157
|
+
['BO', 'Bolivia, Plurinational State of'],
|
|
158
|
+
['BQ', 'Bonaire, Sint Eustatius and Saba'],
|
|
159
|
+
['BR', 'Brazil'],
|
|
160
|
+
['BS', 'Bahamas'],
|
|
161
|
+
['BT', 'Bhutan'],
|
|
162
|
+
['BV', 'Bouvet Island'],
|
|
163
|
+
['BW', 'Botswana'],
|
|
164
|
+
['BY', 'Belarus'],
|
|
165
|
+
['BZ', 'Belize'],
|
|
166
|
+
['CA', 'Canada'],
|
|
167
|
+
['CC', 'Cocos (Keeling) Islands'],
|
|
168
|
+
['CD', 'Congo, Democratic Republic of the'],
|
|
169
|
+
['CF', 'Central African Republic'],
|
|
170
|
+
['CG', 'Congo'],
|
|
171
|
+
['CH', 'Switzerland'],
|
|
172
|
+
['CI', "Côte d'Ivoire"],
|
|
173
|
+
['CK', 'Cook Islands'],
|
|
174
|
+
['CL', 'Chile'],
|
|
175
|
+
['CM', 'Cameroon'],
|
|
176
|
+
['CN', 'China'],
|
|
177
|
+
['CO', 'Colombia'],
|
|
178
|
+
['CR', 'Costa Rica'],
|
|
179
|
+
['CU', 'Cuba'],
|
|
180
|
+
['CV', 'Cabo Verde'],
|
|
181
|
+
['CW', 'Curaçao'],
|
|
182
|
+
['CX', 'Christmas Island'],
|
|
183
|
+
['CY', 'Cyprus'],
|
|
184
|
+
['CZ', 'Czechia'],
|
|
185
|
+
['DE', 'Germany'],
|
|
186
|
+
['DJ', 'Djibouti'],
|
|
187
|
+
['DK', 'Denmark'],
|
|
188
|
+
['DM', 'Dominica'],
|
|
189
|
+
['DO', 'Dominican Republic'],
|
|
190
|
+
['DZ', 'Algeria'],
|
|
191
|
+
['EC', 'Ecuador'],
|
|
192
|
+
['EE', 'Estonia'],
|
|
193
|
+
['EG', 'Egypt'],
|
|
194
|
+
['EH', 'Western Sahara'],
|
|
195
|
+
['ER', 'Eritrea'],
|
|
196
|
+
['ES', 'Spain'],
|
|
197
|
+
['ET', 'Ethiopia'],
|
|
198
|
+
['EU', 'European Union'],
|
|
199
|
+
['FI', 'Finland'],
|
|
200
|
+
['FJ', 'Fiji'],
|
|
201
|
+
['FK', 'Falkland Islands (Malvinas)'],
|
|
202
|
+
['FM', 'Micronesia, Federated States of'],
|
|
203
|
+
['FO', 'Faroe Islands'],
|
|
204
|
+
['FR', 'France'],
|
|
205
|
+
['GA', 'Gabon'],
|
|
206
|
+
['GB', 'United Kingdom of Great Britain and Northern Ireland'],
|
|
207
|
+
['GD', 'Grenada'],
|
|
208
|
+
['GE', 'Georgia'],
|
|
209
|
+
['GF', 'French Guiana'],
|
|
210
|
+
['GG', 'Guernsey'],
|
|
211
|
+
['GH', 'Ghana'],
|
|
212
|
+
['GI', 'Gibraltar'],
|
|
213
|
+
['GL', 'Greenland'],
|
|
214
|
+
['GM', 'Gambia'],
|
|
215
|
+
['GN', 'Guinea'],
|
|
216
|
+
['GP', 'Guadeloupe'],
|
|
217
|
+
['GQ', 'Equatorial Guinea'],
|
|
218
|
+
['GR', 'Greece'],
|
|
219
|
+
['GS', 'South Georgia and the South Sandwich Islands'],
|
|
220
|
+
['GT', 'Guatemala'],
|
|
221
|
+
['GU', 'Guam'],
|
|
222
|
+
['GW', 'Guinea-Bissau'],
|
|
223
|
+
['GY', 'Guyana'],
|
|
224
|
+
['HK', 'Hong Kong'],
|
|
225
|
+
['HM', 'Heard Island and McDonald Islands'],
|
|
226
|
+
['HN', 'Honduras'],
|
|
227
|
+
['HR', 'Croatia'],
|
|
228
|
+
['HT', 'Haiti'],
|
|
229
|
+
['HU', 'Hungary'],
|
|
230
|
+
['ID', 'Indonesia'],
|
|
231
|
+
['IE', 'Ireland'],
|
|
232
|
+
['IL', 'Israel'],
|
|
233
|
+
['IM', 'Isle of Man'],
|
|
234
|
+
['IN', 'India'],
|
|
235
|
+
['IO', 'British Indian Ocean Territory'],
|
|
236
|
+
['IQ', 'Iraq'],
|
|
237
|
+
['IR', 'Iran, Islamic Republic of'],
|
|
238
|
+
['IS', 'Iceland'],
|
|
239
|
+
['IT', 'Italy'],
|
|
240
|
+
['JE', 'Jersey'],
|
|
241
|
+
['JM', 'Jamaica'],
|
|
242
|
+
['JO', 'Jordan'],
|
|
243
|
+
['JP', 'Japan'],
|
|
244
|
+
['KE', 'Kenya'],
|
|
245
|
+
['KG', 'Kyrgyzstan'],
|
|
246
|
+
['KH', 'Cambodia'],
|
|
247
|
+
['KI', 'Kiribati'],
|
|
248
|
+
['KM', 'Comoros'],
|
|
249
|
+
['KN', 'Saint Kitts and Nevis'],
|
|
250
|
+
['KP', "Korea, Democratic People's Republic of"],
|
|
251
|
+
['KR', 'Korea, Republic of'],
|
|
252
|
+
['KW', 'Kuwait'],
|
|
253
|
+
['KY', 'Cayman Islands'],
|
|
254
|
+
['KZ', 'Kazakhstan'],
|
|
255
|
+
['LA', "Lao People's Democratic Republic"],
|
|
256
|
+
['LB', 'Lebanon'],
|
|
257
|
+
['LC', 'Saint Lucia'],
|
|
258
|
+
['LI', 'Liechtenstein'],
|
|
259
|
+
['LK', 'Sri Lanka'],
|
|
260
|
+
['LR', 'Liberia'],
|
|
261
|
+
['LS', 'Lesotho'],
|
|
262
|
+
['LT', 'Lithuania'],
|
|
263
|
+
['LU', 'Luxembourg'],
|
|
264
|
+
['LV', 'Latvia'],
|
|
265
|
+
['LY', 'Libya'],
|
|
266
|
+
['MA', 'Morocco'],
|
|
267
|
+
['MC', 'Monaco'],
|
|
268
|
+
['MD', 'Moldova, Republic of'],
|
|
269
|
+
['ME', 'Montenegro'],
|
|
270
|
+
['MF', 'Saint Martin (French part)'],
|
|
271
|
+
['MG', 'Madagascar'],
|
|
272
|
+
['MH', 'Marshall Islands'],
|
|
273
|
+
['MK', 'North Macedonia'],
|
|
274
|
+
['ML', 'Mali'],
|
|
275
|
+
['MM', 'Myanmar'],
|
|
276
|
+
['MN', 'Mongolia'],
|
|
277
|
+
['MO', 'Macao'],
|
|
278
|
+
['MP', 'Northern Mariana Islands'],
|
|
279
|
+
['MQ', 'Martinique'],
|
|
280
|
+
['MR', 'Mauritania'],
|
|
281
|
+
['MS', 'Montserrat'],
|
|
282
|
+
['MT', 'Malta'],
|
|
283
|
+
['MU', 'Mauritius'],
|
|
284
|
+
['MV', 'Maldives'],
|
|
285
|
+
['MW', 'Malawi'],
|
|
286
|
+
['MX', 'Mexico'],
|
|
287
|
+
['MY', 'Malaysia'],
|
|
288
|
+
['MZ', 'Mozambique'],
|
|
289
|
+
['NA', 'Namibia'],
|
|
290
|
+
['NC', 'New Caledonia'],
|
|
291
|
+
['NE', 'Niger'],
|
|
292
|
+
['NF', 'Norfolk Island'],
|
|
293
|
+
['NG', 'Nigeria'],
|
|
294
|
+
['NI', 'Nicaragua'],
|
|
295
|
+
['NL', 'Netherlands, Kingdom of the'],
|
|
296
|
+
['NO', 'Norway'],
|
|
297
|
+
['NP', 'Nepal'],
|
|
298
|
+
['NR', 'Nauru'],
|
|
299
|
+
['NU', 'Niue'],
|
|
300
|
+
['NZ', 'New Zealand'],
|
|
301
|
+
['OM', 'Oman'],
|
|
302
|
+
['PA', 'Panama'],
|
|
303
|
+
['PE', 'Peru'],
|
|
304
|
+
['PF', 'French Polynesia'],
|
|
305
|
+
['PG', 'Papua New Guinea'],
|
|
306
|
+
['PH', 'Philippines'],
|
|
307
|
+
['PK', 'Pakistan'],
|
|
308
|
+
['PL', 'Poland'],
|
|
309
|
+
['PM', 'Saint Pierre and Miquelon'],
|
|
310
|
+
['PN', 'Pitcairn'],
|
|
311
|
+
['PR', 'Puerto Rico'],
|
|
312
|
+
['PS', 'Palestine, State of'],
|
|
313
|
+
['PT', 'Portugal'],
|
|
314
|
+
['PW', 'Palau'],
|
|
315
|
+
['PY', 'Paraguay'],
|
|
316
|
+
['QA', 'Qatar'],
|
|
317
|
+
['RE', 'Réunion'],
|
|
318
|
+
['RO', 'Romania'],
|
|
319
|
+
['RS', 'Serbia'],
|
|
320
|
+
['RU', 'Russian Federation'],
|
|
321
|
+
['RW', 'Rwanda'],
|
|
322
|
+
['SA', 'Saudi Arabia'],
|
|
323
|
+
['SB', 'Solomon Islands'],
|
|
324
|
+
['SC', 'Seychelles'],
|
|
325
|
+
['SD', 'Sudan'],
|
|
326
|
+
['SE', 'Sweden'],
|
|
327
|
+
['SG', 'Singapore'],
|
|
328
|
+
['SH', 'Saint Helena, Ascension and Tristan da Cunha'],
|
|
329
|
+
['SI', 'Slovenia'],
|
|
330
|
+
['SJ', 'Svalbard and Jan Mayen'],
|
|
331
|
+
['SK', 'Slovakia'],
|
|
332
|
+
['SL', 'Sierra Leone'],
|
|
333
|
+
['SM', 'San Marino'],
|
|
334
|
+
['SN', 'Senegal'],
|
|
335
|
+
['SO', 'Somalia'],
|
|
336
|
+
['SR', 'Suriname'],
|
|
337
|
+
['SS', 'South Sudan'],
|
|
338
|
+
['ST', 'Sao Tome and Principe'],
|
|
339
|
+
['SV', 'El Salvador'],
|
|
340
|
+
['SX', 'Sint Maarten (Dutch part)'],
|
|
341
|
+
['SY', 'Syrian Arab Republic'],
|
|
342
|
+
['SZ', 'Eswatini'],
|
|
343
|
+
['TC', 'Turks and Caicos Islands'],
|
|
344
|
+
['TD', 'Chad'],
|
|
345
|
+
['TF', 'French Southern Territories'],
|
|
346
|
+
['TG', 'Togo'],
|
|
347
|
+
['TH', 'Thailand'],
|
|
348
|
+
['TJ', 'Tajikistan'],
|
|
349
|
+
['TK', 'Tokelau'],
|
|
350
|
+
['TL', 'Timor-Leste'],
|
|
351
|
+
['TM', 'Turkmenistan'],
|
|
352
|
+
['TN', 'Tunisia'],
|
|
353
|
+
['TO', 'Tonga'],
|
|
354
|
+
['TR', 'Türkiye'],
|
|
355
|
+
['TT', 'Trinidad and Tobago'],
|
|
356
|
+
['TV', 'Tuvalu'],
|
|
357
|
+
['TW', 'Taiwan, Province of China'],
|
|
358
|
+
['TZ', 'Tanzania, United Republic of'],
|
|
359
|
+
['UA', 'Ukraine'],
|
|
360
|
+
['UG', 'Uganda'],
|
|
361
|
+
['UK', 'United Kingdom'],
|
|
362
|
+
['UM', 'United States Minor Outlying Islands'],
|
|
363
|
+
['US', 'United States of America'],
|
|
364
|
+
['UY', 'Uruguay'],
|
|
365
|
+
['UZ', 'Uzbekistan'],
|
|
366
|
+
['VA', 'Holy See'],
|
|
367
|
+
['VC', 'Saint Vincent and the Grenadines'],
|
|
368
|
+
['VE', 'Venezuela, Bolivarian Republic of'],
|
|
369
|
+
['VG', 'Virgin Islands (British)'],
|
|
370
|
+
['VI', 'Virgin Islands (U.S.)'],
|
|
371
|
+
['VN', 'Viet Nam'],
|
|
372
|
+
['VU', 'Vanuatu'],
|
|
373
|
+
['WF', 'Wallis and Futuna'],
|
|
374
|
+
['WS', 'Samoa'],
|
|
375
|
+
['YE', 'Yemen'],
|
|
376
|
+
['YT', 'Mayotte'],
|
|
377
|
+
['ZA', 'South Africa'],
|
|
378
|
+
['ZM', 'Zambia'],
|
|
379
|
+
['ZW', 'Zimbabwe'],
|
|
380
|
+
]);
|
|
381
|
+
new Set(isoCountries.keys());
|
|
382
|
+
const parseCache = new Map();
|
|
383
|
+
const doesGeoRequestMatchList = (requestRegion, isEUCountry, geoRegions) => {
|
|
384
|
+
if (!requestRegion || !geoRegions) {
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
let parsedRegions = parseCache.get(geoRegions);
|
|
388
|
+
if (!parsedRegions) {
|
|
389
|
+
parsedRegions = new Set((geoRegions !== null && geoRegions !== void 0 ? geoRegions : '').split(','));
|
|
390
|
+
parseCache.set(geoRegions, parsedRegions);
|
|
391
|
+
}
|
|
392
|
+
if (parsedRegions.size == 0) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
if (isEUCountry && parsedRegions.has('EU')) {
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
return parsedRegions.has(requestRegion);
|
|
399
|
+
};
|
|
400
|
+
|
|
143
401
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
144
402
|
let edgeTagSettings;
|
|
145
403
|
const initSettings = (destination, options) => {
|
|
@@ -152,6 +410,8 @@ const initSettings = (destination, options) => {
|
|
|
152
410
|
stubs: [],
|
|
153
411
|
browserPackages: [],
|
|
154
412
|
channels: new Map(),
|
|
413
|
+
geoRegion: null,
|
|
414
|
+
isEURequest: false,
|
|
155
415
|
...options,
|
|
156
416
|
};
|
|
157
417
|
};
|
|
@@ -190,6 +450,7 @@ const getProviderVariables = (destination, packageId) => {
|
|
|
190
450
|
.filter((pkg) => pkg.package === packageId)
|
|
191
451
|
.map((pkg) => ({
|
|
192
452
|
tagName: pkg.tagName,
|
|
453
|
+
geoRegions: pkg.geoRegions || null,
|
|
193
454
|
variableSet: pkg.variables || {},
|
|
194
455
|
})) || []);
|
|
195
456
|
};
|
|
@@ -284,6 +545,7 @@ const areEqual = (a, b) => {
|
|
|
284
545
|
|
|
285
546
|
const tagStorage = 'edgeTag';
|
|
286
547
|
const consentKey = 'consent';
|
|
548
|
+
const consentCategoriesKey = 'consentCategories';
|
|
287
549
|
const keyPrefix = `_worker`;
|
|
288
550
|
const cookieKey = 'tag_user_id';
|
|
289
551
|
const fallbackSessionKey = 'fallback_tag_user_id';
|
|
@@ -571,7 +833,7 @@ const getStandardPayload = (destination, payload) => {
|
|
|
571
833
|
referrer: getReferrer(destination),
|
|
572
834
|
search: getSearch(destination),
|
|
573
835
|
locale: getLocale(),
|
|
574
|
-
sdkVersion: "0.
|
|
836
|
+
sdkVersion: "1.0.0" ,
|
|
575
837
|
...(payload || {}),
|
|
576
838
|
};
|
|
577
839
|
let storage = {};
|
|
@@ -661,6 +923,13 @@ const getConsent$1 = (destination) => {
|
|
|
661
923
|
}
|
|
662
924
|
return getSetting(destination, 'consent');
|
|
663
925
|
};
|
|
926
|
+
const getConsentCategories = (destination) => {
|
|
927
|
+
const storageConsentCategories = getDataPerKey(destination, 'local', tagStorage, consentCategoriesKey);
|
|
928
|
+
if (storageConsentCategories) {
|
|
929
|
+
return storageConsentCategories;
|
|
930
|
+
}
|
|
931
|
+
return getSetting(destination, 'consentCategories');
|
|
932
|
+
};
|
|
664
933
|
|
|
665
934
|
const processStubs = (destination) => {
|
|
666
935
|
try {
|
|
@@ -739,6 +1008,8 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
739
1008
|
const providerPackages = getSetting(destination, 'browserPackages');
|
|
740
1009
|
const configuredTags = getSetting(destination, 'channels');
|
|
741
1010
|
const skipZeroPurchaseEvent = getSetting(destination, 'skipZeroPurchaseEvent') || false;
|
|
1011
|
+
const requestRegion = getSetting(destination, 'geoRegion') || null;
|
|
1012
|
+
const isEURequest = getSetting(destination, 'isEURequest') || false;
|
|
742
1013
|
const userId = getUserId$1(destination);
|
|
743
1014
|
const providerData = {};
|
|
744
1015
|
const consent = getConsent$1(destination);
|
|
@@ -766,6 +1037,10 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
766
1037
|
logger.log(`Consent is missing (${pkg.name}: ${variable.tagName})`);
|
|
767
1038
|
continue;
|
|
768
1039
|
}
|
|
1040
|
+
if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
|
|
1041
|
+
logger.log('GEO request region does not match the filter, skiping');
|
|
1042
|
+
continue;
|
|
1043
|
+
}
|
|
769
1044
|
const payload = ((_a = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
770
1045
|
((_b = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _b === void 0 ? void 0 : _b.includes(pkg.name))
|
|
771
1046
|
? conversion.payload
|
|
@@ -847,6 +1122,8 @@ const processData = (destination, data, providers, options) => {
|
|
|
847
1122
|
const configuredTags = getSetting(destination, 'channels');
|
|
848
1123
|
const userId = getUserId$1(destination);
|
|
849
1124
|
const consent = getConsent$1(destination);
|
|
1125
|
+
const requestRegion = getSetting(destination, 'geoRegion') || null;
|
|
1126
|
+
const isEURequest = getSetting(destination, 'isEURequest') || false;
|
|
850
1127
|
for (const pkg of providerPackages) {
|
|
851
1128
|
if (!pkg || !pkg.user || !pkg.name) {
|
|
852
1129
|
continue;
|
|
@@ -865,6 +1142,10 @@ const processData = (destination, data, providers, options) => {
|
|
|
865
1142
|
logger.log(`Consent is missing for ${pkg.name} (${variable.tagName})`);
|
|
866
1143
|
continue;
|
|
867
1144
|
}
|
|
1145
|
+
if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
|
|
1146
|
+
logger.log(`GEO request region does not match list, skipping`);
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
868
1149
|
pkg.user({
|
|
869
1150
|
userId,
|
|
870
1151
|
data,
|
|
@@ -888,43 +1169,50 @@ const handleData = (data, providers, options) => {
|
|
|
888
1169
|
});
|
|
889
1170
|
};
|
|
890
1171
|
|
|
891
|
-
const handleConsent = (consent, options) => {
|
|
1172
|
+
const handleConsent = (consent, consentCategories, options) => {
|
|
892
1173
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|
|
893
|
-
processConsent(options.destination, consent, options);
|
|
1174
|
+
processConsent(options.destination, consent, consentCategories, options);
|
|
894
1175
|
return;
|
|
895
1176
|
}
|
|
896
1177
|
getInstances().forEach((destination) => {
|
|
897
|
-
processConsent(destination, consent, options);
|
|
1178
|
+
processConsent(destination, consent, consentCategories, options);
|
|
898
1179
|
});
|
|
899
1180
|
};
|
|
900
|
-
const saveConsent = (destination, consent) => {
|
|
1181
|
+
const saveConsent = (destination, consent, consentCategories) => {
|
|
901
1182
|
setSetting(destination, {
|
|
902
1183
|
consent,
|
|
1184
|
+
consentCategories,
|
|
903
1185
|
});
|
|
904
1186
|
savePerKey(destination, 'local', tagStorage, consent, consentKey);
|
|
1187
|
+
savePerKey(destination, 'local', tagStorage, consentCategories, consentCategoriesKey);
|
|
905
1188
|
};
|
|
906
|
-
const processConsent = (destination, consent, options) => {
|
|
1189
|
+
const processConsent = (destination, consent, consentCategories, options) => {
|
|
907
1190
|
const existingConsent = getConsent$1(destination);
|
|
908
|
-
|
|
1191
|
+
const existingConsentCategories = getConsentCategories(destination);
|
|
1192
|
+
if (areEqual(existingConsent, consent) &&
|
|
1193
|
+
areEqual(existingConsentCategories, consentCategories)) {
|
|
909
1194
|
return;
|
|
910
1195
|
}
|
|
911
1196
|
if (!getSetting(destination, 'initialized')) {
|
|
912
1197
|
addStub(destination, {
|
|
913
1198
|
name: 'consent',
|
|
914
|
-
arguments: [consent, options],
|
|
1199
|
+
arguments: [consent, consentCategories, options],
|
|
915
1200
|
});
|
|
916
1201
|
return;
|
|
917
1202
|
}
|
|
918
1203
|
const payload = {
|
|
919
1204
|
consentString: consent,
|
|
1205
|
+
consentCategories: { ...consentCategories, necessary: true },
|
|
920
1206
|
};
|
|
921
|
-
saveConsent(destination, consent);
|
|
1207
|
+
saveConsent(destination, consent, consentCategories);
|
|
922
1208
|
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
923
1209
|
postRequest(getConsentURL(destination), payload).catch(logger.error);
|
|
924
1210
|
}
|
|
925
1211
|
const userId = getUserId$1(destination);
|
|
926
1212
|
const providerPackages = getSetting(destination, 'browserPackages');
|
|
927
1213
|
const executionContext = new Map();
|
|
1214
|
+
const requestRegion = getSetting(destination, 'geoRegion') || null;
|
|
1215
|
+
const isEURequest = getSetting(destination, 'isEURequest') || false;
|
|
928
1216
|
/* Calling Init for all provider instances based on consent check */
|
|
929
1217
|
for (const pkg of providerPackages) {
|
|
930
1218
|
if (!pkg || !pkg.name || !pkg.init) {
|
|
@@ -936,6 +1224,9 @@ const processConsent = (destination, consent, options) => {
|
|
|
936
1224
|
if (!hasConsent) {
|
|
937
1225
|
continue;
|
|
938
1226
|
}
|
|
1227
|
+
if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
939
1230
|
pkg.init({
|
|
940
1231
|
userId,
|
|
941
1232
|
isNewUser: false,
|
|
@@ -944,6 +1235,7 @@ const processConsent = (destination, consent, options) => {
|
|
|
944
1235
|
tagName: variable.tagName,
|
|
945
1236
|
variables: variable.variableSet,
|
|
946
1237
|
package: pkg.name,
|
|
1238
|
+
geoRegions: variable.geoRegions,
|
|
947
1239
|
},
|
|
948
1240
|
sendTag: sendTag.bind(null, destination),
|
|
949
1241
|
sendEdgeData: processData.bind(null, destination),
|
|
@@ -952,6 +1244,10 @@ const processConsent = (destination, consent, options) => {
|
|
|
952
1244
|
executionContext,
|
|
953
1245
|
session: null,
|
|
954
1246
|
destination,
|
|
1247
|
+
consentData: {
|
|
1248
|
+
consent,
|
|
1249
|
+
categories: { ...consentCategories, necessary: true },
|
|
1250
|
+
},
|
|
955
1251
|
});
|
|
956
1252
|
}
|
|
957
1253
|
}
|
|
@@ -972,9 +1268,17 @@ const processConsent = (destination, consent, options) => {
|
|
|
972
1268
|
if (!pkg || !pkg.name || !pkg.consent) {
|
|
973
1269
|
continue;
|
|
974
1270
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1271
|
+
const variables = getProviderVariables(destination, pkg.name);
|
|
1272
|
+
pkg.consent({
|
|
1273
|
+
consentData: {
|
|
1274
|
+
consent,
|
|
1275
|
+
categories: {
|
|
1276
|
+
...consentCategories,
|
|
1277
|
+
necessary: true,
|
|
1278
|
+
},
|
|
1279
|
+
},
|
|
1280
|
+
variables,
|
|
1281
|
+
});
|
|
978
1282
|
}
|
|
979
1283
|
};
|
|
980
1284
|
|
|
@@ -1142,7 +1446,8 @@ const handleManifest = (destination, response) => {
|
|
|
1142
1446
|
if (pkg && pkg.name && pkg.init) {
|
|
1143
1447
|
/* this defines if the consent is given for a specific instance of a provider */
|
|
1144
1448
|
const hasConsent = hasUserConsent(getSetting(destination, 'consent'), pkg.name, provider.tagName);
|
|
1145
|
-
if (hasConsent
|
|
1449
|
+
if (hasConsent &&
|
|
1450
|
+
doesGeoRequestMatchList(response.geoRegion, response.isEURequest, provider.geoRegions)) {
|
|
1146
1451
|
pkg.init({
|
|
1147
1452
|
userId,
|
|
1148
1453
|
isNewUser: !!response.isNewUser,
|
|
@@ -1155,6 +1460,10 @@ const handleManifest = (destination, response) => {
|
|
|
1155
1460
|
keyName,
|
|
1156
1461
|
executionContext,
|
|
1157
1462
|
destination,
|
|
1463
|
+
consentData: {
|
|
1464
|
+
consent: response.consent,
|
|
1465
|
+
categories: response.consentCategories,
|
|
1466
|
+
},
|
|
1158
1467
|
});
|
|
1159
1468
|
}
|
|
1160
1469
|
}
|
|
@@ -1198,7 +1507,11 @@ const handleInit = (preferences) => {
|
|
|
1198
1507
|
const url = new URL(getInitURL(preferences.edgeURL));
|
|
1199
1508
|
if (preferences.disableConsentCheck) {
|
|
1200
1509
|
url.searchParams.set('consentDisabled', 'true');
|
|
1201
|
-
saveConsent(preferences.edgeURL, {
|
|
1510
|
+
saveConsent(preferences.edgeURL, {
|
|
1511
|
+
all: true,
|
|
1512
|
+
}, {
|
|
1513
|
+
all: true,
|
|
1514
|
+
});
|
|
1202
1515
|
}
|
|
1203
1516
|
if (preferences.userId) {
|
|
1204
1517
|
setSetting(preferences.edgeURL, { userId: preferences.userId });
|
|
@@ -1219,7 +1532,7 @@ const handleInit = (preferences) => {
|
|
|
1219
1532
|
return;
|
|
1220
1533
|
}
|
|
1221
1534
|
if (result.isNewUser && result.consent) {
|
|
1222
|
-
saveConsent(preferences.edgeURL, result.consent);
|
|
1535
|
+
saveConsent(preferences.edgeURL, result.consent, result.consentCategories);
|
|
1223
1536
|
}
|
|
1224
1537
|
const providers = {};
|
|
1225
1538
|
(_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
|
|
@@ -1238,6 +1551,8 @@ const handleInit = (preferences) => {
|
|
|
1238
1551
|
storageId: result.storageId,
|
|
1239
1552
|
currency: result.currency,
|
|
1240
1553
|
skipZeroPurchaseEvent: result.skipZeroPurchaseEvent,
|
|
1554
|
+
geoRegion: result.geoRegion,
|
|
1555
|
+
isEURequest: result.isEURequest,
|
|
1241
1556
|
});
|
|
1242
1557
|
if (result.storageId != null) {
|
|
1243
1558
|
savePerKey(preferences.edgeURL, 'local', tagStorage, result.storageId, storageIdKey);
|
|
@@ -1270,6 +1585,8 @@ const processUser = (destination, key, value, providers, options) => {
|
|
|
1270
1585
|
const configuredTags = getSetting(destination, 'channels');
|
|
1271
1586
|
const consent = getConsent$1(destination);
|
|
1272
1587
|
const userId = getUserId$1(destination);
|
|
1588
|
+
const requestRegion = getSetting(destination, 'geoRegion') || null;
|
|
1589
|
+
const isEURequest = getSetting(destination, 'isEURequest') || false;
|
|
1273
1590
|
for (const pkg of providerPackages) {
|
|
1274
1591
|
if (!pkg || !pkg.name || !pkg.user) {
|
|
1275
1592
|
continue;
|
|
@@ -1288,6 +1605,10 @@ const processUser = (destination, key, value, providers, options) => {
|
|
|
1288
1605
|
logger.log(`User do not have consent for ${pkg.name} (${variable.tagName})`);
|
|
1289
1606
|
continue;
|
|
1290
1607
|
}
|
|
1608
|
+
if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
|
|
1609
|
+
logger.log(`GEO request region does not match list, skipping`);
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1291
1612
|
pkg.user({
|
|
1292
1613
|
userId,
|
|
1293
1614
|
data: { [key]: value },
|
|
@@ -1403,8 +1724,8 @@ const init = (preferences) => {
|
|
|
1403
1724
|
const tag = (name, data, providers, options) => {
|
|
1404
1725
|
handleTag(name, data, providers, options);
|
|
1405
1726
|
};
|
|
1406
|
-
const consent = (value, options) => {
|
|
1407
|
-
handleConsent(value, options);
|
|
1727
|
+
const consent = (value, consentCategories, options) => {
|
|
1728
|
+
handleConsent(value, consentCategories, options);
|
|
1408
1729
|
};
|
|
1409
1730
|
const user = (key, value, providers, options) => {
|
|
1410
1731
|
handleUser(key, value, providers, options);
|
package/index.mjs
CHANGED
|
@@ -40,25 +40,6 @@ const hasUserConsent = (consent, provider, tagName) => {
|
|
|
40
40
|
}
|
|
41
41
|
return allowed;
|
|
42
42
|
};
|
|
43
|
-
/**
|
|
44
|
-
* This function validates user consent for a given provider type, not based on tagName.
|
|
45
|
-
*/
|
|
46
|
-
const hasUserConsentForProvider = (consent, provider) => {
|
|
47
|
-
if (!isRecord(consent)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
let allowed = isBool(consent.all) ? consent.all : false;
|
|
51
|
-
if (provider in consent) {
|
|
52
|
-
const providerSpecific = consent[provider];
|
|
53
|
-
if (isBool(providerSpecific)) {
|
|
54
|
-
allowed = providerSpecific;
|
|
55
|
-
}
|
|
56
|
-
else if (isRecord(providerSpecific)) {
|
|
57
|
-
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return allowed;
|
|
61
|
-
};
|
|
62
43
|
/**
|
|
63
44
|
* This function validates provider allowance for a given provider and tag name.
|
|
64
45
|
* It should not be used to validate `UserConsent`.
|
|
@@ -138,6 +119,283 @@ const isZeroPurchaseEvent = (payload) => {
|
|
|
138
119
|
return value === 0;
|
|
139
120
|
};
|
|
140
121
|
|
|
122
|
+
/**
|
|
123
|
+
* ISO-3166 2-leter country codes and their names
|
|
124
|
+
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
125
|
+
*/
|
|
126
|
+
const isoCountries = new Map([
|
|
127
|
+
['AD', 'Andorra'],
|
|
128
|
+
['AE', 'United Arab Emirates'],
|
|
129
|
+
['AF', 'Afghanistan'],
|
|
130
|
+
['AG', 'Antigua and Barbuda'],
|
|
131
|
+
['AI', 'Anguilla'],
|
|
132
|
+
['AL', 'Albania'],
|
|
133
|
+
['AM', 'Armenia'],
|
|
134
|
+
['AO', 'Angola'],
|
|
135
|
+
['AQ', 'Antarctica'],
|
|
136
|
+
['AR', 'Argentina'],
|
|
137
|
+
['AS', 'American Samoa'],
|
|
138
|
+
['AT', 'Austria'],
|
|
139
|
+
['AU', 'Australia'],
|
|
140
|
+
['AW', 'Aruba'],
|
|
141
|
+
['AX', 'Åland Islands'],
|
|
142
|
+
['AZ', 'Azerbaijan'],
|
|
143
|
+
['BA', 'Bosnia and Herzegovina'],
|
|
144
|
+
['BB', 'Barbados'],
|
|
145
|
+
['BD', 'Bangladesh'],
|
|
146
|
+
['BE', 'Belgium'],
|
|
147
|
+
['BF', 'Burkina Faso'],
|
|
148
|
+
['BG', 'Bulgaria'],
|
|
149
|
+
['BH', 'Bahrain'],
|
|
150
|
+
['BI', 'Burundi'],
|
|
151
|
+
['BJ', 'Benin'],
|
|
152
|
+
['BL', 'Saint Barthélemy'],
|
|
153
|
+
['BM', 'Bermuda'],
|
|
154
|
+
['BN', 'Brunei Darussalam'],
|
|
155
|
+
['BO', 'Bolivia, Plurinational State of'],
|
|
156
|
+
['BQ', 'Bonaire, Sint Eustatius and Saba'],
|
|
157
|
+
['BR', 'Brazil'],
|
|
158
|
+
['BS', 'Bahamas'],
|
|
159
|
+
['BT', 'Bhutan'],
|
|
160
|
+
['BV', 'Bouvet Island'],
|
|
161
|
+
['BW', 'Botswana'],
|
|
162
|
+
['BY', 'Belarus'],
|
|
163
|
+
['BZ', 'Belize'],
|
|
164
|
+
['CA', 'Canada'],
|
|
165
|
+
['CC', 'Cocos (Keeling) Islands'],
|
|
166
|
+
['CD', 'Congo, Democratic Republic of the'],
|
|
167
|
+
['CF', 'Central African Republic'],
|
|
168
|
+
['CG', 'Congo'],
|
|
169
|
+
['CH', 'Switzerland'],
|
|
170
|
+
['CI', "Côte d'Ivoire"],
|
|
171
|
+
['CK', 'Cook Islands'],
|
|
172
|
+
['CL', 'Chile'],
|
|
173
|
+
['CM', 'Cameroon'],
|
|
174
|
+
['CN', 'China'],
|
|
175
|
+
['CO', 'Colombia'],
|
|
176
|
+
['CR', 'Costa Rica'],
|
|
177
|
+
['CU', 'Cuba'],
|
|
178
|
+
['CV', 'Cabo Verde'],
|
|
179
|
+
['CW', 'Curaçao'],
|
|
180
|
+
['CX', 'Christmas Island'],
|
|
181
|
+
['CY', 'Cyprus'],
|
|
182
|
+
['CZ', 'Czechia'],
|
|
183
|
+
['DE', 'Germany'],
|
|
184
|
+
['DJ', 'Djibouti'],
|
|
185
|
+
['DK', 'Denmark'],
|
|
186
|
+
['DM', 'Dominica'],
|
|
187
|
+
['DO', 'Dominican Republic'],
|
|
188
|
+
['DZ', 'Algeria'],
|
|
189
|
+
['EC', 'Ecuador'],
|
|
190
|
+
['EE', 'Estonia'],
|
|
191
|
+
['EG', 'Egypt'],
|
|
192
|
+
['EH', 'Western Sahara'],
|
|
193
|
+
['ER', 'Eritrea'],
|
|
194
|
+
['ES', 'Spain'],
|
|
195
|
+
['ET', 'Ethiopia'],
|
|
196
|
+
['EU', 'European Union'],
|
|
197
|
+
['FI', 'Finland'],
|
|
198
|
+
['FJ', 'Fiji'],
|
|
199
|
+
['FK', 'Falkland Islands (Malvinas)'],
|
|
200
|
+
['FM', 'Micronesia, Federated States of'],
|
|
201
|
+
['FO', 'Faroe Islands'],
|
|
202
|
+
['FR', 'France'],
|
|
203
|
+
['GA', 'Gabon'],
|
|
204
|
+
['GB', 'United Kingdom of Great Britain and Northern Ireland'],
|
|
205
|
+
['GD', 'Grenada'],
|
|
206
|
+
['GE', 'Georgia'],
|
|
207
|
+
['GF', 'French Guiana'],
|
|
208
|
+
['GG', 'Guernsey'],
|
|
209
|
+
['GH', 'Ghana'],
|
|
210
|
+
['GI', 'Gibraltar'],
|
|
211
|
+
['GL', 'Greenland'],
|
|
212
|
+
['GM', 'Gambia'],
|
|
213
|
+
['GN', 'Guinea'],
|
|
214
|
+
['GP', 'Guadeloupe'],
|
|
215
|
+
['GQ', 'Equatorial Guinea'],
|
|
216
|
+
['GR', 'Greece'],
|
|
217
|
+
['GS', 'South Georgia and the South Sandwich Islands'],
|
|
218
|
+
['GT', 'Guatemala'],
|
|
219
|
+
['GU', 'Guam'],
|
|
220
|
+
['GW', 'Guinea-Bissau'],
|
|
221
|
+
['GY', 'Guyana'],
|
|
222
|
+
['HK', 'Hong Kong'],
|
|
223
|
+
['HM', 'Heard Island and McDonald Islands'],
|
|
224
|
+
['HN', 'Honduras'],
|
|
225
|
+
['HR', 'Croatia'],
|
|
226
|
+
['HT', 'Haiti'],
|
|
227
|
+
['HU', 'Hungary'],
|
|
228
|
+
['ID', 'Indonesia'],
|
|
229
|
+
['IE', 'Ireland'],
|
|
230
|
+
['IL', 'Israel'],
|
|
231
|
+
['IM', 'Isle of Man'],
|
|
232
|
+
['IN', 'India'],
|
|
233
|
+
['IO', 'British Indian Ocean Territory'],
|
|
234
|
+
['IQ', 'Iraq'],
|
|
235
|
+
['IR', 'Iran, Islamic Republic of'],
|
|
236
|
+
['IS', 'Iceland'],
|
|
237
|
+
['IT', 'Italy'],
|
|
238
|
+
['JE', 'Jersey'],
|
|
239
|
+
['JM', 'Jamaica'],
|
|
240
|
+
['JO', 'Jordan'],
|
|
241
|
+
['JP', 'Japan'],
|
|
242
|
+
['KE', 'Kenya'],
|
|
243
|
+
['KG', 'Kyrgyzstan'],
|
|
244
|
+
['KH', 'Cambodia'],
|
|
245
|
+
['KI', 'Kiribati'],
|
|
246
|
+
['KM', 'Comoros'],
|
|
247
|
+
['KN', 'Saint Kitts and Nevis'],
|
|
248
|
+
['KP', "Korea, Democratic People's Republic of"],
|
|
249
|
+
['KR', 'Korea, Republic of'],
|
|
250
|
+
['KW', 'Kuwait'],
|
|
251
|
+
['KY', 'Cayman Islands'],
|
|
252
|
+
['KZ', 'Kazakhstan'],
|
|
253
|
+
['LA', "Lao People's Democratic Republic"],
|
|
254
|
+
['LB', 'Lebanon'],
|
|
255
|
+
['LC', 'Saint Lucia'],
|
|
256
|
+
['LI', 'Liechtenstein'],
|
|
257
|
+
['LK', 'Sri Lanka'],
|
|
258
|
+
['LR', 'Liberia'],
|
|
259
|
+
['LS', 'Lesotho'],
|
|
260
|
+
['LT', 'Lithuania'],
|
|
261
|
+
['LU', 'Luxembourg'],
|
|
262
|
+
['LV', 'Latvia'],
|
|
263
|
+
['LY', 'Libya'],
|
|
264
|
+
['MA', 'Morocco'],
|
|
265
|
+
['MC', 'Monaco'],
|
|
266
|
+
['MD', 'Moldova, Republic of'],
|
|
267
|
+
['ME', 'Montenegro'],
|
|
268
|
+
['MF', 'Saint Martin (French part)'],
|
|
269
|
+
['MG', 'Madagascar'],
|
|
270
|
+
['MH', 'Marshall Islands'],
|
|
271
|
+
['MK', 'North Macedonia'],
|
|
272
|
+
['ML', 'Mali'],
|
|
273
|
+
['MM', 'Myanmar'],
|
|
274
|
+
['MN', 'Mongolia'],
|
|
275
|
+
['MO', 'Macao'],
|
|
276
|
+
['MP', 'Northern Mariana Islands'],
|
|
277
|
+
['MQ', 'Martinique'],
|
|
278
|
+
['MR', 'Mauritania'],
|
|
279
|
+
['MS', 'Montserrat'],
|
|
280
|
+
['MT', 'Malta'],
|
|
281
|
+
['MU', 'Mauritius'],
|
|
282
|
+
['MV', 'Maldives'],
|
|
283
|
+
['MW', 'Malawi'],
|
|
284
|
+
['MX', 'Mexico'],
|
|
285
|
+
['MY', 'Malaysia'],
|
|
286
|
+
['MZ', 'Mozambique'],
|
|
287
|
+
['NA', 'Namibia'],
|
|
288
|
+
['NC', 'New Caledonia'],
|
|
289
|
+
['NE', 'Niger'],
|
|
290
|
+
['NF', 'Norfolk Island'],
|
|
291
|
+
['NG', 'Nigeria'],
|
|
292
|
+
['NI', 'Nicaragua'],
|
|
293
|
+
['NL', 'Netherlands, Kingdom of the'],
|
|
294
|
+
['NO', 'Norway'],
|
|
295
|
+
['NP', 'Nepal'],
|
|
296
|
+
['NR', 'Nauru'],
|
|
297
|
+
['NU', 'Niue'],
|
|
298
|
+
['NZ', 'New Zealand'],
|
|
299
|
+
['OM', 'Oman'],
|
|
300
|
+
['PA', 'Panama'],
|
|
301
|
+
['PE', 'Peru'],
|
|
302
|
+
['PF', 'French Polynesia'],
|
|
303
|
+
['PG', 'Papua New Guinea'],
|
|
304
|
+
['PH', 'Philippines'],
|
|
305
|
+
['PK', 'Pakistan'],
|
|
306
|
+
['PL', 'Poland'],
|
|
307
|
+
['PM', 'Saint Pierre and Miquelon'],
|
|
308
|
+
['PN', 'Pitcairn'],
|
|
309
|
+
['PR', 'Puerto Rico'],
|
|
310
|
+
['PS', 'Palestine, State of'],
|
|
311
|
+
['PT', 'Portugal'],
|
|
312
|
+
['PW', 'Palau'],
|
|
313
|
+
['PY', 'Paraguay'],
|
|
314
|
+
['QA', 'Qatar'],
|
|
315
|
+
['RE', 'Réunion'],
|
|
316
|
+
['RO', 'Romania'],
|
|
317
|
+
['RS', 'Serbia'],
|
|
318
|
+
['RU', 'Russian Federation'],
|
|
319
|
+
['RW', 'Rwanda'],
|
|
320
|
+
['SA', 'Saudi Arabia'],
|
|
321
|
+
['SB', 'Solomon Islands'],
|
|
322
|
+
['SC', 'Seychelles'],
|
|
323
|
+
['SD', 'Sudan'],
|
|
324
|
+
['SE', 'Sweden'],
|
|
325
|
+
['SG', 'Singapore'],
|
|
326
|
+
['SH', 'Saint Helena, Ascension and Tristan da Cunha'],
|
|
327
|
+
['SI', 'Slovenia'],
|
|
328
|
+
['SJ', 'Svalbard and Jan Mayen'],
|
|
329
|
+
['SK', 'Slovakia'],
|
|
330
|
+
['SL', 'Sierra Leone'],
|
|
331
|
+
['SM', 'San Marino'],
|
|
332
|
+
['SN', 'Senegal'],
|
|
333
|
+
['SO', 'Somalia'],
|
|
334
|
+
['SR', 'Suriname'],
|
|
335
|
+
['SS', 'South Sudan'],
|
|
336
|
+
['ST', 'Sao Tome and Principe'],
|
|
337
|
+
['SV', 'El Salvador'],
|
|
338
|
+
['SX', 'Sint Maarten (Dutch part)'],
|
|
339
|
+
['SY', 'Syrian Arab Republic'],
|
|
340
|
+
['SZ', 'Eswatini'],
|
|
341
|
+
['TC', 'Turks and Caicos Islands'],
|
|
342
|
+
['TD', 'Chad'],
|
|
343
|
+
['TF', 'French Southern Territories'],
|
|
344
|
+
['TG', 'Togo'],
|
|
345
|
+
['TH', 'Thailand'],
|
|
346
|
+
['TJ', 'Tajikistan'],
|
|
347
|
+
['TK', 'Tokelau'],
|
|
348
|
+
['TL', 'Timor-Leste'],
|
|
349
|
+
['TM', 'Turkmenistan'],
|
|
350
|
+
['TN', 'Tunisia'],
|
|
351
|
+
['TO', 'Tonga'],
|
|
352
|
+
['TR', 'Türkiye'],
|
|
353
|
+
['TT', 'Trinidad and Tobago'],
|
|
354
|
+
['TV', 'Tuvalu'],
|
|
355
|
+
['TW', 'Taiwan, Province of China'],
|
|
356
|
+
['TZ', 'Tanzania, United Republic of'],
|
|
357
|
+
['UA', 'Ukraine'],
|
|
358
|
+
['UG', 'Uganda'],
|
|
359
|
+
['UK', 'United Kingdom'],
|
|
360
|
+
['UM', 'United States Minor Outlying Islands'],
|
|
361
|
+
['US', 'United States of America'],
|
|
362
|
+
['UY', 'Uruguay'],
|
|
363
|
+
['UZ', 'Uzbekistan'],
|
|
364
|
+
['VA', 'Holy See'],
|
|
365
|
+
['VC', 'Saint Vincent and the Grenadines'],
|
|
366
|
+
['VE', 'Venezuela, Bolivarian Republic of'],
|
|
367
|
+
['VG', 'Virgin Islands (British)'],
|
|
368
|
+
['VI', 'Virgin Islands (U.S.)'],
|
|
369
|
+
['VN', 'Viet Nam'],
|
|
370
|
+
['VU', 'Vanuatu'],
|
|
371
|
+
['WF', 'Wallis and Futuna'],
|
|
372
|
+
['WS', 'Samoa'],
|
|
373
|
+
['YE', 'Yemen'],
|
|
374
|
+
['YT', 'Mayotte'],
|
|
375
|
+
['ZA', 'South Africa'],
|
|
376
|
+
['ZM', 'Zambia'],
|
|
377
|
+
['ZW', 'Zimbabwe'],
|
|
378
|
+
]);
|
|
379
|
+
new Set(isoCountries.keys());
|
|
380
|
+
const parseCache = new Map();
|
|
381
|
+
const doesGeoRequestMatchList = (requestRegion, isEUCountry, geoRegions) => {
|
|
382
|
+
if (!requestRegion || !geoRegions) {
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
let parsedRegions = parseCache.get(geoRegions);
|
|
386
|
+
if (!parsedRegions) {
|
|
387
|
+
parsedRegions = new Set((geoRegions !== null && geoRegions !== void 0 ? geoRegions : '').split(','));
|
|
388
|
+
parseCache.set(geoRegions, parsedRegions);
|
|
389
|
+
}
|
|
390
|
+
if (parsedRegions.size == 0) {
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
if (isEUCountry && parsedRegions.has('EU')) {
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
return parsedRegions.has(requestRegion);
|
|
397
|
+
};
|
|
398
|
+
|
|
141
399
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
142
400
|
let edgeTagSettings;
|
|
143
401
|
const initSettings = (destination, options) => {
|
|
@@ -150,6 +408,8 @@ const initSettings = (destination, options) => {
|
|
|
150
408
|
stubs: [],
|
|
151
409
|
browserPackages: [],
|
|
152
410
|
channels: new Map(),
|
|
411
|
+
geoRegion: null,
|
|
412
|
+
isEURequest: false,
|
|
153
413
|
...options,
|
|
154
414
|
};
|
|
155
415
|
};
|
|
@@ -188,6 +448,7 @@ const getProviderVariables = (destination, packageId) => {
|
|
|
188
448
|
.filter((pkg) => pkg.package === packageId)
|
|
189
449
|
.map((pkg) => ({
|
|
190
450
|
tagName: pkg.tagName,
|
|
451
|
+
geoRegions: pkg.geoRegions || null,
|
|
191
452
|
variableSet: pkg.variables || {},
|
|
192
453
|
})) || []);
|
|
193
454
|
};
|
|
@@ -282,6 +543,7 @@ const areEqual = (a, b) => {
|
|
|
282
543
|
|
|
283
544
|
const tagStorage = 'edgeTag';
|
|
284
545
|
const consentKey = 'consent';
|
|
546
|
+
const consentCategoriesKey = 'consentCategories';
|
|
285
547
|
const keyPrefix = `_worker`;
|
|
286
548
|
const cookieKey = 'tag_user_id';
|
|
287
549
|
const fallbackSessionKey = 'fallback_tag_user_id';
|
|
@@ -569,7 +831,7 @@ const getStandardPayload = (destination, payload) => {
|
|
|
569
831
|
referrer: getReferrer(destination),
|
|
570
832
|
search: getSearch(destination),
|
|
571
833
|
locale: getLocale(),
|
|
572
|
-
sdkVersion: "0.
|
|
834
|
+
sdkVersion: "1.0.0" ,
|
|
573
835
|
...(payload || {}),
|
|
574
836
|
};
|
|
575
837
|
let storage = {};
|
|
@@ -659,6 +921,13 @@ const getConsent$1 = (destination) => {
|
|
|
659
921
|
}
|
|
660
922
|
return getSetting(destination, 'consent');
|
|
661
923
|
};
|
|
924
|
+
const getConsentCategories = (destination) => {
|
|
925
|
+
const storageConsentCategories = getDataPerKey(destination, 'local', tagStorage, consentCategoriesKey);
|
|
926
|
+
if (storageConsentCategories) {
|
|
927
|
+
return storageConsentCategories;
|
|
928
|
+
}
|
|
929
|
+
return getSetting(destination, 'consentCategories');
|
|
930
|
+
};
|
|
662
931
|
|
|
663
932
|
const processStubs = (destination) => {
|
|
664
933
|
try {
|
|
@@ -737,6 +1006,8 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
737
1006
|
const providerPackages = getSetting(destination, 'browserPackages');
|
|
738
1007
|
const configuredTags = getSetting(destination, 'channels');
|
|
739
1008
|
const skipZeroPurchaseEvent = getSetting(destination, 'skipZeroPurchaseEvent') || false;
|
|
1009
|
+
const requestRegion = getSetting(destination, 'geoRegion') || null;
|
|
1010
|
+
const isEURequest = getSetting(destination, 'isEURequest') || false;
|
|
740
1011
|
const userId = getUserId$1(destination);
|
|
741
1012
|
const providerData = {};
|
|
742
1013
|
const consent = getConsent$1(destination);
|
|
@@ -764,6 +1035,10 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
764
1035
|
logger.log(`Consent is missing (${pkg.name}: ${variable.tagName})`);
|
|
765
1036
|
continue;
|
|
766
1037
|
}
|
|
1038
|
+
if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
|
|
1039
|
+
logger.log('GEO request region does not match the filter, skiping');
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
767
1042
|
const payload = ((_a = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
768
1043
|
((_b = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _b === void 0 ? void 0 : _b.includes(pkg.name))
|
|
769
1044
|
? conversion.payload
|
|
@@ -845,6 +1120,8 @@ const processData = (destination, data, providers, options) => {
|
|
|
845
1120
|
const configuredTags = getSetting(destination, 'channels');
|
|
846
1121
|
const userId = getUserId$1(destination);
|
|
847
1122
|
const consent = getConsent$1(destination);
|
|
1123
|
+
const requestRegion = getSetting(destination, 'geoRegion') || null;
|
|
1124
|
+
const isEURequest = getSetting(destination, 'isEURequest') || false;
|
|
848
1125
|
for (const pkg of providerPackages) {
|
|
849
1126
|
if (!pkg || !pkg.user || !pkg.name) {
|
|
850
1127
|
continue;
|
|
@@ -863,6 +1140,10 @@ const processData = (destination, data, providers, options) => {
|
|
|
863
1140
|
logger.log(`Consent is missing for ${pkg.name} (${variable.tagName})`);
|
|
864
1141
|
continue;
|
|
865
1142
|
}
|
|
1143
|
+
if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
|
|
1144
|
+
logger.log(`GEO request region does not match list, skipping`);
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
866
1147
|
pkg.user({
|
|
867
1148
|
userId,
|
|
868
1149
|
data,
|
|
@@ -886,43 +1167,50 @@ const handleData = (data, providers, options) => {
|
|
|
886
1167
|
});
|
|
887
1168
|
};
|
|
888
1169
|
|
|
889
|
-
const handleConsent = (consent, options) => {
|
|
1170
|
+
const handleConsent = (consent, consentCategories, options) => {
|
|
890
1171
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|
|
891
|
-
processConsent(options.destination, consent, options);
|
|
1172
|
+
processConsent(options.destination, consent, consentCategories, options);
|
|
892
1173
|
return;
|
|
893
1174
|
}
|
|
894
1175
|
getInstances().forEach((destination) => {
|
|
895
|
-
processConsent(destination, consent, options);
|
|
1176
|
+
processConsent(destination, consent, consentCategories, options);
|
|
896
1177
|
});
|
|
897
1178
|
};
|
|
898
|
-
const saveConsent = (destination, consent) => {
|
|
1179
|
+
const saveConsent = (destination, consent, consentCategories) => {
|
|
899
1180
|
setSetting(destination, {
|
|
900
1181
|
consent,
|
|
1182
|
+
consentCategories,
|
|
901
1183
|
});
|
|
902
1184
|
savePerKey(destination, 'local', tagStorage, consent, consentKey);
|
|
1185
|
+
savePerKey(destination, 'local', tagStorage, consentCategories, consentCategoriesKey);
|
|
903
1186
|
};
|
|
904
|
-
const processConsent = (destination, consent, options) => {
|
|
1187
|
+
const processConsent = (destination, consent, consentCategories, options) => {
|
|
905
1188
|
const existingConsent = getConsent$1(destination);
|
|
906
|
-
|
|
1189
|
+
const existingConsentCategories = getConsentCategories(destination);
|
|
1190
|
+
if (areEqual(existingConsent, consent) &&
|
|
1191
|
+
areEqual(existingConsentCategories, consentCategories)) {
|
|
907
1192
|
return;
|
|
908
1193
|
}
|
|
909
1194
|
if (!getSetting(destination, 'initialized')) {
|
|
910
1195
|
addStub(destination, {
|
|
911
1196
|
name: 'consent',
|
|
912
|
-
arguments: [consent, options],
|
|
1197
|
+
arguments: [consent, consentCategories, options],
|
|
913
1198
|
});
|
|
914
1199
|
return;
|
|
915
1200
|
}
|
|
916
1201
|
const payload = {
|
|
917
1202
|
consentString: consent,
|
|
1203
|
+
consentCategories: { ...consentCategories, necessary: true },
|
|
918
1204
|
};
|
|
919
|
-
saveConsent(destination, consent);
|
|
1205
|
+
saveConsent(destination, consent, consentCategories);
|
|
920
1206
|
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
921
1207
|
postRequest(getConsentURL(destination), payload).catch(logger.error);
|
|
922
1208
|
}
|
|
923
1209
|
const userId = getUserId$1(destination);
|
|
924
1210
|
const providerPackages = getSetting(destination, 'browserPackages');
|
|
925
1211
|
const executionContext = new Map();
|
|
1212
|
+
const requestRegion = getSetting(destination, 'geoRegion') || null;
|
|
1213
|
+
const isEURequest = getSetting(destination, 'isEURequest') || false;
|
|
926
1214
|
/* Calling Init for all provider instances based on consent check */
|
|
927
1215
|
for (const pkg of providerPackages) {
|
|
928
1216
|
if (!pkg || !pkg.name || !pkg.init) {
|
|
@@ -934,6 +1222,9 @@ const processConsent = (destination, consent, options) => {
|
|
|
934
1222
|
if (!hasConsent) {
|
|
935
1223
|
continue;
|
|
936
1224
|
}
|
|
1225
|
+
if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
937
1228
|
pkg.init({
|
|
938
1229
|
userId,
|
|
939
1230
|
isNewUser: false,
|
|
@@ -942,6 +1233,7 @@ const processConsent = (destination, consent, options) => {
|
|
|
942
1233
|
tagName: variable.tagName,
|
|
943
1234
|
variables: variable.variableSet,
|
|
944
1235
|
package: pkg.name,
|
|
1236
|
+
geoRegions: variable.geoRegions,
|
|
945
1237
|
},
|
|
946
1238
|
sendTag: sendTag.bind(null, destination),
|
|
947
1239
|
sendEdgeData: processData.bind(null, destination),
|
|
@@ -950,6 +1242,10 @@ const processConsent = (destination, consent, options) => {
|
|
|
950
1242
|
executionContext,
|
|
951
1243
|
session: null,
|
|
952
1244
|
destination,
|
|
1245
|
+
consentData: {
|
|
1246
|
+
consent,
|
|
1247
|
+
categories: { ...consentCategories, necessary: true },
|
|
1248
|
+
},
|
|
953
1249
|
});
|
|
954
1250
|
}
|
|
955
1251
|
}
|
|
@@ -970,9 +1266,17 @@ const processConsent = (destination, consent, options) => {
|
|
|
970
1266
|
if (!pkg || !pkg.name || !pkg.consent) {
|
|
971
1267
|
continue;
|
|
972
1268
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1269
|
+
const variables = getProviderVariables(destination, pkg.name);
|
|
1270
|
+
pkg.consent({
|
|
1271
|
+
consentData: {
|
|
1272
|
+
consent,
|
|
1273
|
+
categories: {
|
|
1274
|
+
...consentCategories,
|
|
1275
|
+
necessary: true,
|
|
1276
|
+
},
|
|
1277
|
+
},
|
|
1278
|
+
variables,
|
|
1279
|
+
});
|
|
976
1280
|
}
|
|
977
1281
|
};
|
|
978
1282
|
|
|
@@ -1140,7 +1444,8 @@ const handleManifest = (destination, response) => {
|
|
|
1140
1444
|
if (pkg && pkg.name && pkg.init) {
|
|
1141
1445
|
/* this defines if the consent is given for a specific instance of a provider */
|
|
1142
1446
|
const hasConsent = hasUserConsent(getSetting(destination, 'consent'), pkg.name, provider.tagName);
|
|
1143
|
-
if (hasConsent
|
|
1447
|
+
if (hasConsent &&
|
|
1448
|
+
doesGeoRequestMatchList(response.geoRegion, response.isEURequest, provider.geoRegions)) {
|
|
1144
1449
|
pkg.init({
|
|
1145
1450
|
userId,
|
|
1146
1451
|
isNewUser: !!response.isNewUser,
|
|
@@ -1153,6 +1458,10 @@ const handleManifest = (destination, response) => {
|
|
|
1153
1458
|
keyName,
|
|
1154
1459
|
executionContext,
|
|
1155
1460
|
destination,
|
|
1461
|
+
consentData: {
|
|
1462
|
+
consent: response.consent,
|
|
1463
|
+
categories: response.consentCategories,
|
|
1464
|
+
},
|
|
1156
1465
|
});
|
|
1157
1466
|
}
|
|
1158
1467
|
}
|
|
@@ -1196,7 +1505,11 @@ const handleInit = (preferences) => {
|
|
|
1196
1505
|
const url = new URL(getInitURL(preferences.edgeURL));
|
|
1197
1506
|
if (preferences.disableConsentCheck) {
|
|
1198
1507
|
url.searchParams.set('consentDisabled', 'true');
|
|
1199
|
-
saveConsent(preferences.edgeURL, {
|
|
1508
|
+
saveConsent(preferences.edgeURL, {
|
|
1509
|
+
all: true,
|
|
1510
|
+
}, {
|
|
1511
|
+
all: true,
|
|
1512
|
+
});
|
|
1200
1513
|
}
|
|
1201
1514
|
if (preferences.userId) {
|
|
1202
1515
|
setSetting(preferences.edgeURL, { userId: preferences.userId });
|
|
@@ -1217,7 +1530,7 @@ const handleInit = (preferences) => {
|
|
|
1217
1530
|
return;
|
|
1218
1531
|
}
|
|
1219
1532
|
if (result.isNewUser && result.consent) {
|
|
1220
|
-
saveConsent(preferences.edgeURL, result.consent);
|
|
1533
|
+
saveConsent(preferences.edgeURL, result.consent, result.consentCategories);
|
|
1221
1534
|
}
|
|
1222
1535
|
const providers = {};
|
|
1223
1536
|
(_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
|
|
@@ -1236,6 +1549,8 @@ const handleInit = (preferences) => {
|
|
|
1236
1549
|
storageId: result.storageId,
|
|
1237
1550
|
currency: result.currency,
|
|
1238
1551
|
skipZeroPurchaseEvent: result.skipZeroPurchaseEvent,
|
|
1552
|
+
geoRegion: result.geoRegion,
|
|
1553
|
+
isEURequest: result.isEURequest,
|
|
1239
1554
|
});
|
|
1240
1555
|
if (result.storageId != null) {
|
|
1241
1556
|
savePerKey(preferences.edgeURL, 'local', tagStorage, result.storageId, storageIdKey);
|
|
@@ -1268,6 +1583,8 @@ const processUser = (destination, key, value, providers, options) => {
|
|
|
1268
1583
|
const configuredTags = getSetting(destination, 'channels');
|
|
1269
1584
|
const consent = getConsent$1(destination);
|
|
1270
1585
|
const userId = getUserId$1(destination);
|
|
1586
|
+
const requestRegion = getSetting(destination, 'geoRegion') || null;
|
|
1587
|
+
const isEURequest = getSetting(destination, 'isEURequest') || false;
|
|
1271
1588
|
for (const pkg of providerPackages) {
|
|
1272
1589
|
if (!pkg || !pkg.name || !pkg.user) {
|
|
1273
1590
|
continue;
|
|
@@ -1286,6 +1603,10 @@ const processUser = (destination, key, value, providers, options) => {
|
|
|
1286
1603
|
logger.log(`User do not have consent for ${pkg.name} (${variable.tagName})`);
|
|
1287
1604
|
continue;
|
|
1288
1605
|
}
|
|
1606
|
+
if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
|
|
1607
|
+
logger.log(`GEO request region does not match list, skipping`);
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1289
1610
|
pkg.user({
|
|
1290
1611
|
userId,
|
|
1291
1612
|
data: { [key]: value },
|
|
@@ -1401,8 +1722,8 @@ const init = (preferences) => {
|
|
|
1401
1722
|
const tag = (name, data, providers, options) => {
|
|
1402
1723
|
handleTag(name, data, providers, options);
|
|
1403
1724
|
};
|
|
1404
|
-
const consent = (value, options) => {
|
|
1405
|
-
handleConsent(value, options);
|
|
1725
|
+
const consent = (value, consentCategories, options) => {
|
|
1726
|
+
handleConsent(value, consentCategories, options);
|
|
1406
1727
|
};
|
|
1407
1728
|
const user = (key, value, providers, options) => {
|
|
1408
1729
|
handleUser(key, value, providers, options);
|
package/internal.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
Library,
|
|
4
4
|
ProvidersConfig,
|
|
5
5
|
UserConsent,
|
|
6
|
+
UserConsentCategories,
|
|
6
7
|
} from '@blotoutio/cdn/types'
|
|
7
|
-
import { UserKey, Data } from './index'
|
|
8
|
+
import { UserKey, Data, Manifest } from './index'
|
|
8
9
|
|
|
9
10
|
type Navigator = {
|
|
10
11
|
userAgent: string
|
|
@@ -51,6 +52,7 @@ type InitResponse = {
|
|
|
51
52
|
userId?: string
|
|
52
53
|
storageId?: number
|
|
53
54
|
consent: UserConsent
|
|
55
|
+
consentCategories: UserConsentCategories
|
|
54
56
|
consentSetting: ConsentSetting
|
|
55
57
|
isNewUser?: boolean
|
|
56
58
|
session: {
|
|
@@ -61,4 +63,6 @@ type InitResponse = {
|
|
|
61
63
|
rates: { from: string; to: string; value: number }[]
|
|
62
64
|
}
|
|
63
65
|
skipZeroPurchaseEvent?: boolean
|
|
66
|
+
geoRegion: string | null
|
|
67
|
+
isEURequest: boolean
|
|
64
68
|
}
|