@blotoutio/edgetag-sdk-browser 0.52.1 → 0.53.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 +73 -74
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -142,11 +142,12 @@
|
|
|
142
142
|
destination,
|
|
143
143
|
initialized: false,
|
|
144
144
|
stubs: [],
|
|
145
|
+
browserPackages: [],
|
|
145
146
|
channels: new Map(),
|
|
146
147
|
...options,
|
|
147
148
|
};
|
|
148
149
|
};
|
|
149
|
-
const setSetting = (
|
|
150
|
+
const setSetting = (destination, options) => {
|
|
150
151
|
if (!edgeTagSettings) {
|
|
151
152
|
return;
|
|
152
153
|
}
|
|
@@ -173,7 +174,7 @@
|
|
|
173
174
|
};
|
|
174
175
|
const addChannel = (destination, pkg, tagName) => upsert(getSetting(destination, 'channels'), pkg, (names) => names.add(tagName), () => new Set());
|
|
175
176
|
const getProviderVariables = (destination, packageId) => {
|
|
176
|
-
const setting = getSetting(destination, '
|
|
177
|
+
const setting = getSetting(destination, 'manifest');
|
|
177
178
|
if (!setting) {
|
|
178
179
|
return [];
|
|
179
180
|
}
|
|
@@ -548,7 +549,7 @@
|
|
|
548
549
|
referrer: getReferrer(destination),
|
|
549
550
|
search: getSearch(destination),
|
|
550
551
|
locale: getLocale(),
|
|
551
|
-
sdkVersion: "0.
|
|
552
|
+
sdkVersion: "0.53.0" ,
|
|
552
553
|
...(payload || {}),
|
|
553
554
|
};
|
|
554
555
|
let storage = {};
|
|
@@ -628,53 +629,6 @@
|
|
|
628
629
|
return generateUrl(destination, `/keys`);
|
|
629
630
|
};
|
|
630
631
|
|
|
631
|
-
const providersPackages = {};
|
|
632
|
-
const setPreferences = (preferences) => {
|
|
633
|
-
var _a;
|
|
634
|
-
if (!preferences) {
|
|
635
|
-
return false;
|
|
636
|
-
}
|
|
637
|
-
if (!preferences.edgeURL) {
|
|
638
|
-
error('Please provide URL for EdgeTag');
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
(_a = preferences.providers) === null || _a === void 0 ? void 0 : _a.forEach((provider) => {
|
|
642
|
-
if (!provider.name) {
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
providersPackages[provider.name] = provider;
|
|
646
|
-
});
|
|
647
|
-
try {
|
|
648
|
-
if (window && Array.isArray(window.edgetagProviders)) {
|
|
649
|
-
window.edgetagProviders.forEach((provider) => {
|
|
650
|
-
if (!provider.name) {
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
providersPackages[provider.name] = provider;
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
catch {
|
|
658
|
-
// do nothing
|
|
659
|
-
}
|
|
660
|
-
initSettings(preferences.edgeURL, {
|
|
661
|
-
disableConsent: !!preferences.disableConsentCheck,
|
|
662
|
-
});
|
|
663
|
-
return true;
|
|
664
|
-
};
|
|
665
|
-
const getProvidersPackage = (destination) => {
|
|
666
|
-
const packages = getSetting(destination, 'packages');
|
|
667
|
-
const providers = [];
|
|
668
|
-
packages === null || packages === void 0 ? void 0 : packages.forEach((pkg) => {
|
|
669
|
-
const provider = providersPackages[pkg.package];
|
|
670
|
-
if (!provider) {
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
providers.push(provider);
|
|
674
|
-
});
|
|
675
|
-
return providers;
|
|
676
|
-
};
|
|
677
|
-
|
|
678
632
|
const getConsent$1 = (destination) => {
|
|
679
633
|
const storageConsent = getDataPerKey(destination, 'local', tagStorage, consentKey);
|
|
680
634
|
if (storageConsent) {
|
|
@@ -689,9 +643,9 @@
|
|
|
689
643
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
690
644
|
// @ts-ignore
|
|
691
645
|
stubs.forEach((stub) => api$1[stub.name](...(stub.arguments || [])));
|
|
692
|
-
setSetting({
|
|
646
|
+
setSetting(destination, {
|
|
693
647
|
stubs: [],
|
|
694
|
-
}
|
|
648
|
+
});
|
|
695
649
|
}
|
|
696
650
|
catch (e) {
|
|
697
651
|
error(e);
|
|
@@ -699,9 +653,9 @@
|
|
|
699
653
|
};
|
|
700
654
|
const addStub = (destination, stub) => {
|
|
701
655
|
const otherStubs = getSetting(destination, 'stubs') || [];
|
|
702
|
-
setSetting({
|
|
656
|
+
setSetting(destination, {
|
|
703
657
|
stubs: [...otherStubs, stub],
|
|
704
|
-
}
|
|
658
|
+
});
|
|
705
659
|
};
|
|
706
660
|
|
|
707
661
|
const sendTag = (destination, { eventName, eventId, data, providerData, providers, options }) => {
|
|
@@ -729,7 +683,7 @@
|
|
|
729
683
|
if (!eventId) {
|
|
730
684
|
eventId = generateEventId(eventName);
|
|
731
685
|
}
|
|
732
|
-
const providerPackages =
|
|
686
|
+
const providerPackages = getSetting(destination, 'browserPackages');
|
|
733
687
|
const configuredTags = getSetting(destination, 'channels');
|
|
734
688
|
const userId = getUserId$1(destination);
|
|
735
689
|
const providerData = {};
|
|
@@ -826,7 +780,7 @@
|
|
|
826
780
|
|
|
827
781
|
const processData = (destination, data, providers, options) => {
|
|
828
782
|
saveKV(destination, data);
|
|
829
|
-
const providerPackages =
|
|
783
|
+
const providerPackages = getSetting(destination, 'browserPackages');
|
|
830
784
|
const configuredTags = getSetting(destination, 'channels');
|
|
831
785
|
const userId = getUserId$1(destination);
|
|
832
786
|
const consent = getConsent$1(destination);
|
|
@@ -881,9 +835,9 @@
|
|
|
881
835
|
});
|
|
882
836
|
};
|
|
883
837
|
const saveConsent = (destination, consent) => {
|
|
884
|
-
setSetting({
|
|
838
|
+
setSetting(destination, {
|
|
885
839
|
consent,
|
|
886
|
-
}
|
|
840
|
+
});
|
|
887
841
|
savePerKey(destination, 'local', tagStorage, consent, consentKey);
|
|
888
842
|
};
|
|
889
843
|
const processConsent = (destination, consent, localSave) => {
|
|
@@ -899,7 +853,7 @@
|
|
|
899
853
|
postRequest(getConsentURL(destination), payload).catch(error);
|
|
900
854
|
}
|
|
901
855
|
const userId = getUserId$1(destination);
|
|
902
|
-
const providerPackages =
|
|
856
|
+
const providerPackages = getSetting(destination, 'browserPackages');
|
|
903
857
|
const executionContext = new Map();
|
|
904
858
|
/* Calling Init for all provider instances based on consent check */
|
|
905
859
|
for (const pkg of providerPackages) {
|
|
@@ -953,6 +907,41 @@
|
|
|
953
907
|
}
|
|
954
908
|
};
|
|
955
909
|
|
|
910
|
+
const setPreferences = (preferences) => {
|
|
911
|
+
var _a;
|
|
912
|
+
if (!preferences) {
|
|
913
|
+
return null;
|
|
914
|
+
}
|
|
915
|
+
if (!preferences.edgeURL) {
|
|
916
|
+
error('Please provide URL for EdgeTag');
|
|
917
|
+
return null;
|
|
918
|
+
}
|
|
919
|
+
const providersPackages = {};
|
|
920
|
+
(_a = preferences.providers) === null || _a === void 0 ? void 0 : _a.forEach((provider) => {
|
|
921
|
+
if (!provider.name) {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
providersPackages[provider.name] = provider;
|
|
925
|
+
});
|
|
926
|
+
try {
|
|
927
|
+
if (window && Array.isArray(window.edgetagProviders)) {
|
|
928
|
+
window.edgetagProviders.forEach((provider) => {
|
|
929
|
+
if (!provider.name) {
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
providersPackages[provider.name] = provider;
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
catch {
|
|
937
|
+
// do nothing
|
|
938
|
+
}
|
|
939
|
+
initSettings(preferences.edgeURL, {
|
|
940
|
+
disableConsent: !!preferences.disableConsentCheck,
|
|
941
|
+
});
|
|
942
|
+
return providersPackages;
|
|
943
|
+
};
|
|
944
|
+
|
|
956
945
|
const cacheKey = `${keyPrefix}Cache`;
|
|
957
946
|
const identity = (v) => v;
|
|
958
947
|
const saveDataToEdge = (destination, key, value, provider) => {
|
|
@@ -1061,7 +1050,7 @@
|
|
|
1061
1050
|
};
|
|
1062
1051
|
|
|
1063
1052
|
const handleManifest = (destination, response) => {
|
|
1064
|
-
const providerPackages =
|
|
1053
|
+
const providerPackages = getSetting(destination, 'browserPackages');
|
|
1065
1054
|
const userId = getUserId$1(destination);
|
|
1066
1055
|
const executionContext = new Map();
|
|
1067
1056
|
const manifest = response.result;
|
|
@@ -1097,21 +1086,21 @@
|
|
|
1097
1086
|
}
|
|
1098
1087
|
}
|
|
1099
1088
|
});
|
|
1100
|
-
setSetting({
|
|
1089
|
+
setSetting(destination, {
|
|
1101
1090
|
initialized: true,
|
|
1102
|
-
}
|
|
1091
|
+
});
|
|
1103
1092
|
processStubs(destination);
|
|
1104
1093
|
};
|
|
1105
1094
|
|
|
1106
1095
|
const handleInit = (preferences) => {
|
|
1107
|
-
const
|
|
1108
|
-
if (!
|
|
1096
|
+
const browserPackages = setPreferences(preferences);
|
|
1097
|
+
if (!browserPackages) {
|
|
1109
1098
|
return;
|
|
1110
1099
|
}
|
|
1111
1100
|
if (preferences.afterManifestEvents) {
|
|
1112
|
-
setSetting({
|
|
1101
|
+
setSetting(preferences.edgeURL, {
|
|
1113
1102
|
stubs: preferences.afterManifestEvents,
|
|
1114
|
-
}
|
|
1103
|
+
});
|
|
1115
1104
|
}
|
|
1116
1105
|
const url = new URL(getInitURL(preferences.edgeURL));
|
|
1117
1106
|
if (preferences.disableConsentCheck) {
|
|
@@ -1119,21 +1108,31 @@
|
|
|
1119
1108
|
saveConsent(preferences.edgeURL, { all: true });
|
|
1120
1109
|
}
|
|
1121
1110
|
if (preferences.userId) {
|
|
1122
|
-
setSetting({ userId: preferences.userId }
|
|
1111
|
+
setSetting(preferences.edgeURL, { userId: preferences.userId });
|
|
1123
1112
|
url.searchParams.set('userId', preferences.userId);
|
|
1124
1113
|
}
|
|
1125
1114
|
getRequest(url.href)
|
|
1126
1115
|
.then((result) => {
|
|
1116
|
+
var _a;
|
|
1127
1117
|
if (!result) {
|
|
1128
1118
|
error('Initialization failed');
|
|
1129
1119
|
return;
|
|
1130
1120
|
}
|
|
1131
|
-
|
|
1121
|
+
const providers = {};
|
|
1122
|
+
(_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
|
|
1123
|
+
const provider = browserPackages[pkg.package];
|
|
1124
|
+
if (!provider) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
providers[pkg.package] = provider;
|
|
1128
|
+
});
|
|
1129
|
+
setSetting(preferences.edgeURL, {
|
|
1132
1130
|
isNewUser: result.isNewUser,
|
|
1133
1131
|
consent: getConsent$1(preferences.edgeURL) || result.consent,
|
|
1134
1132
|
userId: result.userId,
|
|
1135
|
-
|
|
1136
|
-
|
|
1133
|
+
manifest: result.result,
|
|
1134
|
+
browserPackages: Object.values(providers),
|
|
1135
|
+
});
|
|
1137
1136
|
handleManifest(preferences.edgeURL, result);
|
|
1138
1137
|
try {
|
|
1139
1138
|
window.dispatchEvent(new CustomEvent('edgetag-initialized', {
|
|
@@ -1158,7 +1157,7 @@
|
|
|
1158
1157
|
saveKV(destination, {
|
|
1159
1158
|
[key]: value,
|
|
1160
1159
|
});
|
|
1161
|
-
const providerPackages =
|
|
1160
|
+
const providerPackages = getSetting(destination, 'browserPackages');
|
|
1162
1161
|
const configuredTags = getSetting(destination, 'channels');
|
|
1163
1162
|
const consent = getConsent$1(destination);
|
|
1164
1163
|
const userId = getUserId$1(destination);
|
|
@@ -1177,7 +1176,7 @@
|
|
|
1177
1176
|
continue;
|
|
1178
1177
|
}
|
|
1179
1178
|
if (!hasUserConsent(consent, pkg.name, variable.tagName)) {
|
|
1180
|
-
log(`User
|
|
1179
|
+
log(`User do not have consent for ${pkg.name} (${variable.tagName})`);
|
|
1181
1180
|
continue;
|
|
1182
1181
|
}
|
|
1183
1182
|
pkg.user({
|
|
@@ -1272,12 +1271,12 @@
|
|
|
1272
1271
|
|
|
1273
1272
|
const processConfig = (destination, config) => {
|
|
1274
1273
|
const existingConfig = getSetting(destination, 'config');
|
|
1275
|
-
setSetting({
|
|
1274
|
+
setSetting(destination, {
|
|
1276
1275
|
config: {
|
|
1277
1276
|
...existingConfig,
|
|
1278
1277
|
...config,
|
|
1279
1278
|
},
|
|
1280
|
-
}
|
|
1279
|
+
});
|
|
1281
1280
|
};
|
|
1282
1281
|
const handleConfig = (config, options) => {
|
|
1283
1282
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|