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