@blotoutio/edgetag-sdk-browser 0.26.1 → 0.26.2
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 +151 -150
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -324,7 +324,7 @@
|
|
|
324
324
|
referrer: getReferrer(),
|
|
325
325
|
search: getSearch(),
|
|
326
326
|
locale: getLocale(),
|
|
327
|
-
sdkVersion: "0.26.
|
|
327
|
+
sdkVersion: "0.26.2" ,
|
|
328
328
|
...(payload || {}),
|
|
329
329
|
};
|
|
330
330
|
let storage = {};
|
|
@@ -432,7 +432,64 @@
|
|
|
432
432
|
return memoryConsent;
|
|
433
433
|
};
|
|
434
434
|
|
|
435
|
-
const
|
|
435
|
+
const isBool = (v) => typeof v == 'boolean';
|
|
436
|
+
const isRecord = (v) => !!v && typeof v == 'object';
|
|
437
|
+
/**
|
|
438
|
+
* This function validates user consent for a given provider and tag name.
|
|
439
|
+
* It should be used in conjunction with `UserConsent`, not `ProvidersConfig`.
|
|
440
|
+
*/
|
|
441
|
+
const hasUserConsent = (consent, provider, tagName) => {
|
|
442
|
+
if (!isRecord(consent)) {
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
let allowed = isBool(consent.all) ? consent.all : false;
|
|
446
|
+
if (provider in consent) {
|
|
447
|
+
const providerSpecific = consent[provider];
|
|
448
|
+
if (isBool(providerSpecific)) {
|
|
449
|
+
allowed = providerSpecific;
|
|
450
|
+
}
|
|
451
|
+
else if (isRecord(providerSpecific)) {
|
|
452
|
+
if ('all' in providerSpecific && isBool(providerSpecific.all)) {
|
|
453
|
+
allowed = providerSpecific.all;
|
|
454
|
+
}
|
|
455
|
+
if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
|
|
456
|
+
allowed = providerSpecific[tagName];
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return allowed;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* This function validates provider allowance for a given provider and tag name.
|
|
464
|
+
* It should not be used to validate `UserConsent`.
|
|
465
|
+
*/
|
|
466
|
+
const isProviderInstanceAllowed = (providersConfig, provider, tagName) => {
|
|
467
|
+
if (!isRecord(providersConfig)) {
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
let allowed = isBool(providersConfig.all) ? providersConfig.all : true;
|
|
471
|
+
if (provider in providersConfig) {
|
|
472
|
+
const providerSpecific = providersConfig[provider];
|
|
473
|
+
if (isBool(providerSpecific)) {
|
|
474
|
+
allowed = providerSpecific;
|
|
475
|
+
}
|
|
476
|
+
else if (isRecord(providerSpecific)) {
|
|
477
|
+
if ('all' in providerSpecific && isBool(providerSpecific.all)) {
|
|
478
|
+
allowed = providerSpecific.all;
|
|
479
|
+
}
|
|
480
|
+
if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
|
|
481
|
+
allowed = providerSpecific[tagName];
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return allowed;
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const upsert = (map, key, update, createDefault) => {
|
|
489
|
+
const currentValue = map.has(key) ? map.get(key) : createDefault();
|
|
490
|
+
return map.set(key, update(currentValue));
|
|
491
|
+
};
|
|
492
|
+
|
|
436
493
|
let initialized = false;
|
|
437
494
|
const providersPackages = {};
|
|
438
495
|
const setPreferences = (preferences) => {
|
|
@@ -472,12 +529,9 @@
|
|
|
472
529
|
const setInitialized = () => {
|
|
473
530
|
initialized = true;
|
|
474
531
|
};
|
|
475
|
-
const
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
allowedProvider.add(provider);
|
|
479
|
-
}
|
|
480
|
-
};
|
|
532
|
+
const configuredTags = new Map();
|
|
533
|
+
const addConfiguredTag = (pkg, tagName) => upsert(configuredTags, pkg, (names) => names.add(tagName), () => new Set());
|
|
534
|
+
const getConfiguredTags = () => configuredTags;
|
|
481
535
|
|
|
482
536
|
const manifestVariables = {};
|
|
483
537
|
const addProviderVariable = (name, variables, tagName) => {
|
|
@@ -512,59 +566,6 @@
|
|
|
512
566
|
}
|
|
513
567
|
};
|
|
514
568
|
|
|
515
|
-
const isBool = (v) => typeof v == 'boolean';
|
|
516
|
-
const isRecord = (v) => !!v && typeof v == 'object';
|
|
517
|
-
/**
|
|
518
|
-
* This function validates user consent for a given provider and tag name.
|
|
519
|
-
* It should be used in conjunction with `UserConsent`, not `ProvidersConfig`.
|
|
520
|
-
*/
|
|
521
|
-
const hasUserConsent = (consent, provider, tagName) => {
|
|
522
|
-
if (!isRecord(consent)) {
|
|
523
|
-
return false;
|
|
524
|
-
}
|
|
525
|
-
let allowed = isBool(consent.all) ? consent.all : false;
|
|
526
|
-
if (provider in consent) {
|
|
527
|
-
const providerSpecific = consent[provider];
|
|
528
|
-
if (isBool(providerSpecific)) {
|
|
529
|
-
allowed = providerSpecific;
|
|
530
|
-
}
|
|
531
|
-
else if (isRecord(providerSpecific)) {
|
|
532
|
-
if ('all' in providerSpecific && isBool(providerSpecific.all)) {
|
|
533
|
-
allowed = providerSpecific.all;
|
|
534
|
-
}
|
|
535
|
-
if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
|
|
536
|
-
allowed = providerSpecific[tagName];
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
return allowed;
|
|
541
|
-
};
|
|
542
|
-
/**
|
|
543
|
-
* This function validates provider allowance for a given provider and tag name.
|
|
544
|
-
* It should not be used to validate `UserConsent`.
|
|
545
|
-
*/
|
|
546
|
-
const isProviderInstanceAllowed = (providersConfig, provider, tagName) => {
|
|
547
|
-
if (!isRecord(providersConfig)) {
|
|
548
|
-
return true;
|
|
549
|
-
}
|
|
550
|
-
let allowed = isBool(providersConfig.all) ? providersConfig.all : true;
|
|
551
|
-
if (provider in providersConfig) {
|
|
552
|
-
const providerSpecific = providersConfig[provider];
|
|
553
|
-
if (isBool(providerSpecific)) {
|
|
554
|
-
allowed = providerSpecific;
|
|
555
|
-
}
|
|
556
|
-
else if (isRecord(providerSpecific)) {
|
|
557
|
-
if ('all' in providerSpecific && isBool(providerSpecific.all)) {
|
|
558
|
-
allowed = providerSpecific.all;
|
|
559
|
-
}
|
|
560
|
-
if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
|
|
561
|
-
allowed = providerSpecific[tagName];
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return allowed;
|
|
566
|
-
};
|
|
567
|
-
|
|
568
569
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
569
570
|
const payload = {
|
|
570
571
|
eventName,
|
|
@@ -591,47 +592,43 @@
|
|
|
591
592
|
eventId = generateEventId(eventName);
|
|
592
593
|
}
|
|
593
594
|
const providerPackages = getProvidersPackage();
|
|
595
|
+
const configuredTags = getConfiguredTags();
|
|
594
596
|
const userId = handleGetUserId();
|
|
595
597
|
const providerData = {};
|
|
596
598
|
const consent = getConsent();
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
599
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
600
|
+
if (!pkg || !pkg.name || !pkg.tag) {
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (!configuredTags.has(pkg.name)) {
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
const variables = getProviderVariables(pkg.name);
|
|
607
|
+
const result = {};
|
|
608
|
+
const providerVariables = Object.entries(variables);
|
|
609
|
+
const executionContext = new Map();
|
|
610
|
+
for (const [tagName, variableSet] of providerVariables) {
|
|
611
|
+
if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
|
|
612
|
+
log(`Provider instance is not allowed (${pkg.name}: ${tagName})`);
|
|
602
613
|
continue;
|
|
603
614
|
}
|
|
604
|
-
if (!
|
|
615
|
+
if (!hasUserConsent(consent, pkg.name, tagName)) {
|
|
616
|
+
log(`Consent is missing (${pkg.name}: ${tagName})`);
|
|
605
617
|
continue;
|
|
606
618
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
if (!hasUserConsent(consent, pkg.name, tagName)) {
|
|
617
|
-
log(`Consent is missing (${pkg.name}: ${tagName})`);
|
|
618
|
-
continue;
|
|
619
|
-
}
|
|
620
|
-
anyProviderCalled = true;
|
|
621
|
-
result[tagName] = pkg.tag({
|
|
622
|
-
userId,
|
|
623
|
-
eventName,
|
|
624
|
-
eventId,
|
|
625
|
-
data: JSON.parse(JSON.stringify(data)),
|
|
626
|
-
sendTag,
|
|
627
|
-
manifestVariables: variableSet,
|
|
628
|
-
executionContext,
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
providerData[pkg.name] = result;
|
|
619
|
+
result[tagName] = pkg.tag({
|
|
620
|
+
userId,
|
|
621
|
+
eventName,
|
|
622
|
+
eventId,
|
|
623
|
+
data: JSON.parse(JSON.stringify(data)),
|
|
624
|
+
sendTag,
|
|
625
|
+
manifestVariables: variableSet,
|
|
626
|
+
executionContext,
|
|
627
|
+
});
|
|
632
628
|
}
|
|
629
|
+
providerData[pkg.name] = result;
|
|
633
630
|
}
|
|
634
|
-
if (!
|
|
631
|
+
if (!hasAllowedManifestTags(configuredTags, consent, providers)) {
|
|
635
632
|
return;
|
|
636
633
|
}
|
|
637
634
|
sendTag({
|
|
@@ -643,6 +640,17 @@
|
|
|
643
640
|
options,
|
|
644
641
|
});
|
|
645
642
|
};
|
|
643
|
+
const hasAllowedManifestTags = (tags, consent, providersConfig) => {
|
|
644
|
+
for (const [pkg, tagNames] of tags) {
|
|
645
|
+
for (const tagName of tagNames) {
|
|
646
|
+
if (hasUserConsent(consent, pkg, tagName) &&
|
|
647
|
+
isProviderInstanceAllowed(providersConfig, pkg, tagName)) {
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return false;
|
|
653
|
+
};
|
|
646
654
|
|
|
647
655
|
const handleData = (data, providers, options) => {
|
|
648
656
|
if (!data || Object.keys(data).length === 0) {
|
|
@@ -651,33 +659,31 @@
|
|
|
651
659
|
}
|
|
652
660
|
saveKV(data);
|
|
653
661
|
const providerPackages = getProvidersPackage();
|
|
662
|
+
const configuredTags = getConfiguredTags();
|
|
654
663
|
const userId = handleGetUserId();
|
|
655
664
|
const consent = getConsent();
|
|
656
|
-
const
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
665
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
666
|
+
if (!pkg || !pkg.user || !pkg.name) {
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (!configuredTags.has(pkg.name)) {
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
const variables = getProviderVariables(pkg.name);
|
|
673
|
+
for (const [tagName, variableSet] of Object.entries(variables)) {
|
|
674
|
+
if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
|
|
675
|
+
log(`Data not allowed for ${pkg.name} (${tagName})`);
|
|
660
676
|
continue;
|
|
661
677
|
}
|
|
662
|
-
if (!
|
|
678
|
+
if (!hasUserConsent(consent, pkg.name, tagName)) {
|
|
679
|
+
log(`Consent is missing for ${pkg.name} (${tagName})`);
|
|
663
680
|
continue;
|
|
664
681
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
}
|
|
671
|
-
if (!hasUserConsent(consent, pkg.name, tagName)) {
|
|
672
|
-
log(`Consent is missing for ${pkg.name} (${tagName})`);
|
|
673
|
-
continue;
|
|
674
|
-
}
|
|
675
|
-
pkg.user({
|
|
676
|
-
userId,
|
|
677
|
-
data,
|
|
678
|
-
manifestVariables: variableSet,
|
|
679
|
-
});
|
|
680
|
-
}
|
|
682
|
+
pkg.user({
|
|
683
|
+
userId,
|
|
684
|
+
data,
|
|
685
|
+
manifestVariables: variableSet,
|
|
686
|
+
});
|
|
681
687
|
}
|
|
682
688
|
}
|
|
683
689
|
postRequest(getDataURL(), { data, providers }, options).catch(error);
|
|
@@ -780,8 +786,8 @@
|
|
|
780
786
|
const handleManifest = (manifest) => {
|
|
781
787
|
const providerPackages = getProvidersPackage();
|
|
782
788
|
const userId = handleGetUserId();
|
|
783
|
-
setAllowedProviders(manifest.map((provider) => provider.package));
|
|
784
789
|
manifest.forEach((provider) => {
|
|
790
|
+
addConfiguredTag(provider.package, provider.tagName);
|
|
785
791
|
addProviderVariable(provider.package, provider.variables, provider.tagName);
|
|
786
792
|
if (provider.rules) {
|
|
787
793
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
@@ -793,18 +799,16 @@
|
|
|
793
799
|
}
|
|
794
800
|
});
|
|
795
801
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
});
|
|
807
|
-
}
|
|
802
|
+
const pkg = providerPackages[provider.package];
|
|
803
|
+
if (pkg && pkg.name && pkg.init) {
|
|
804
|
+
pkg.init({
|
|
805
|
+
userId,
|
|
806
|
+
manifest: provider,
|
|
807
|
+
sendTag,
|
|
808
|
+
sendEdgeData: handleData,
|
|
809
|
+
getEdgeData: handleGetData,
|
|
810
|
+
keyName: `${keyPrefix}Store`,
|
|
811
|
+
});
|
|
808
812
|
}
|
|
809
813
|
});
|
|
810
814
|
setInitialized();
|
|
@@ -854,35 +858,32 @@
|
|
|
854
858
|
saveKV({
|
|
855
859
|
[key]: value,
|
|
856
860
|
});
|
|
857
|
-
const consent = getConsent();
|
|
858
|
-
const allowedProviders = getAllowedProviders();
|
|
859
861
|
const providerPackages = getProvidersPackage();
|
|
862
|
+
const configuredTags = getConfiguredTags();
|
|
863
|
+
const consent = getConsent();
|
|
860
864
|
const userId = handleGetUserId();
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
865
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
866
|
+
if (!pkg || !pkg.name || !pkg.user) {
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
if (!configuredTags.has(pkg.name)) {
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
const variables = getProviderVariables(pkg.name);
|
|
873
|
+
for (const [tagName, variableSet] of Object.entries(variables)) {
|
|
874
|
+
if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
|
|
875
|
+
log(`User not allowed for ${pkg.name} (${tagName})`);
|
|
864
876
|
continue;
|
|
865
877
|
}
|
|
866
|
-
if (!
|
|
878
|
+
if (!hasUserConsent(consent, pkg.name, tagName)) {
|
|
879
|
+
log(`User doesn't have consent for ${pkg.name} (${tagName})`);
|
|
867
880
|
continue;
|
|
868
881
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
continue;
|
|
875
|
-
}
|
|
876
|
-
if (!hasUserConsent(consent, pkg.name, tagName)) {
|
|
877
|
-
log(`User doesn't have consent for ${pkg.name} (${tagName})`);
|
|
878
|
-
continue;
|
|
879
|
-
}
|
|
880
|
-
pkg.user({
|
|
881
|
-
userId,
|
|
882
|
-
data: { [key]: value },
|
|
883
|
-
manifestVariables: variableSet,
|
|
884
|
-
});
|
|
885
|
-
}
|
|
882
|
+
pkg.user({
|
|
883
|
+
userId,
|
|
884
|
+
data: { [key]: value },
|
|
885
|
+
manifestVariables: variableSet,
|
|
886
|
+
});
|
|
886
887
|
}
|
|
887
888
|
}
|
|
888
889
|
postRequest(getUserURL(), {
|