@kameleoon/javascript-sdk-core 5.16.0 → 5.16.1

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.
@@ -2273,11 +2273,11 @@ let CustomData$1 = class CustomData {
2273
2273
  const isNumber = typeof first === 'number';
2274
2274
  const isBoolean = typeof second === 'boolean';
2275
2275
  if (isNumber) {
2276
- this.index = first;
2276
+ this._index = first;
2277
2277
  }
2278
2278
  else {
2279
- this.name = first;
2280
- this.index = -1;
2279
+ this._name = first;
2280
+ this._index = CustomData.UNDEFINED_INDEX;
2281
2281
  }
2282
2282
  this.overwrite = isBoolean ? second : true;
2283
2283
  this.value = isBoolean
@@ -2288,7 +2288,7 @@ let CustomData$1 = class CustomData {
2288
2288
  // --- Note ---
2289
2289
  // If SDK is used in vanilla JS codebase, then you're also able to create an instance
2290
2290
  // with no required data, we don't want send anything to tracking in that case
2291
- if (typeof this.index !== 'number') {
2291
+ if (typeof this._index !== 'number') {
2292
2292
  return '';
2293
2293
  }
2294
2294
  const uniqueValues = [...new Set(this.value)];
@@ -2305,7 +2305,7 @@ let CustomData$1 = class CustomData {
2305
2305
  }
2306
2306
  return (UrlEventType.CustomData +
2307
2307
  UrlParameter.Index +
2308
- this.index +
2308
+ this._index +
2309
2309
  UrlParameter.ValuesCountMap +
2310
2310
  encodeURIComponent(JSON.stringify(resultValue)) +
2311
2311
  UrlParameter.Overwrite +
@@ -2313,7 +2313,7 @@ let CustomData$1 = class CustomData {
2313
2313
  identifierParameter);
2314
2314
  }
2315
2315
  get data() {
2316
- return Object.assign(Object.assign({ index: this.index }, (this.name !== undefined ? { name: this.name } : {})), { value: this.value, type: exports.KameleoonData.CustomData, isIdentifier: this.isIdentifier, status: this.status, overwrite: this.overwrite });
2316
+ return Object.assign(Object.assign({ index: this._index }, (this._name !== undefined ? { name: this._name } : {})), { value: this.value, type: exports.KameleoonData.CustomData, isIdentifier: this.isIdentifier, status: this.status, overwrite: this.overwrite });
2317
2317
  }
2318
2318
  get status() {
2319
2319
  if (this._isMappingIdentifier) {
@@ -2332,7 +2332,7 @@ let CustomData$1 = class CustomData {
2332
2332
  let customData;
2333
2333
  if (name) {
2334
2334
  customData = new CustomData(name, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
2335
- customData._index = index;
2335
+ customData.index = index;
2336
2336
  }
2337
2337
  else {
2338
2338
  customData = new CustomData(index, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
@@ -2369,13 +2369,28 @@ let CustomData$1 = class CustomData {
2369
2369
  }
2370
2370
  /**
2371
2371
  * @private
2372
- * @method _index - an internal setter for setting index of custom data
2372
+ * @method index - an internal setter for setting index of custom data
2373
2373
  * @param {number} value - an index value
2374
2374
  * */
2375
- set _index(value) {
2376
- this.index = value;
2375
+ set index(value) {
2376
+ this._index = value;
2377
+ }
2378
+ /**
2379
+ * @private
2380
+ * @method index - an internal getter for index of custom data
2381
+ * */
2382
+ get index() {
2383
+ return this._index;
2384
+ }
2385
+ /**
2386
+ * @private
2387
+ * @method name - an internal getter for a name of custom data
2388
+ * */
2389
+ get name() {
2390
+ return this._name;
2377
2391
  }
2378
2392
  };
2393
+ CustomData$1.UNDEFINED_INDEX = -1;
2379
2394
 
2380
2395
  /**
2381
2396
  * @class
@@ -2412,6 +2427,9 @@ let Conversion$1 = class Conversion {
2412
2427
  ? UrlParameter.Metadata + this._encodeMetadata()
2413
2428
  : ''));
2414
2429
  }
2430
+ get _metadata() {
2431
+ return this.metadata;
2432
+ }
2415
2433
  get data() {
2416
2434
  var _a;
2417
2435
  return {
@@ -5842,7 +5860,9 @@ class DataManager {
5842
5860
  return null;
5843
5861
  }
5844
5862
  mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, }) {
5863
+ var _a;
5845
5864
  for (const dataItem of kameleoonData) {
5865
+ // process custom data
5846
5866
  if (dataItem.data.type === exports.KameleoonData.CustomData) {
5847
5867
  const customDataIsValid = this.processCustomData({
5848
5868
  infoData,
@@ -5854,6 +5874,10 @@ class DataManager {
5854
5874
  continue;
5855
5875
  }
5856
5876
  }
5877
+ // process metadata of conversions
5878
+ if (dataItem.data.type === exports.KameleoonData.Conversion) {
5879
+ (_a = dataItem._metadata) === null || _a === void 0 ? void 0 : _a.forEach((item) => this.trySetCustomDataIndexByName(item));
5880
+ }
5857
5881
  const expirationTime = this.dataProcessor.mutUpdateData({
5858
5882
  infoData,
5859
5883
  visitorCode,
@@ -5893,13 +5917,9 @@ class DataManager {
5893
5917
  var _a;
5894
5918
  const { data } = customData;
5895
5919
  const isDataValid = Boolean(data.value.length && data.value[0].length);
5896
- if (data.name) {
5897
- const cdIndex = this.customDataIndexByName.get(data.name);
5898
- if (cdIndex === undefined) {
5899
- return false;
5900
- }
5901
- data.index = cdIndex;
5902
- customData._index = cdIndex;
5920
+ this.trySetCustomDataIndexByName(customData);
5921
+ if (data.index == CustomData$1.UNDEFINED_INDEX) {
5922
+ data.index = customData.index;
5903
5923
  }
5904
5924
  if (this.mappingIdentifierCustomDataIndex === data.index && isDataValid) {
5905
5925
  customData._isMappingIdentifier = true;
@@ -5926,6 +5946,15 @@ class DataManager {
5926
5946
  }
5927
5947
  return true;
5928
5948
  }
5949
+ trySetCustomDataIndexByName(customData) {
5950
+ if (customData.index == CustomData$1.UNDEFINED_INDEX && customData.name) {
5951
+ const cdIndex = this.customDataIndexByName.get(customData.name);
5952
+ if (cdIndex === undefined) {
5953
+ return;
5954
+ }
5955
+ customData.index = cdIndex;
5956
+ }
5957
+ }
5929
5958
  get unsentDataVisitors() {
5930
5959
  const infoResult = this.infoStorage.read();
5931
5960
  if (!infoResult.ok) {