@blotoutio/edgetag-sdk-browser 1.57.0 → 1.58.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.js +83 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -508,6 +508,74 @@
|
|
|
508
508
|
['US-VI', 'Virgin Islands, U.S.'],
|
|
509
509
|
]);
|
|
510
510
|
new Set([...isoCountries.keys(), ...usStates.keys()]);
|
|
511
|
+
/**
|
|
512
|
+
* ISO 3166-1 alpha-2 codes for EU member states (as of 2024)
|
|
513
|
+
*/
|
|
514
|
+
const EU_COUNTRY_CODES = new Set([
|
|
515
|
+
'AT', // Austria
|
|
516
|
+
'BE', // Belgium
|
|
517
|
+
'BG', // Bulgaria
|
|
518
|
+
'CY', // Cyprus
|
|
519
|
+
'CZ', // Czech Republic
|
|
520
|
+
'DE', // Germany
|
|
521
|
+
'DK', // Denmark
|
|
522
|
+
'EE', // Estonia
|
|
523
|
+
'ES', // Spain
|
|
524
|
+
'FI', // Finland
|
|
525
|
+
'FR', // France
|
|
526
|
+
'GR', // Greece
|
|
527
|
+
'HR', // Croatia
|
|
528
|
+
'HU', // Hungary
|
|
529
|
+
'IE', // Ireland
|
|
530
|
+
'IT', // Italy
|
|
531
|
+
'LT', // Lithuania
|
|
532
|
+
'LU', // Luxembourg
|
|
533
|
+
'LV', // Latvia
|
|
534
|
+
'MT', // Malta
|
|
535
|
+
'NL', // Netherlands
|
|
536
|
+
'PL', // Poland
|
|
537
|
+
'PT', // Portugal
|
|
538
|
+
'RO', // Romania
|
|
539
|
+
'SE', // Sweden
|
|
540
|
+
'SI', // Slovenia
|
|
541
|
+
'SK', // Slovakia
|
|
542
|
+
]);
|
|
543
|
+
/**
|
|
544
|
+
* Returns true if the request originates from the EU or the UK (GB).
|
|
545
|
+
* Cloudflare's isEUCountry flag excludes the UK post-Brexit, so GB is
|
|
546
|
+
* checked explicitly alongside the EU member set.
|
|
547
|
+
*
|
|
548
|
+
* Fails closed: when the country cannot be resolved, the request is treated
|
|
549
|
+
* as EU/UK. This is the safe default for the compliance-sensitive Grey Switch
|
|
550
|
+
* (an unknown visitor may be in the EU/UK, so it must not slip through when
|
|
551
|
+
* the EU/UK toggle is off).
|
|
552
|
+
*/
|
|
553
|
+
const isEuUkRegion = (country, isEURequest) => {
|
|
554
|
+
if (isEURequest) {
|
|
555
|
+
return true;
|
|
556
|
+
}
|
|
557
|
+
if (!country) {
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
const upper = country.toUpperCase();
|
|
561
|
+
return upper === 'GB' || EU_COUNTRY_CODES.has(upper);
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Grey Switch fire rule, shared by the SDK and the CDN worker so both stay in
|
|
565
|
+
* sync. When Grey Switch is on, EdgeTag fires server-side events for
|
|
566
|
+
* non-consented users. The EU/UK toggle is off by default, which keeps EU/UK
|
|
567
|
+
* visitors on normal consent unless the merchant explicitly opts those regions
|
|
568
|
+
* in. Returns whether a server-side event should fire for a non-consented user.
|
|
569
|
+
*/
|
|
570
|
+
const greySwitchAllowsServerEvent = ({ greySwitch, greySwitchEuUk, country, isEURequest, }) => {
|
|
571
|
+
if (!greySwitch) {
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
if (greySwitchEuUk) {
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
return !isEuUkRegion(country, isEURequest);
|
|
578
|
+
};
|
|
511
579
|
const parseCache = new Map();
|
|
512
580
|
const parseRegions = (regionString) => {
|
|
513
581
|
const include = new Set();
|
|
@@ -1225,7 +1293,7 @@
|
|
|
1225
1293
|
time = perf.toFixed(4);
|
|
1226
1294
|
}
|
|
1227
1295
|
}
|
|
1228
|
-
return `${encodeString(name)}-${generateUUID()}-${time}`;
|
|
1296
|
+
return `${encodeString(name).replace(/[^a-zA-Z0-9]/g, '')}-${generateUUID()}-${time}`;
|
|
1229
1297
|
};
|
|
1230
1298
|
|
|
1231
1299
|
const getCookieValue = (key) => {
|
|
@@ -1471,7 +1539,7 @@
|
|
|
1471
1539
|
referrer: getReferrer(destination),
|
|
1472
1540
|
search: getSearch(destination),
|
|
1473
1541
|
locale: getLocale(),
|
|
1474
|
-
sdkVersion: "1.
|
|
1542
|
+
sdkVersion: "1.58.0" ,
|
|
1475
1543
|
...(payload || {}),
|
|
1476
1544
|
};
|
|
1477
1545
|
let storage = {};
|
|
@@ -1747,6 +1815,15 @@
|
|
|
1747
1815
|
const consentCategory = getConsentCategories(destination);
|
|
1748
1816
|
const consentSettings = getSetting(destination, 'consentSetting');
|
|
1749
1817
|
const userConsent = { consentChannel, consentCategory, consentSettings };
|
|
1818
|
+
// Grey Switch: when enabled, still send the event to the server for
|
|
1819
|
+
// non-consented users. Browser pixels remain gated by hasUserConsent below,
|
|
1820
|
+
// so nothing fires client-side.
|
|
1821
|
+
const greySwitchAllows = greySwitchAllowsServerEvent({
|
|
1822
|
+
greySwitch: getSetting(destination, 'greySwitch') || false,
|
|
1823
|
+
greySwitchEuUk: getSetting(destination, 'greySwitchEuUk') || false,
|
|
1824
|
+
country: requestCountry,
|
|
1825
|
+
isEURequest,
|
|
1826
|
+
});
|
|
1750
1827
|
const ip = getSetting(destination, 'ip') || null;
|
|
1751
1828
|
const userProperties = getSetting(destination, 'userProperties');
|
|
1752
1829
|
if (skipZeroPurchaseEvent && isZeroPurchaseEvent({ eventName, data })) {
|
|
@@ -1903,7 +1980,8 @@
|
|
|
1903
1980
|
else {
|
|
1904
1981
|
logger.log('Browser events skipped by event rules, sending tag to server only');
|
|
1905
1982
|
}
|
|
1906
|
-
if (!hasAllowedManifestTags(configuredTags, userConsent, providers)
|
|
1983
|
+
if (!hasAllowedManifestTags(configuredTags, userConsent, providers) &&
|
|
1984
|
+
!greySwitchAllows) {
|
|
1907
1985
|
return;
|
|
1908
1986
|
}
|
|
1909
1987
|
sendTag(destination, {
|
|
@@ -2474,6 +2552,8 @@
|
|
|
2474
2552
|
storageId: result.storageId,
|
|
2475
2553
|
currency: result.currency,
|
|
2476
2554
|
skipZeroPurchaseEvent: result.skipZeroPurchaseEvent,
|
|
2555
|
+
greySwitch: result.greySwitch,
|
|
2556
|
+
greySwitchEuUk: result.greySwitchEuUk,
|
|
2477
2557
|
geoCountry: result.geoCountry,
|
|
2478
2558
|
geoRegion: result.geoRegion,
|
|
2479
2559
|
isEURequest: result.isEURequest,
|