@kameleoon/javascript-sdk-core 5.17.2 → 5.18.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/CHANGELOG.md +15 -0
- package/dist/browser.d.ts +1 -1
- package/dist/cacheManager/cacheManager.d.ts +2 -2
- package/dist/clientConfiguration/clientConfiguration.d.ts +9 -9
- package/dist/clientSettings/clientSettings.d.ts +11 -8
- package/dist/index.d.ts +1 -1
- package/dist/javascript-sdk-core.browser.cjs.js +214 -180
- package/dist/javascript-sdk-core.browser.cjs.js.map +1 -1
- package/dist/javascript-sdk-core.browser.es.js +214 -180
- package/dist/javascript-sdk-core.browser.es.js.map +1 -1
- package/dist/javascript-sdk-core.cjs.js +214 -180
- package/dist/javascript-sdk-core.cjs.js.map +1 -1
- package/dist/javascript-sdk-core.es.js +214 -180
- package/dist/javascript-sdk-core.es.js.map +1 -1
- package/dist/kameleoonClient.d.ts +12 -10
- package/dist/kameleoonClientInterface.d.ts +18 -10
- package/dist/kameleoonData/browser.d.ts +2 -2
- package/dist/kameleoonData/conversion.d.ts +3 -3
- package/dist/kameleoonData/customData.d.ts +3 -3
- package/dist/kameleoonData/dataManager.d.ts +11 -4
- package/dist/kameleoonData/device.d.ts +1 -1
- package/dist/kameleoonData/geolocation.d.ts +5 -5
- package/dist/kameleoonData/index.d.ts +1 -1
- package/dist/kameleoonData/pageView.d.ts +3 -3
- package/dist/kameleoonData/targetedSegment.d.ts +1 -1
- package/dist/kameleoonData/types.d.ts +12 -0
- package/dist/kameleoonData/uniqueIdentifier.d.ts +1 -1
- package/dist/kameleoonData/userAgent.d.ts +1 -1
- package/dist/requester/types.d.ts +1 -0
- package/dist/tracking/tracker.d.ts +7 -7
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
|
@@ -3393,6 +3393,7 @@ class Parser {
|
|
|
3393
3393
|
}
|
|
3394
3394
|
}
|
|
3395
3395
|
|
|
3396
|
+
var _a;
|
|
3396
3397
|
class ClientSettings {
|
|
3397
3398
|
constructor(siteCode, configuration) {
|
|
3398
3399
|
KameleoonLogger.debug `CALL: new ClientSettings(siteCode: ${siteCode}, configuration: ${configuration})`;
|
|
@@ -3407,18 +3408,19 @@ class ClientSettings {
|
|
|
3407
3408
|
KameleoonLogger.debug `RETURN: new ClientSettings(siteCode: ${siteCode}, configuration: ${configuration})`;
|
|
3408
3409
|
}
|
|
3409
3410
|
getTrackingInterval(configuration) {
|
|
3411
|
+
const { MIN_TRACKING_INTERVAL_MS, MAX_TRACKING_INTERVAL_MS, DEFAULT_TRACKING_INTERVAL_MS, } = ClientSettings;
|
|
3410
3412
|
if (typeof (configuration === null || configuration === void 0 ? void 0 : configuration.trackingInterval) === 'number') {
|
|
3411
|
-
if (configuration.trackingInterval <
|
|
3412
|
-
KameleoonLogger.warning(
|
|
3413
|
-
return
|
|
3413
|
+
if (configuration.trackingInterval < MIN_TRACKING_INTERVAL_MS) {
|
|
3414
|
+
KameleoonLogger.warning(`Tracking interval must not be shorter than ${MIN_TRACKING_INTERVAL_MS} ms. Minimum possible interval was applied.`);
|
|
3415
|
+
return MIN_TRACKING_INTERVAL_MS;
|
|
3414
3416
|
}
|
|
3415
|
-
if (configuration.trackingInterval >
|
|
3416
|
-
KameleoonLogger.warning(
|
|
3417
|
-
return
|
|
3417
|
+
if (configuration.trackingInterval > MAX_TRACKING_INTERVAL_MS) {
|
|
3418
|
+
KameleoonLogger.warning(`Tracking interval must not be longer than ${MAX_TRACKING_INTERVAL_MS} ms. Maximum possible interval was applied.`);
|
|
3419
|
+
return MAX_TRACKING_INTERVAL_MS;
|
|
3418
3420
|
}
|
|
3419
3421
|
return configuration.trackingInterval;
|
|
3420
3422
|
}
|
|
3421
|
-
return
|
|
3423
|
+
return DEFAULT_TRACKING_INTERVAL_MS;
|
|
3422
3424
|
}
|
|
3423
3425
|
getEnvironment(configuration) {
|
|
3424
3426
|
if (configuration === null || configuration === void 0 ? void 0 : configuration.environment) {
|
|
@@ -3472,6 +3474,10 @@ class ClientSettings {
|
|
|
3472
3474
|
};
|
|
3473
3475
|
}
|
|
3474
3476
|
}
|
|
3477
|
+
_a = ClientSettings;
|
|
3478
|
+
ClientSettings.DEFAULT_TRACKING_INTERVAL_MS = 1000;
|
|
3479
|
+
ClientSettings.MIN_TRACKING_INTERVAL_MS = _a.DEFAULT_TRACKING_INTERVAL_MS;
|
|
3480
|
+
ClientSettings.MAX_TRACKING_INTERVAL_MS = 5000;
|
|
3475
3481
|
|
|
3476
3482
|
/**
|
|
3477
3483
|
* @class
|
|
@@ -5466,7 +5472,6 @@ class StorageCleanupManager {
|
|
|
5466
5472
|
break;
|
|
5467
5473
|
default:
|
|
5468
5474
|
// check if all cases are handled
|
|
5469
|
-
const exhaustiveCheck = storageKey;
|
|
5470
5475
|
KameleoonLogger.error `Unknown storage key: ${storageKey} for initCleanupInterval.`;
|
|
5471
5476
|
}
|
|
5472
5477
|
}
|
|
@@ -5761,7 +5766,7 @@ class DataManager {
|
|
|
5761
5766
|
return resultData;
|
|
5762
5767
|
}
|
|
5763
5768
|
storeTrackedData(data) {
|
|
5764
|
-
this.
|
|
5769
|
+
this.storeDataForVisitors(data, false);
|
|
5765
5770
|
const infoResult = this.infoStorage.read();
|
|
5766
5771
|
if (!infoResult.ok) {
|
|
5767
5772
|
return;
|
|
@@ -5795,30 +5800,31 @@ class DataManager {
|
|
|
5795
5800
|
}
|
|
5796
5801
|
this.infoStorage.write(infoResult.data);
|
|
5797
5802
|
}
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
}
|
|
5805
|
-
if (!infoResult.ok) {
|
|
5806
|
-
return infoResult;
|
|
5807
|
-
}
|
|
5808
|
-
const targetingData = result.data;
|
|
5809
|
-
const infoData = infoResult.data;
|
|
5810
|
-
if (typeof firstParameter === 'string') {
|
|
5803
|
+
/**
|
|
5804
|
+
* Store data for a single visitor
|
|
5805
|
+
*/
|
|
5806
|
+
storeData({ visitorCode, data, track, }) {
|
|
5807
|
+
KameleoonLogger.debug `CALL: DataManager.storeDataForVisitor(vc: ${visitorCode}, track: ${track}, data: ${data})`;
|
|
5808
|
+
const result = this.storeDataInternal((infoData, targetingData) => {
|
|
5811
5809
|
this.mutUpdateTargetingData({
|
|
5812
5810
|
infoData,
|
|
5813
5811
|
targetingData,
|
|
5814
|
-
visitorCode
|
|
5815
|
-
kameleoonData:
|
|
5812
|
+
visitorCode,
|
|
5813
|
+
kameleoonData: data,
|
|
5816
5814
|
extendTtl: true,
|
|
5815
|
+
track,
|
|
5817
5816
|
});
|
|
5818
|
-
}
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5817
|
+
});
|
|
5818
|
+
KameleoonLogger.debug `RETURN: DataManager.storeDataForVisitor(vc: ${visitorCode}, track: ${track}, data: ${data}) -> ${result}`;
|
|
5819
|
+
return result;
|
|
5820
|
+
}
|
|
5821
|
+
/**
|
|
5822
|
+
* Store data for multiple visitors
|
|
5823
|
+
*/
|
|
5824
|
+
storeDataForVisitors(data, extendTtl) {
|
|
5825
|
+
KameleoonLogger.debug `CALL: DataManager.storeDataForVisitors(data: ${data}, extendTtl: ${extendTtl})`;
|
|
5826
|
+
const result = this.storeDataInternal((infoData, targetingData) => {
|
|
5827
|
+
for (const [visitorCode, kameleoonData] of Object.entries(data)) {
|
|
5822
5828
|
this.mutUpdateTargetingData({
|
|
5823
5829
|
infoData,
|
|
5824
5830
|
targetingData,
|
|
@@ -5827,12 +5833,26 @@ class DataManager {
|
|
|
5827
5833
|
extendTtl,
|
|
5828
5834
|
});
|
|
5829
5835
|
}
|
|
5836
|
+
});
|
|
5837
|
+
KameleoonLogger.debug `RETURN: DataManager.storeDataForVisitors(data: ${data}, extendTtl: ${extendTtl}) -> ${result}`;
|
|
5838
|
+
return result;
|
|
5839
|
+
}
|
|
5840
|
+
// ========= Internal shared logic =========
|
|
5841
|
+
storeDataInternal(updater) {
|
|
5842
|
+
const dataResult = this.dataStorage.read();
|
|
5843
|
+
if (!dataResult.ok) {
|
|
5844
|
+
return dataResult;
|
|
5830
5845
|
}
|
|
5846
|
+
const infoResult = this.infoStorage.read();
|
|
5847
|
+
if (!infoResult.ok) {
|
|
5848
|
+
return infoResult;
|
|
5849
|
+
}
|
|
5850
|
+
const targetingData = dataResult.data;
|
|
5851
|
+
const infoData = infoResult.data;
|
|
5852
|
+
updater(infoData, targetingData);
|
|
5831
5853
|
this.cleanupData();
|
|
5832
|
-
this.infoStorage.write(
|
|
5833
|
-
|
|
5834
|
-
KameleoonLogger.debug `RETURN: DataManager.storeData(visitorCode: ${firstParameter}, data: ${secondParameter}) -> (writeResult: ${writeResult})`;
|
|
5835
|
-
return writeResult;
|
|
5854
|
+
this.infoStorage.write(infoData);
|
|
5855
|
+
return this.dataStorage.write(targetingData);
|
|
5836
5856
|
}
|
|
5837
5857
|
getTree(segment) {
|
|
5838
5858
|
if (this.targetingTrees.has(segment.id)) {
|
|
@@ -5921,29 +5941,31 @@ class DataManager {
|
|
|
5921
5941
|
return new Set(Object.keys(targetingData));
|
|
5922
5942
|
}
|
|
5923
5943
|
getLinkedVisitor(visitorCode) {
|
|
5944
|
+
var _a, _b, _c;
|
|
5924
5945
|
const storageData = this.dataStorage.read();
|
|
5925
5946
|
if (!storageData.ok) {
|
|
5926
5947
|
return null;
|
|
5927
5948
|
}
|
|
5928
|
-
|
|
5929
|
-
|
|
5949
|
+
const visitorDataOrRef = storageData.data[visitorCode];
|
|
5950
|
+
// Direct reference case
|
|
5951
|
+
if (typeof visitorDataOrRef === 'string') {
|
|
5952
|
+
return visitorDataOrRef;
|
|
5930
5953
|
}
|
|
5931
|
-
|
|
5954
|
+
// No mapping index or no visitor data
|
|
5955
|
+
if (visitorDataOrRef == null ||
|
|
5956
|
+
this.mappingIdentifierCustomDataIndex == null) {
|
|
5932
5957
|
return null;
|
|
5933
5958
|
}
|
|
5934
|
-
const
|
|
5935
|
-
|
|
5936
|
-
return null;
|
|
5937
|
-
}
|
|
5938
|
-
const customData = visitorData[KameleoonData.CustomData];
|
|
5939
|
-
if (customData && customData[this.mappingIdentifierCustomDataIndex]) {
|
|
5940
|
-
return customData[this.mappingIdentifierCustomDataIndex].value[0];
|
|
5941
|
-
}
|
|
5942
|
-
return null;
|
|
5959
|
+
const value = (_c = (_b = (_a = visitorDataOrRef[KameleoonData.CustomData]) === null || _a === void 0 ? void 0 : _a[this.mappingIdentifierCustomDataIndex]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c[0];
|
|
5960
|
+
return value !== null && value !== void 0 ? value : null;
|
|
5943
5961
|
}
|
|
5944
|
-
mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, extendTtl, }) {
|
|
5962
|
+
mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, extendTtl, track, }) {
|
|
5945
5963
|
var _a, _b, _c;
|
|
5946
5964
|
for (const dataItem of kameleoonData) {
|
|
5965
|
+
// prcoess track status
|
|
5966
|
+
if (track === false) {
|
|
5967
|
+
dataItem.status = TrackingStatus.Sent;
|
|
5968
|
+
}
|
|
5947
5969
|
// process custom data
|
|
5948
5970
|
if (dataItem.data.type === KameleoonData.CustomData) {
|
|
5949
5971
|
const customDataIsValid = this.processCustomData({
|
|
@@ -6101,6 +6123,135 @@ class DataManager {
|
|
|
6101
6123
|
}
|
|
6102
6124
|
}
|
|
6103
6125
|
|
|
6126
|
+
const VISITOR_CODE_LENGTH = 16;
|
|
6127
|
+
const VISITOR_CODE_MAX_LENGTH = 255;
|
|
6128
|
+
const DEFAULT_MAX_AGE = 60 * 60 * 24 * 365;
|
|
6129
|
+
const PATH = '/';
|
|
6130
|
+
|
|
6131
|
+
/**
|
|
6132
|
+
* VisitorCodeManager - a class which manages visitor codes using cookies, offering functions to generate, retrieve,
|
|
6133
|
+
* and handle these codes while considering user consent.
|
|
6134
|
+
**/
|
|
6135
|
+
class VisitorCodeManager {
|
|
6136
|
+
constructor() {
|
|
6137
|
+
this.isConsentRequired = false;
|
|
6138
|
+
}
|
|
6139
|
+
set consentRequired(isRequired) {
|
|
6140
|
+
this.isConsentRequired = isRequired;
|
|
6141
|
+
}
|
|
6142
|
+
get consentRequired() {
|
|
6143
|
+
return this.isConsentRequired;
|
|
6144
|
+
}
|
|
6145
|
+
set getData(callback) {
|
|
6146
|
+
this.getDataCallback = callback;
|
|
6147
|
+
}
|
|
6148
|
+
set setData(callback) {
|
|
6149
|
+
this.setDataCallback = callback;
|
|
6150
|
+
}
|
|
6151
|
+
get setData() {
|
|
6152
|
+
if (this.setDataCallback) {
|
|
6153
|
+
return this.setDataCallback;
|
|
6154
|
+
}
|
|
6155
|
+
throw new Error('Missing setDataCallback!');
|
|
6156
|
+
}
|
|
6157
|
+
validateVisitorCode(visitorCode) {
|
|
6158
|
+
if (visitorCode.length === 0) {
|
|
6159
|
+
return buildExports.Err(new KameleoonError(KameleoonException.VisitorCodeEmpty));
|
|
6160
|
+
}
|
|
6161
|
+
if (visitorCode.length > VISITOR_CODE_MAX_LENGTH) {
|
|
6162
|
+
return buildExports.Err(new KameleoonError(KameleoonException.VisitorCodeMaxLength));
|
|
6163
|
+
}
|
|
6164
|
+
return buildExports.Ok();
|
|
6165
|
+
}
|
|
6166
|
+
getVisitorCode(defaultVisitorCode) {
|
|
6167
|
+
KameleoonLogger.debug `CALL: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode})`;
|
|
6168
|
+
if (!this.getDataCallback || !this.setDataCallback) {
|
|
6169
|
+
throw new Error('Missing getDataCallback or setDataCallback methods in getVisitorCode!');
|
|
6170
|
+
}
|
|
6171
|
+
let visitorCode;
|
|
6172
|
+
const existingVisitorCode = this.getDataCallback(KameleoonStorageKey.VisitorCode);
|
|
6173
|
+
if (existingVisitorCode) {
|
|
6174
|
+
visitorCode = existingVisitorCode;
|
|
6175
|
+
}
|
|
6176
|
+
if (!visitorCode) {
|
|
6177
|
+
if (defaultVisitorCode) {
|
|
6178
|
+
this.validateVisitorCode(defaultVisitorCode).throw();
|
|
6179
|
+
visitorCode = defaultVisitorCode;
|
|
6180
|
+
KameleoonLogger.debug `Used default visitor code: ${visitorCode}`;
|
|
6181
|
+
}
|
|
6182
|
+
else {
|
|
6183
|
+
visitorCode = this.generateVisitorCode();
|
|
6184
|
+
KameleoonLogger.debug `Generated new visitor code: ${visitorCode}`;
|
|
6185
|
+
}
|
|
6186
|
+
}
|
|
6187
|
+
this.processSimulatedVariations(visitorCode);
|
|
6188
|
+
if (!this.isConsentRequired) {
|
|
6189
|
+
this.setDataCallback({
|
|
6190
|
+
visitorCode,
|
|
6191
|
+
key: KameleoonStorageKey.VisitorCode,
|
|
6192
|
+
maxAge: DEFAULT_MAX_AGE,
|
|
6193
|
+
path: PATH,
|
|
6194
|
+
});
|
|
6195
|
+
}
|
|
6196
|
+
KameleoonLogger.debug `RETURN: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode}) -> (visitorCode: ${visitorCode})`;
|
|
6197
|
+
return visitorCode;
|
|
6198
|
+
}
|
|
6199
|
+
processSimulatedVariations(visitorCode) {
|
|
6200
|
+
if (this.variationConfiguration) {
|
|
6201
|
+
const simulatedVariationsData = this.getSimulatedVariations(visitorCode);
|
|
6202
|
+
try {
|
|
6203
|
+
this.variationConfiguration.clearSimulatedVariations(visitorCode).throw();
|
|
6204
|
+
if (simulatedVariationsData !== null && simulatedVariationsData.length > 0) {
|
|
6205
|
+
this.variationConfiguration.updateForcedFeatureVariations(visitorCode, simulatedVariationsData).throw();
|
|
6206
|
+
}
|
|
6207
|
+
}
|
|
6208
|
+
catch (error) {
|
|
6209
|
+
if (error instanceof Error) {
|
|
6210
|
+
KameleoonLogger.error `Failed to process simulated variations: ${error.message}`;
|
|
6211
|
+
}
|
|
6212
|
+
}
|
|
6213
|
+
}
|
|
6214
|
+
}
|
|
6215
|
+
getSimulatedVariations(visitorCode) {
|
|
6216
|
+
KameleoonLogger.debug `CALL: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode})`;
|
|
6217
|
+
const simulatedVariationsData = this.getDataCallback(KameleoonStorageKey.KameleoonSimulationFFData);
|
|
6218
|
+
let variations = null;
|
|
6219
|
+
if (typeof simulatedVariationsData === 'string' &&
|
|
6220
|
+
simulatedVariationsData.length > 0) {
|
|
6221
|
+
try {
|
|
6222
|
+
const parsed = JSON.parse(decodeURIComponent(simulatedVariationsData));
|
|
6223
|
+
if (parsed && typeof parsed === 'object') {
|
|
6224
|
+
variations = Object.entries(parsed)
|
|
6225
|
+
.map(([key, value]) => {
|
|
6226
|
+
return this.variationConfiguration.simulatedVariationFromJson(key, value);
|
|
6227
|
+
})
|
|
6228
|
+
.filter((variation) => variation !== null);
|
|
6229
|
+
}
|
|
6230
|
+
}
|
|
6231
|
+
catch (error) {
|
|
6232
|
+
if (error instanceof Error) {
|
|
6233
|
+
KameleoonLogger.error `Failed to parse simulated variations: ${error.message}`;
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
}
|
|
6237
|
+
KameleoonLogger.debug `RETURN: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode}) -> (variations: ${variations})`;
|
|
6238
|
+
return variations;
|
|
6239
|
+
}
|
|
6240
|
+
generateVisitorCode() {
|
|
6241
|
+
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
6242
|
+
const randomCharacterArray = [];
|
|
6243
|
+
for (let i = 0; i < VISITOR_CODE_LENGTH; i++) {
|
|
6244
|
+
randomCharacterArray.push(characters[Math.floor(Math.random() * characters.length)]);
|
|
6245
|
+
}
|
|
6246
|
+
return randomCharacterArray.join('');
|
|
6247
|
+
}
|
|
6248
|
+
setVariationConfiguration(variationConfiguration) {
|
|
6249
|
+
if (!this.variationConfiguration) {
|
|
6250
|
+
this.variationConfiguration = variationConfiguration;
|
|
6251
|
+
}
|
|
6252
|
+
}
|
|
6253
|
+
}
|
|
6254
|
+
|
|
6104
6255
|
var sha256$2 = {exports: {}};
|
|
6105
6256
|
|
|
6106
6257
|
function commonjsRequire(path) {
|
|
@@ -7635,135 +7786,6 @@ class KameleoonEventSource {
|
|
|
7635
7786
|
}
|
|
7636
7787
|
}
|
|
7637
7788
|
|
|
7638
|
-
const VISITOR_CODE_LENGTH = 16;
|
|
7639
|
-
const VISITOR_CODE_MAX_LENGTH = 255;
|
|
7640
|
-
const DEFAULT_MAX_AGE = 60 * 60 * 24 * 365;
|
|
7641
|
-
const PATH = '/';
|
|
7642
|
-
|
|
7643
|
-
/**
|
|
7644
|
-
* VisitorCodeManager - a class which manages visitor codes using cookies, offering functions to generate, retrieve,
|
|
7645
|
-
* and handle these codes while considering user consent.
|
|
7646
|
-
**/
|
|
7647
|
-
class VisitorCodeManager {
|
|
7648
|
-
constructor() {
|
|
7649
|
-
this.isConsentRequired = false;
|
|
7650
|
-
}
|
|
7651
|
-
set consentRequired(isRequired) {
|
|
7652
|
-
this.isConsentRequired = isRequired;
|
|
7653
|
-
}
|
|
7654
|
-
get consentRequired() {
|
|
7655
|
-
return this.isConsentRequired;
|
|
7656
|
-
}
|
|
7657
|
-
set getData(callback) {
|
|
7658
|
-
this.getDataCallback = callback;
|
|
7659
|
-
}
|
|
7660
|
-
set setData(callback) {
|
|
7661
|
-
this.setDataCallback = callback;
|
|
7662
|
-
}
|
|
7663
|
-
get setData() {
|
|
7664
|
-
if (this.setDataCallback) {
|
|
7665
|
-
return this.setDataCallback;
|
|
7666
|
-
}
|
|
7667
|
-
throw new Error('Missing setDataCallback!');
|
|
7668
|
-
}
|
|
7669
|
-
validateVisitorCode(visitorCode) {
|
|
7670
|
-
if (visitorCode.length === 0) {
|
|
7671
|
-
return buildExports.Err(new KameleoonError(KameleoonException.VisitorCodeEmpty));
|
|
7672
|
-
}
|
|
7673
|
-
if (visitorCode.length > VISITOR_CODE_MAX_LENGTH) {
|
|
7674
|
-
return buildExports.Err(new KameleoonError(KameleoonException.VisitorCodeMaxLength));
|
|
7675
|
-
}
|
|
7676
|
-
return buildExports.Ok();
|
|
7677
|
-
}
|
|
7678
|
-
getVisitorCode(defaultVisitorCode) {
|
|
7679
|
-
KameleoonLogger.debug `CALL: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode})`;
|
|
7680
|
-
if (!this.getDataCallback || !this.setDataCallback) {
|
|
7681
|
-
throw new Error('Missing getDataCallback or setDataCallback methods in getVisitorCode!');
|
|
7682
|
-
}
|
|
7683
|
-
let visitorCode;
|
|
7684
|
-
const existingVisitorCode = this.getDataCallback(KameleoonStorageKey.VisitorCode);
|
|
7685
|
-
if (existingVisitorCode) {
|
|
7686
|
-
visitorCode = existingVisitorCode;
|
|
7687
|
-
}
|
|
7688
|
-
if (!visitorCode) {
|
|
7689
|
-
if (defaultVisitorCode) {
|
|
7690
|
-
this.validateVisitorCode(defaultVisitorCode).throw();
|
|
7691
|
-
visitorCode = defaultVisitorCode;
|
|
7692
|
-
KameleoonLogger.debug `Used default visitor code: ${visitorCode}`;
|
|
7693
|
-
}
|
|
7694
|
-
else {
|
|
7695
|
-
visitorCode = this.generateVisitorCode();
|
|
7696
|
-
KameleoonLogger.debug `Generated new visitor code: ${visitorCode}`;
|
|
7697
|
-
}
|
|
7698
|
-
}
|
|
7699
|
-
this.processSimulatedVariations(visitorCode);
|
|
7700
|
-
if (!this.isConsentRequired) {
|
|
7701
|
-
this.setDataCallback({
|
|
7702
|
-
visitorCode,
|
|
7703
|
-
key: KameleoonStorageKey.VisitorCode,
|
|
7704
|
-
maxAge: DEFAULT_MAX_AGE,
|
|
7705
|
-
path: PATH,
|
|
7706
|
-
});
|
|
7707
|
-
}
|
|
7708
|
-
KameleoonLogger.debug `RETURN: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode}) -> (visitorCode: ${visitorCode})`;
|
|
7709
|
-
return visitorCode;
|
|
7710
|
-
}
|
|
7711
|
-
processSimulatedVariations(visitorCode) {
|
|
7712
|
-
if (this.variationConfiguration) {
|
|
7713
|
-
const simulatedVariationsData = this.getSimulatedVariations(visitorCode);
|
|
7714
|
-
try {
|
|
7715
|
-
this.variationConfiguration.clearSimulatedVariations(visitorCode).throw();
|
|
7716
|
-
if (simulatedVariationsData !== null && simulatedVariationsData.length > 0) {
|
|
7717
|
-
this.variationConfiguration.updateForcedFeatureVariations(visitorCode, simulatedVariationsData).throw();
|
|
7718
|
-
}
|
|
7719
|
-
}
|
|
7720
|
-
catch (error) {
|
|
7721
|
-
if (error instanceof Error) {
|
|
7722
|
-
KameleoonLogger.error `Failed to process simulated variations: ${error.message}`;
|
|
7723
|
-
}
|
|
7724
|
-
}
|
|
7725
|
-
}
|
|
7726
|
-
}
|
|
7727
|
-
getSimulatedVariations(visitorCode) {
|
|
7728
|
-
KameleoonLogger.debug `CALL: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode})`;
|
|
7729
|
-
const simulatedVariationsData = this.getDataCallback(KameleoonStorageKey.KameleoonSimulationFFData);
|
|
7730
|
-
let variations = null;
|
|
7731
|
-
if (typeof simulatedVariationsData === 'string' &&
|
|
7732
|
-
simulatedVariationsData.length > 0) {
|
|
7733
|
-
try {
|
|
7734
|
-
const parsed = JSON.parse(decodeURIComponent(simulatedVariationsData));
|
|
7735
|
-
if (parsed && typeof parsed === 'object') {
|
|
7736
|
-
variations = Object.entries(parsed)
|
|
7737
|
-
.map(([key, value]) => {
|
|
7738
|
-
return this.variationConfiguration.simulatedVariationFromJson(key, value);
|
|
7739
|
-
})
|
|
7740
|
-
.filter((variation) => variation !== null);
|
|
7741
|
-
}
|
|
7742
|
-
}
|
|
7743
|
-
catch (error) {
|
|
7744
|
-
if (error instanceof Error) {
|
|
7745
|
-
KameleoonLogger.error `Failed to parse simulated variations: ${error.message}`;
|
|
7746
|
-
}
|
|
7747
|
-
}
|
|
7748
|
-
}
|
|
7749
|
-
KameleoonLogger.debug `RETURN: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode}) -> (variations: ${variations})`;
|
|
7750
|
-
return variations;
|
|
7751
|
-
}
|
|
7752
|
-
generateVisitorCode() {
|
|
7753
|
-
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
7754
|
-
const randomCharacterArray = [];
|
|
7755
|
-
for (let i = 0; i < VISITOR_CODE_LENGTH; i++) {
|
|
7756
|
-
randomCharacterArray.push(characters[Math.floor(Math.random() * characters.length)]);
|
|
7757
|
-
}
|
|
7758
|
-
return randomCharacterArray.join('');
|
|
7759
|
-
}
|
|
7760
|
-
setVariationConfiguration(variationConfiguration) {
|
|
7761
|
-
if (!this.variationConfiguration) {
|
|
7762
|
-
this.variationConfiguration = variationConfiguration;
|
|
7763
|
-
}
|
|
7764
|
-
}
|
|
7765
|
-
}
|
|
7766
|
-
|
|
7767
7789
|
var Byte;
|
|
7768
7790
|
(function (Byte) {
|
|
7769
7791
|
Byte[Byte["Kb"] = 1000] = "Kb";
|
|
@@ -7956,7 +7978,10 @@ class Tracker {
|
|
|
7956
7978
|
const linkedVisitor = this.dataManager.getLinkedVisitor(visitorCode);
|
|
7957
7979
|
const index = this.dataManager.identifierCustomDataIndex;
|
|
7958
7980
|
if (!linkedVisitor && typeof index === 'number') {
|
|
7959
|
-
this.dataManager.storeData(
|
|
7981
|
+
this.dataManager.storeData({
|
|
7982
|
+
visitorCode,
|
|
7983
|
+
data: [new CustomData$1(index, visitorCode)],
|
|
7984
|
+
});
|
|
7960
7985
|
}
|
|
7961
7986
|
else {
|
|
7962
7987
|
isMappingIdentifier = true;
|
|
@@ -8105,7 +8130,7 @@ class Tracker {
|
|
|
8105
8130
|
this.dataManager.storeTrackedData(updatedData);
|
|
8106
8131
|
}
|
|
8107
8132
|
else {
|
|
8108
|
-
this.dataManager.
|
|
8133
|
+
this.dataManager.storeDataForVisitors(updatedData, false);
|
|
8109
8134
|
}
|
|
8110
8135
|
}
|
|
8111
8136
|
getUnsentVisitorData(visitorCode, isConsentProvided) {
|
|
@@ -8288,16 +8313,21 @@ class KameleoonClient {
|
|
|
8288
8313
|
return result.ok;
|
|
8289
8314
|
});
|
|
8290
8315
|
}
|
|
8291
|
-
addData(
|
|
8316
|
+
addData(visitorCodeOrParams, ...dataRest) {
|
|
8292
8317
|
if (this.stubMode) {
|
|
8293
8318
|
throw new KameleoonError(KameleoonException.Initialization);
|
|
8294
8319
|
}
|
|
8320
|
+
const params = typeof visitorCodeOrParams === 'string'
|
|
8321
|
+
? { visitorCode: visitorCodeOrParams, data: dataRest }
|
|
8322
|
+
: visitorCodeOrParams;
|
|
8323
|
+
const { visitorCode, data, track = true } = params;
|
|
8295
8324
|
KameleoonLogger.info `CALL: KameleoonClient.addData(visitorCode: ${visitorCode}, data: ${data})`;
|
|
8296
8325
|
this.visitorCodeManager.validateVisitorCode(visitorCode).throw();
|
|
8297
8326
|
if (!this.initialized) {
|
|
8298
8327
|
throw new KameleoonError(KameleoonException.Initialization);
|
|
8299
8328
|
}
|
|
8300
|
-
|
|
8329
|
+
// assuming DataManager.storeData supports `track` (boolean) as discussed
|
|
8330
|
+
this.dataManager.storeData({ visitorCode, track, data }).throw();
|
|
8301
8331
|
KameleoonLogger.info `RETURN: KameleoonClient.addData(visitorCode: ${visitorCode}, data: ${data})`;
|
|
8302
8332
|
}
|
|
8303
8333
|
getRemoteVisitorData({ visitorCode, shouldAddData = true, filters = DEFAULT_VISITOR_DATA_FILTERS, }) {
|
|
@@ -8641,7 +8671,11 @@ class KameleoonClient {
|
|
|
8641
8671
|
return null;
|
|
8642
8672
|
}
|
|
8643
8673
|
const customData = new CustomData$1(customDataIndex, ...Object.keys(data[WAREHOUSE_AUDIENCE_KEY]));
|
|
8644
|
-
this.dataManager.storeData(
|
|
8674
|
+
this.dataManager.storeData({
|
|
8675
|
+
visitorCode,
|
|
8676
|
+
track: true,
|
|
8677
|
+
data: [customData],
|
|
8678
|
+
});
|
|
8645
8679
|
KameleoonLogger.info `RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${visitorCode}, customDataIndex: ${customDataIndex}, warehouseKey: ${warehouseKey}) -> (customData: ${customData})`;
|
|
8646
8680
|
return customData;
|
|
8647
8681
|
});
|
|
@@ -8717,7 +8751,7 @@ class KameleoonClient {
|
|
|
8717
8751
|
}
|
|
8718
8752
|
}
|
|
8719
8753
|
if (targetedSegments.length !== 0) {
|
|
8720
|
-
this.dataManager.storeData(visitorCode,
|
|
8754
|
+
this.dataManager.storeData({ visitorCode, data: targetedSegments });
|
|
8721
8755
|
}
|
|
8722
8756
|
this.flush(visitorCode);
|
|
8723
8757
|
KameleoonLogger.info `RETURN: KameleoonClient.evaluateAudiences(visitorCode: ${visitorCode})`;
|