@blotoutio/edgetag-sdk-js 0.35.3 → 0.36.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 +115 -52
- package/index.d.ts +16 -63
- package/index.mjs +115 -52
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -335,7 +335,7 @@ const getStandardPayload = (payload) => {
|
|
|
335
335
|
referrer: getReferrer(),
|
|
336
336
|
search: getSearch(),
|
|
337
337
|
locale: getLocale(),
|
|
338
|
-
sdkVersion: "0.
|
|
338
|
+
sdkVersion: "0.36.0" ,
|
|
339
339
|
...(payload || {}),
|
|
340
340
|
};
|
|
341
341
|
let storage = {};
|
|
@@ -422,31 +422,6 @@ const getKeysURL = () => {
|
|
|
422
422
|
return generateUrl(`/keys`);
|
|
423
423
|
};
|
|
424
424
|
|
|
425
|
-
let memoryConsent;
|
|
426
|
-
const saveConsent = (consent) => {
|
|
427
|
-
setConsent(consent);
|
|
428
|
-
savePerKey('local', tagStorage, consent, consentKey);
|
|
429
|
-
};
|
|
430
|
-
const handleConsent = (consent, options) => {
|
|
431
|
-
const payload = {
|
|
432
|
-
consentString: consent,
|
|
433
|
-
};
|
|
434
|
-
saveConsent(consent);
|
|
435
|
-
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
436
|
-
postRequest(getConsentURL(), payload).catch(error);
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
const setConsent = (newConsent) => {
|
|
440
|
-
memoryConsent = newConsent;
|
|
441
|
-
};
|
|
442
|
-
const getConsent$1 = () => {
|
|
443
|
-
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
444
|
-
if (storageConsent) {
|
|
445
|
-
return storageConsent;
|
|
446
|
-
}
|
|
447
|
-
return memoryConsent;
|
|
448
|
-
};
|
|
449
|
-
|
|
450
425
|
const isBool = (v) => typeof v == 'boolean';
|
|
451
426
|
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
|
|
452
427
|
/**
|
|
@@ -474,6 +449,25 @@ const hasUserConsent = (consent, provider, tagName) => {
|
|
|
474
449
|
}
|
|
475
450
|
return allowed;
|
|
476
451
|
};
|
|
452
|
+
/**
|
|
453
|
+
* This function validates user consent for a given provider type, not based on tagName.
|
|
454
|
+
*/
|
|
455
|
+
const hasUserConsentForProvider = (consent, provider) => {
|
|
456
|
+
if (!isRecord(consent)) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
let allowed = isBool(consent.all) ? consent.all : false;
|
|
460
|
+
if (provider in consent) {
|
|
461
|
+
const providerSpecific = consent[provider];
|
|
462
|
+
if (isBool(providerSpecific)) {
|
|
463
|
+
allowed = providerSpecific;
|
|
464
|
+
}
|
|
465
|
+
else if (isRecord(providerSpecific)) {
|
|
466
|
+
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return allowed;
|
|
470
|
+
};
|
|
477
471
|
/**
|
|
478
472
|
* This function validates provider allowance for a given provider and tag name.
|
|
479
473
|
* It should not be used to validate `UserConsent`.
|
|
@@ -673,6 +667,18 @@ const hasAllowedManifestTags = (tags, consent, providersConfig) => {
|
|
|
673
667
|
return false;
|
|
674
668
|
};
|
|
675
669
|
|
|
670
|
+
const handleGetData = (keys, callback) => {
|
|
671
|
+
if (!keys || keys.length === 0) {
|
|
672
|
+
error('Provide keys for get data API.');
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
getRequest(getGetDataURL(keys))
|
|
676
|
+
.then((result) => {
|
|
677
|
+
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
678
|
+
})
|
|
679
|
+
.catch(error);
|
|
680
|
+
};
|
|
681
|
+
|
|
676
682
|
const handleData = (data, providers, options) => {
|
|
677
683
|
if (!data || Object.keys(data).length === 0) {
|
|
678
684
|
error('Provide data for data API.');
|
|
@@ -711,7 +717,72 @@ const handleData = (data, providers, options) => {
|
|
|
711
717
|
postRequest(getDataURL(), { data, providers }, options).catch(error);
|
|
712
718
|
};
|
|
713
719
|
|
|
720
|
+
let memoryConsent;
|
|
721
|
+
const saveConsent = (consent) => {
|
|
722
|
+
setConsent(consent);
|
|
723
|
+
savePerKey('local', tagStorage, consent, consentKey);
|
|
724
|
+
};
|
|
725
|
+
const handleConsent = (consent, options) => {
|
|
726
|
+
const payload = {
|
|
727
|
+
consentString: consent,
|
|
728
|
+
};
|
|
729
|
+
saveConsent(consent);
|
|
730
|
+
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
731
|
+
postRequest(getConsentURL(), payload).catch(error);
|
|
732
|
+
}
|
|
733
|
+
const userId = handleGetUserId();
|
|
734
|
+
const providerPackages = getProvidersPackage();
|
|
735
|
+
const executionContext = new Map();
|
|
736
|
+
/* Calling Init for all provider instances based on consent check */
|
|
737
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
738
|
+
if (!pkg || !pkg.name || !pkg.init) {
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
const variables = getProviderVariables(pkg.name);
|
|
742
|
+
const providerVariables = Object.entries(variables);
|
|
743
|
+
for (const [tagName, variablesSet] of providerVariables) {
|
|
744
|
+
const hasConsent = hasUserConsent(consent, pkg.name, tagName);
|
|
745
|
+
if (!hasConsent) {
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
pkg.init({
|
|
749
|
+
userId,
|
|
750
|
+
manifest: {
|
|
751
|
+
tagName,
|
|
752
|
+
variables: variablesSet,
|
|
753
|
+
package: pkg.name,
|
|
754
|
+
},
|
|
755
|
+
sendTag,
|
|
756
|
+
sendEdgeData: handleData,
|
|
757
|
+
getEdgeData: handleGetData,
|
|
758
|
+
keyName: `${keyPrefix}Store`,
|
|
759
|
+
executionContext,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/* Calling Consent for all providers, not on instance level */
|
|
764
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
765
|
+
if (!pkg || !pkg.name || !pkg.consent) {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
/* Returns True if any one instance of given provider has consent */
|
|
769
|
+
const hasConsent = hasUserConsentForProvider(consent, pkg.name);
|
|
770
|
+
pkg.consent({ hasConsent });
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
const setConsent = (newConsent) => {
|
|
774
|
+
memoryConsent = newConsent;
|
|
775
|
+
};
|
|
776
|
+
const getConsent$1 = () => {
|
|
777
|
+
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
778
|
+
if (storageConsent) {
|
|
779
|
+
return storageConsent;
|
|
780
|
+
}
|
|
781
|
+
return memoryConsent;
|
|
782
|
+
};
|
|
783
|
+
|
|
714
784
|
const cacheKey = `${keyPrefix}Cache`;
|
|
785
|
+
const identity = (v) => v;
|
|
715
786
|
const saveDataToEdge = (key, value, provider) => {
|
|
716
787
|
if (!value) {
|
|
717
788
|
return;
|
|
@@ -727,7 +798,7 @@ const saveDataToEdge = (key, value, provider) => {
|
|
|
727
798
|
}
|
|
728
799
|
handleData({ [`${provider}::${key}`]: value });
|
|
729
800
|
};
|
|
730
|
-
const handleCaptureQuery = (provider, key, persistType) => {
|
|
801
|
+
const handleCaptureQuery = (provider, key, persistType, map) => {
|
|
731
802
|
try {
|
|
732
803
|
if (!window) {
|
|
733
804
|
return;
|
|
@@ -740,7 +811,7 @@ const handleCaptureQuery = (provider, key, persistType) => {
|
|
|
740
811
|
if (!params || !params.get(key)) {
|
|
741
812
|
return;
|
|
742
813
|
}
|
|
743
|
-
const data = params.get(key);
|
|
814
|
+
const data = (map !== null && map !== void 0 ? map : identity)(params.get(key));
|
|
744
815
|
if (!data) {
|
|
745
816
|
return;
|
|
746
817
|
}
|
|
@@ -765,20 +836,20 @@ const saveToCache = (persistType, provider, key, value) => {
|
|
|
765
836
|
}
|
|
766
837
|
saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
|
|
767
838
|
};
|
|
768
|
-
const handleCaptureStorage = (provider, key, persistType, location) => {
|
|
839
|
+
const handleCaptureStorage = (provider, key, persistType, location, map) => {
|
|
769
840
|
let data;
|
|
770
841
|
try {
|
|
771
842
|
switch (location) {
|
|
772
843
|
case 'cookie': {
|
|
773
|
-
data = getCookieValue(key);
|
|
844
|
+
data = (map !== null && map !== void 0 ? map : identity)(getCookieValue(key));
|
|
774
845
|
break;
|
|
775
846
|
}
|
|
776
847
|
case 'local': {
|
|
777
|
-
data = localStorage.getItem(key);
|
|
848
|
+
data = (map !== null && map !== void 0 ? map : identity)(localStorage.getItem(key));
|
|
778
849
|
break;
|
|
779
850
|
}
|
|
780
851
|
case 'session': {
|
|
781
|
-
data = sessionStorage.getItem(key);
|
|
852
|
+
data = (map !== null && map !== void 0 ? map : identity)(sessionStorage.getItem(key));
|
|
782
853
|
}
|
|
783
854
|
}
|
|
784
855
|
}
|
|
@@ -797,51 +868,42 @@ const handleCaptureStorage = (provider, key, persistType, location) => {
|
|
|
797
868
|
}
|
|
798
869
|
saveDataPerKey(persistType, provider, data, key);
|
|
799
870
|
};
|
|
800
|
-
const handleCapture = (provider, params) => {
|
|
871
|
+
const handleCapture = (provider, params, capture) => {
|
|
801
872
|
params.forEach((param) => {
|
|
802
873
|
switch (param.type) {
|
|
803
874
|
case 'query': {
|
|
804
|
-
handleCaptureQuery(provider, param.key, param.persist);
|
|
875
|
+
handleCaptureQuery(provider, param.key, param.persist, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
|
|
805
876
|
break;
|
|
806
877
|
}
|
|
807
878
|
case 'storage': {
|
|
808
|
-
handleCaptureStorage(provider, param.key, param.persist, param.location);
|
|
879
|
+
handleCaptureStorage(provider, param.key, param.persist, param.location, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
|
|
809
880
|
break;
|
|
810
881
|
}
|
|
811
882
|
}
|
|
812
883
|
});
|
|
813
884
|
};
|
|
814
885
|
|
|
815
|
-
const
|
|
816
|
-
if (!keys || keys.length === 0) {
|
|
817
|
-
error('Provide keys for get data API.');
|
|
818
|
-
return;
|
|
819
|
-
}
|
|
820
|
-
getRequest(getGetDataURL(keys))
|
|
821
|
-
.then((result) => {
|
|
822
|
-
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
823
|
-
})
|
|
824
|
-
.catch(error);
|
|
825
|
-
};
|
|
826
|
-
|
|
827
|
-
const handleManifest = (manifest) => {
|
|
886
|
+
const handleManifest = (manifest, consent) => {
|
|
828
887
|
const providerPackages = getProvidersPackage();
|
|
829
888
|
const userId = handleGetUserId();
|
|
889
|
+
const executionContext = new Map();
|
|
830
890
|
manifest.forEach((provider) => {
|
|
831
891
|
addConfiguredTag(provider.package, provider.tagName);
|
|
832
892
|
addProviderVariable(provider.package, provider.variables, provider.tagName);
|
|
893
|
+
const pkg = providerPackages[provider.package];
|
|
833
894
|
if (provider.rules) {
|
|
834
895
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
835
896
|
switch (name) {
|
|
836
897
|
case 'capture': {
|
|
837
|
-
handleCapture(provider.package, recipe);
|
|
898
|
+
handleCapture(provider.package, recipe, pkg === null || pkg === void 0 ? void 0 : pkg.capture);
|
|
838
899
|
return;
|
|
839
900
|
}
|
|
840
901
|
}
|
|
841
902
|
});
|
|
842
903
|
}
|
|
843
|
-
|
|
844
|
-
|
|
904
|
+
/* this defines if the consent is given for a specific instance of a provider */
|
|
905
|
+
const hasConsent = hasUserConsent(consent, pkg.name, provider.tagName);
|
|
906
|
+
if (pkg && pkg.name && pkg.init && hasConsent) {
|
|
845
907
|
pkg.init({
|
|
846
908
|
userId,
|
|
847
909
|
manifest: provider,
|
|
@@ -849,6 +911,7 @@ const handleManifest = (manifest) => {
|
|
|
849
911
|
sendEdgeData: handleData,
|
|
850
912
|
getEdgeData: handleGetData,
|
|
851
913
|
keyName: `${keyPrefix}Store`,
|
|
914
|
+
executionContext,
|
|
852
915
|
});
|
|
853
916
|
}
|
|
854
917
|
});
|
|
@@ -886,7 +949,7 @@ const handleInit = (preferences) => {
|
|
|
886
949
|
if (result.consent && !consent) {
|
|
887
950
|
saveConsent(result.consent);
|
|
888
951
|
}
|
|
889
|
-
handleManifest(result.result);
|
|
952
|
+
handleManifest(result.result, consent || result.consent);
|
|
890
953
|
})
|
|
891
954
|
.catch(error);
|
|
892
955
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,64 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type
|
|
15
|
-
eventName: string
|
|
16
|
-
eventId: string
|
|
17
|
-
data: Data
|
|
18
|
-
providerData?: Partial<Record<Library, Record<string, Data>>>
|
|
19
|
-
providers?: Possibly<ProvidersConfig>
|
|
20
|
-
options?: EventOptions
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type ManifestRule = {
|
|
24
|
-
type: string
|
|
25
|
-
key: string
|
|
26
|
-
persist: PersistType
|
|
27
|
-
location?: string
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type Manifest = {
|
|
31
|
-
package: Library
|
|
32
|
-
tagName: string
|
|
33
|
-
variables?: Record<string, string>
|
|
34
|
-
rules: Record<string, ManifestRule[]>
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type InitParams = {
|
|
38
|
-
userId: string
|
|
39
|
-
manifest: Manifest
|
|
40
|
-
sendTag: (params: SendTag) => void
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type TagParams = {
|
|
44
|
-
userId: string
|
|
45
|
-
eventId: string
|
|
46
|
-
eventName: string
|
|
47
|
-
data: Data
|
|
48
|
-
manifestVariables: Record<string, string>
|
|
49
|
-
sendTag: (params: SendTag) => void
|
|
50
|
-
executionContext: Map<string, unknown>
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
type ProviderInit = {
|
|
54
|
-
name?: Library
|
|
55
|
-
init?: (params: InitParams) => void
|
|
56
|
-
tag?: (params: TagParams) => unknown
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// end TODO
|
|
60
|
-
|
|
61
|
-
type UserKey =
|
|
1
|
+
import { ProvidersConfig } from '@blotoutio/cdn/types'
|
|
2
|
+
export {
|
|
3
|
+
InitParams,
|
|
4
|
+
TagParams,
|
|
5
|
+
ManifestRule,
|
|
6
|
+
Manifest,
|
|
7
|
+
ProviderInit,
|
|
8
|
+
SendTag,
|
|
9
|
+
Data,
|
|
10
|
+
EventOptions,
|
|
11
|
+
PersistType,
|
|
12
|
+
} from '@blotoutio/shared/utility-sdk'
|
|
13
|
+
|
|
14
|
+
export type UserKey =
|
|
62
15
|
| 'email'
|
|
63
16
|
| 'phone'
|
|
64
17
|
| 'firstName'
|
|
@@ -71,9 +24,9 @@ type UserKey =
|
|
|
71
24
|
| 'zip'
|
|
72
25
|
| 'address'
|
|
73
26
|
|
|
74
|
-
type Stub = { name: string; arguments: unknown[] }
|
|
27
|
+
export type Stub = { name: string; arguments: unknown[] }
|
|
75
28
|
|
|
76
|
-
type InitPreferences = {
|
|
29
|
+
export type InitPreferences = {
|
|
77
30
|
edgeURL: string
|
|
78
31
|
disableConsentCheck?: boolean
|
|
79
32
|
userId?: string
|
package/index.mjs
CHANGED
|
@@ -333,7 +333,7 @@ const getStandardPayload = (payload) => {
|
|
|
333
333
|
referrer: getReferrer(),
|
|
334
334
|
search: getSearch(),
|
|
335
335
|
locale: getLocale(),
|
|
336
|
-
sdkVersion: "0.
|
|
336
|
+
sdkVersion: "0.36.0" ,
|
|
337
337
|
...(payload || {}),
|
|
338
338
|
};
|
|
339
339
|
let storage = {};
|
|
@@ -420,31 +420,6 @@ const getKeysURL = () => {
|
|
|
420
420
|
return generateUrl(`/keys`);
|
|
421
421
|
};
|
|
422
422
|
|
|
423
|
-
let memoryConsent;
|
|
424
|
-
const saveConsent = (consent) => {
|
|
425
|
-
setConsent(consent);
|
|
426
|
-
savePerKey('local', tagStorage, consent, consentKey);
|
|
427
|
-
};
|
|
428
|
-
const handleConsent = (consent, options) => {
|
|
429
|
-
const payload = {
|
|
430
|
-
consentString: consent,
|
|
431
|
-
};
|
|
432
|
-
saveConsent(consent);
|
|
433
|
-
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
434
|
-
postRequest(getConsentURL(), payload).catch(error);
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
const setConsent = (newConsent) => {
|
|
438
|
-
memoryConsent = newConsent;
|
|
439
|
-
};
|
|
440
|
-
const getConsent$1 = () => {
|
|
441
|
-
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
442
|
-
if (storageConsent) {
|
|
443
|
-
return storageConsent;
|
|
444
|
-
}
|
|
445
|
-
return memoryConsent;
|
|
446
|
-
};
|
|
447
|
-
|
|
448
423
|
const isBool = (v) => typeof v == 'boolean';
|
|
449
424
|
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
|
|
450
425
|
/**
|
|
@@ -472,6 +447,25 @@ const hasUserConsent = (consent, provider, tagName) => {
|
|
|
472
447
|
}
|
|
473
448
|
return allowed;
|
|
474
449
|
};
|
|
450
|
+
/**
|
|
451
|
+
* This function validates user consent for a given provider type, not based on tagName.
|
|
452
|
+
*/
|
|
453
|
+
const hasUserConsentForProvider = (consent, provider) => {
|
|
454
|
+
if (!isRecord(consent)) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
let allowed = isBool(consent.all) ? consent.all : false;
|
|
458
|
+
if (provider in consent) {
|
|
459
|
+
const providerSpecific = consent[provider];
|
|
460
|
+
if (isBool(providerSpecific)) {
|
|
461
|
+
allowed = providerSpecific;
|
|
462
|
+
}
|
|
463
|
+
else if (isRecord(providerSpecific)) {
|
|
464
|
+
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return allowed;
|
|
468
|
+
};
|
|
475
469
|
/**
|
|
476
470
|
* This function validates provider allowance for a given provider and tag name.
|
|
477
471
|
* It should not be used to validate `UserConsent`.
|
|
@@ -671,6 +665,18 @@ const hasAllowedManifestTags = (tags, consent, providersConfig) => {
|
|
|
671
665
|
return false;
|
|
672
666
|
};
|
|
673
667
|
|
|
668
|
+
const handleGetData = (keys, callback) => {
|
|
669
|
+
if (!keys || keys.length === 0) {
|
|
670
|
+
error('Provide keys for get data API.');
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
getRequest(getGetDataURL(keys))
|
|
674
|
+
.then((result) => {
|
|
675
|
+
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
676
|
+
})
|
|
677
|
+
.catch(error);
|
|
678
|
+
};
|
|
679
|
+
|
|
674
680
|
const handleData = (data, providers, options) => {
|
|
675
681
|
if (!data || Object.keys(data).length === 0) {
|
|
676
682
|
error('Provide data for data API.');
|
|
@@ -709,7 +715,72 @@ const handleData = (data, providers, options) => {
|
|
|
709
715
|
postRequest(getDataURL(), { data, providers }, options).catch(error);
|
|
710
716
|
};
|
|
711
717
|
|
|
718
|
+
let memoryConsent;
|
|
719
|
+
const saveConsent = (consent) => {
|
|
720
|
+
setConsent(consent);
|
|
721
|
+
savePerKey('local', tagStorage, consent, consentKey);
|
|
722
|
+
};
|
|
723
|
+
const handleConsent = (consent, options) => {
|
|
724
|
+
const payload = {
|
|
725
|
+
consentString: consent,
|
|
726
|
+
};
|
|
727
|
+
saveConsent(consent);
|
|
728
|
+
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
729
|
+
postRequest(getConsentURL(), payload).catch(error);
|
|
730
|
+
}
|
|
731
|
+
const userId = handleGetUserId();
|
|
732
|
+
const providerPackages = getProvidersPackage();
|
|
733
|
+
const executionContext = new Map();
|
|
734
|
+
/* Calling Init for all provider instances based on consent check */
|
|
735
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
736
|
+
if (!pkg || !pkg.name || !pkg.init) {
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
const variables = getProviderVariables(pkg.name);
|
|
740
|
+
const providerVariables = Object.entries(variables);
|
|
741
|
+
for (const [tagName, variablesSet] of providerVariables) {
|
|
742
|
+
const hasConsent = hasUserConsent(consent, pkg.name, tagName);
|
|
743
|
+
if (!hasConsent) {
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
pkg.init({
|
|
747
|
+
userId,
|
|
748
|
+
manifest: {
|
|
749
|
+
tagName,
|
|
750
|
+
variables: variablesSet,
|
|
751
|
+
package: pkg.name,
|
|
752
|
+
},
|
|
753
|
+
sendTag,
|
|
754
|
+
sendEdgeData: handleData,
|
|
755
|
+
getEdgeData: handleGetData,
|
|
756
|
+
keyName: `${keyPrefix}Store`,
|
|
757
|
+
executionContext,
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
/* Calling Consent for all providers, not on instance level */
|
|
762
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
763
|
+
if (!pkg || !pkg.name || !pkg.consent) {
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
/* Returns True if any one instance of given provider has consent */
|
|
767
|
+
const hasConsent = hasUserConsentForProvider(consent, pkg.name);
|
|
768
|
+
pkg.consent({ hasConsent });
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
const setConsent = (newConsent) => {
|
|
772
|
+
memoryConsent = newConsent;
|
|
773
|
+
};
|
|
774
|
+
const getConsent$1 = () => {
|
|
775
|
+
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
776
|
+
if (storageConsent) {
|
|
777
|
+
return storageConsent;
|
|
778
|
+
}
|
|
779
|
+
return memoryConsent;
|
|
780
|
+
};
|
|
781
|
+
|
|
712
782
|
const cacheKey = `${keyPrefix}Cache`;
|
|
783
|
+
const identity = (v) => v;
|
|
713
784
|
const saveDataToEdge = (key, value, provider) => {
|
|
714
785
|
if (!value) {
|
|
715
786
|
return;
|
|
@@ -725,7 +796,7 @@ const saveDataToEdge = (key, value, provider) => {
|
|
|
725
796
|
}
|
|
726
797
|
handleData({ [`${provider}::${key}`]: value });
|
|
727
798
|
};
|
|
728
|
-
const handleCaptureQuery = (provider, key, persistType) => {
|
|
799
|
+
const handleCaptureQuery = (provider, key, persistType, map) => {
|
|
729
800
|
try {
|
|
730
801
|
if (!window) {
|
|
731
802
|
return;
|
|
@@ -738,7 +809,7 @@ const handleCaptureQuery = (provider, key, persistType) => {
|
|
|
738
809
|
if (!params || !params.get(key)) {
|
|
739
810
|
return;
|
|
740
811
|
}
|
|
741
|
-
const data = params.get(key);
|
|
812
|
+
const data = (map !== null && map !== void 0 ? map : identity)(params.get(key));
|
|
742
813
|
if (!data) {
|
|
743
814
|
return;
|
|
744
815
|
}
|
|
@@ -763,20 +834,20 @@ const saveToCache = (persistType, provider, key, value) => {
|
|
|
763
834
|
}
|
|
764
835
|
saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
|
|
765
836
|
};
|
|
766
|
-
const handleCaptureStorage = (provider, key, persistType, location) => {
|
|
837
|
+
const handleCaptureStorage = (provider, key, persistType, location, map) => {
|
|
767
838
|
let data;
|
|
768
839
|
try {
|
|
769
840
|
switch (location) {
|
|
770
841
|
case 'cookie': {
|
|
771
|
-
data = getCookieValue(key);
|
|
842
|
+
data = (map !== null && map !== void 0 ? map : identity)(getCookieValue(key));
|
|
772
843
|
break;
|
|
773
844
|
}
|
|
774
845
|
case 'local': {
|
|
775
|
-
data = localStorage.getItem(key);
|
|
846
|
+
data = (map !== null && map !== void 0 ? map : identity)(localStorage.getItem(key));
|
|
776
847
|
break;
|
|
777
848
|
}
|
|
778
849
|
case 'session': {
|
|
779
|
-
data = sessionStorage.getItem(key);
|
|
850
|
+
data = (map !== null && map !== void 0 ? map : identity)(sessionStorage.getItem(key));
|
|
780
851
|
}
|
|
781
852
|
}
|
|
782
853
|
}
|
|
@@ -795,51 +866,42 @@ const handleCaptureStorage = (provider, key, persistType, location) => {
|
|
|
795
866
|
}
|
|
796
867
|
saveDataPerKey(persistType, provider, data, key);
|
|
797
868
|
};
|
|
798
|
-
const handleCapture = (provider, params) => {
|
|
869
|
+
const handleCapture = (provider, params, capture) => {
|
|
799
870
|
params.forEach((param) => {
|
|
800
871
|
switch (param.type) {
|
|
801
872
|
case 'query': {
|
|
802
|
-
handleCaptureQuery(provider, param.key, param.persist);
|
|
873
|
+
handleCaptureQuery(provider, param.key, param.persist, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
|
|
803
874
|
break;
|
|
804
875
|
}
|
|
805
876
|
case 'storage': {
|
|
806
|
-
handleCaptureStorage(provider, param.key, param.persist, param.location);
|
|
877
|
+
handleCaptureStorage(provider, param.key, param.persist, param.location, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
|
|
807
878
|
break;
|
|
808
879
|
}
|
|
809
880
|
}
|
|
810
881
|
});
|
|
811
882
|
};
|
|
812
883
|
|
|
813
|
-
const
|
|
814
|
-
if (!keys || keys.length === 0) {
|
|
815
|
-
error('Provide keys for get data API.');
|
|
816
|
-
return;
|
|
817
|
-
}
|
|
818
|
-
getRequest(getGetDataURL(keys))
|
|
819
|
-
.then((result) => {
|
|
820
|
-
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
821
|
-
})
|
|
822
|
-
.catch(error);
|
|
823
|
-
};
|
|
824
|
-
|
|
825
|
-
const handleManifest = (manifest) => {
|
|
884
|
+
const handleManifest = (manifest, consent) => {
|
|
826
885
|
const providerPackages = getProvidersPackage();
|
|
827
886
|
const userId = handleGetUserId();
|
|
887
|
+
const executionContext = new Map();
|
|
828
888
|
manifest.forEach((provider) => {
|
|
829
889
|
addConfiguredTag(provider.package, provider.tagName);
|
|
830
890
|
addProviderVariable(provider.package, provider.variables, provider.tagName);
|
|
891
|
+
const pkg = providerPackages[provider.package];
|
|
831
892
|
if (provider.rules) {
|
|
832
893
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
833
894
|
switch (name) {
|
|
834
895
|
case 'capture': {
|
|
835
|
-
handleCapture(provider.package, recipe);
|
|
896
|
+
handleCapture(provider.package, recipe, pkg === null || pkg === void 0 ? void 0 : pkg.capture);
|
|
836
897
|
return;
|
|
837
898
|
}
|
|
838
899
|
}
|
|
839
900
|
});
|
|
840
901
|
}
|
|
841
|
-
|
|
842
|
-
|
|
902
|
+
/* this defines if the consent is given for a specific instance of a provider */
|
|
903
|
+
const hasConsent = hasUserConsent(consent, pkg.name, provider.tagName);
|
|
904
|
+
if (pkg && pkg.name && pkg.init && hasConsent) {
|
|
843
905
|
pkg.init({
|
|
844
906
|
userId,
|
|
845
907
|
manifest: provider,
|
|
@@ -847,6 +909,7 @@ const handleManifest = (manifest) => {
|
|
|
847
909
|
sendEdgeData: handleData,
|
|
848
910
|
getEdgeData: handleGetData,
|
|
849
911
|
keyName: `${keyPrefix}Store`,
|
|
912
|
+
executionContext,
|
|
850
913
|
});
|
|
851
914
|
}
|
|
852
915
|
});
|
|
@@ -884,7 +947,7 @@ const handleInit = (preferences) => {
|
|
|
884
947
|
if (result.consent && !consent) {
|
|
885
948
|
saveConsent(result.consent);
|
|
886
949
|
}
|
|
887
|
-
handleManifest(result.result);
|
|
950
|
+
handleManifest(result.result, consent || result.consent);
|
|
888
951
|
})
|
|
889
952
|
.catch(error);
|
|
890
953
|
};
|