@ninetailed/experience.js 4.3.0-beta.3 → 4.5.0-beta.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.
package/index.js CHANGED
@@ -5,8 +5,6 @@ import { z } from 'zod';
5
5
 
6
6
  const HAS_SEEN_EXPERIENCE = 'has_seen_experience';
7
7
  const HAS_SEEN_COMPONENT = 'has_seen_component';
8
- const HAS_SEEN_ELEMENT = 'has_seen_element';
9
- const PAGE_HIDDEN = 'page_hidden';
10
8
 
11
9
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
12
10
 
@@ -604,9 +602,9 @@ var inspectSource$3 = store$1.inspectSource;
604
602
  var global$d = global$k;
605
603
  var isCallable$d = isCallable$k;
606
604
 
607
- var WeakMap$2 = global$d.WeakMap;
605
+ var WeakMap$1 = global$d.WeakMap;
608
606
 
609
- var weakMapBasicDetection = isCallable$d(WeakMap$2) && /native code/.test(String(WeakMap$2));
607
+ var weakMapBasicDetection = isCallable$d(WeakMap$1) && /native code/.test(String(WeakMap$1));
610
608
 
611
609
  var shared$1 = shared$3.exports;
612
610
  var uid = uid$2;
@@ -630,7 +628,7 @@ var hiddenKeys$3 = hiddenKeys$4;
630
628
 
631
629
  var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
632
630
  var TypeError$2 = global$c.TypeError;
633
- var WeakMap$1 = global$c.WeakMap;
631
+ var WeakMap = global$c.WeakMap;
634
632
  var set$1, get, has;
635
633
 
636
634
  var enforce = function (it) {
@@ -647,7 +645,7 @@ var getterFor = function (TYPE) {
647
645
  };
648
646
 
649
647
  if (NATIVE_WEAK_MAP || shared.state) {
650
- var store = shared.state || (shared.state = new WeakMap$1());
648
+ var store = shared.state || (shared.state = new WeakMap());
651
649
  /* eslint-disable no-self-assign -- prototype methods protection */
652
650
  store.get = store.get;
653
651
  store.has = store.has;
@@ -2519,18 +2517,6 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2519
2517
  PERFORMANCE OF THIS SOFTWARE.
2520
2518
  ***************************************************************************** */
2521
2519
 
2522
- function __rest(s, e) {
2523
- var t = {};
2524
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2525
- t[p] = s[p];
2526
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
2527
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
2528
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
2529
- t[p[i]] = s[p[i]];
2530
- }
2531
- return t;
2532
- }
2533
-
2534
2520
  function __awaiter(thisArg, _arguments, P, generator) {
2535
2521
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2536
2522
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -2598,11 +2584,13 @@ const ninetailedPlugin = ({
2598
2584
  apiClient,
2599
2585
  profile,
2600
2586
  locale,
2601
- ninetailed
2587
+ ninetailed,
2588
+ buildClientContext
2602
2589
  }) => {
2603
2590
  let _instance;
2604
2591
  let queue = [];
2605
2592
  let enabledFeatures = Object.values(FEATURES);
2593
+ const buildContext = buildClientContext || buildClientNinetailedRequestContext;
2606
2594
  const flush = () => __awaiter(void 0, void 0, void 0, function* () {
2607
2595
  const events = Object.assign([], queue);
2608
2596
  logger.info('Start flushing events.');
@@ -2706,7 +2694,7 @@ const ninetailedPlugin = ({
2706
2694
  payload
2707
2695
  }) => __awaiter(void 0, void 0, void 0, function* () {
2708
2696
  logger.info('Sending Page event.');
2709
- const ctx = buildClientNinetailedRequestContext();
2697
+ const ctx = buildContext();
2710
2698
  return enqueueEvent(buildPageEvent({
2711
2699
  messageId: payload.meta.rid,
2712
2700
  timestamp: payload.meta.ts,
@@ -2721,7 +2709,7 @@ const ninetailedPlugin = ({
2721
2709
  payload
2722
2710
  }) => __awaiter(void 0, void 0, void 0, function* () {
2723
2711
  logger.info('Sending Track event.');
2724
- const ctx = buildClientNinetailedRequestContext();
2712
+ const ctx = buildContext();
2725
2713
  return enqueueEvent(buildTrackEvent({
2726
2714
  messageId: payload.meta.rid,
2727
2715
  timestamp: payload.meta.ts,
@@ -2737,7 +2725,7 @@ const ninetailedPlugin = ({
2737
2725
  payload
2738
2726
  }) => __awaiter(void 0, void 0, void 0, function* () {
2739
2727
  logger.info('Sending Identify event.');
2740
- const ctx = buildClientNinetailedRequestContext();
2728
+ const ctx = buildContext();
2741
2729
  if (payload.userId === EMPTY_MERGE_ID && (!payload.traits || typeof payload.traits === 'object' && Object.keys(payload.traits).length === 0)) {
2742
2730
  logger.info('Skipping Identify event as no userId and no traits are set.');
2743
2731
  return;
@@ -2849,115 +2837,6 @@ if (NOT_GENERIC || INCORRECT_NAME) {
2849
2837
  }, { unsafe: true });
2850
2838
  }
2851
2839
 
2852
- var classof = classofRaw$2;
2853
-
2854
- // `IsArray` abstract operation
2855
- // https://tc39.es/ecma262/#sec-isarray
2856
- // eslint-disable-next-line es/no-array-isarray -- safe
2857
- var isArray$2 = Array.isArray || function isArray(argument) {
2858
- return classof(argument) == 'Array';
2859
- };
2860
-
2861
- var $TypeError$1 = TypeError;
2862
- var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991
2863
-
2864
- var doesNotExceedSafeInteger$1 = function (it) {
2865
- if (it > MAX_SAFE_INTEGER) throw $TypeError$1('Maximum allowed index exceeded');
2866
- return it;
2867
- };
2868
-
2869
- var isArray$1 = isArray$2;
2870
- var lengthOfArrayLike$2 = lengthOfArrayLike$5;
2871
- var doesNotExceedSafeInteger = doesNotExceedSafeInteger$1;
2872
- var bind = functionBindContext;
2873
-
2874
- // `FlattenIntoArray` abstract operation
2875
- // https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
2876
- var flattenIntoArray$1 = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
2877
- var targetIndex = start;
2878
- var sourceIndex = 0;
2879
- var mapFn = mapper ? bind(mapper, thisArg) : false;
2880
- var element, elementLen;
2881
-
2882
- while (sourceIndex < sourceLen) {
2883
- if (sourceIndex in source) {
2884
- element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
2885
-
2886
- if (depth > 0 && isArray$1(element)) {
2887
- elementLen = lengthOfArrayLike$2(element);
2888
- targetIndex = flattenIntoArray$1(target, original, element, elementLen, targetIndex, depth - 1) - 1;
2889
- } else {
2890
- doesNotExceedSafeInteger(targetIndex + 1);
2891
- target[targetIndex] = element;
2892
- }
2893
-
2894
- targetIndex++;
2895
- }
2896
- sourceIndex++;
2897
- }
2898
- return targetIndex;
2899
- };
2900
-
2901
- var flattenIntoArray_1 = flattenIntoArray$1;
2902
-
2903
- var isArray = isArray$2;
2904
- var isConstructor = isConstructor$2;
2905
- var isObject$1 = isObject$a;
2906
- var wellKnownSymbol$3 = wellKnownSymbol$h;
2907
-
2908
- var SPECIES = wellKnownSymbol$3('species');
2909
- var $Array = Array;
2910
-
2911
- // a part of `ArraySpeciesCreate` abstract operation
2912
- // https://tc39.es/ecma262/#sec-arrayspeciescreate
2913
- var arraySpeciesConstructor$1 = function (originalArray) {
2914
- var C;
2915
- if (isArray(originalArray)) {
2916
- C = originalArray.constructor;
2917
- // cross-realm fallback
2918
- if (isConstructor(C) && (C === $Array || isArray(C.prototype))) C = undefined;
2919
- else if (isObject$1(C)) {
2920
- C = C[SPECIES];
2921
- if (C === null) C = undefined;
2922
- }
2923
- } return C === undefined ? $Array : C;
2924
- };
2925
-
2926
- var arraySpeciesConstructor = arraySpeciesConstructor$1;
2927
-
2928
- // `ArraySpeciesCreate` abstract operation
2929
- // https://tc39.es/ecma262/#sec-arrayspeciescreate
2930
- var arraySpeciesCreate$1 = function (originalArray, length) {
2931
- return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length);
2932
- };
2933
-
2934
- var $$3 = _export;
2935
- var flattenIntoArray = flattenIntoArray_1;
2936
- var toObject$2 = toObject$5;
2937
- var lengthOfArrayLike$1 = lengthOfArrayLike$5;
2938
- var toIntegerOrInfinity = toIntegerOrInfinity$3;
2939
- var arraySpeciesCreate = arraySpeciesCreate$1;
2940
-
2941
- // `Array.prototype.flat` method
2942
- // https://tc39.es/ecma262/#sec-array.prototype.flat
2943
- $$3({ target: 'Array', proto: true }, {
2944
- flat: function flat(/* depthArg = 1 */) {
2945
- var depthArg = arguments.length ? arguments[0] : undefined;
2946
- var O = toObject$2(this);
2947
- var sourceLen = lengthOfArrayLike$1(O);
2948
- var A = arraySpeciesCreate(O, 0);
2949
- A.length = flattenIntoArray(A, O, O, sourceLen, 0, depthArg === undefined ? 1 : toIntegerOrInfinity(depthArg));
2950
- return A;
2951
- }
2952
- });
2953
-
2954
- // this method was added to unscopables after implementation
2955
- // in popular engines, so it's moved to a separate module
2956
- var addToUnscopables$1 = addToUnscopables$3;
2957
-
2958
- // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
2959
- addToUnscopables$1('flat');
2960
-
2961
2840
  var fails$3 = fails$h;
2962
2841
 
2963
2842
  var correctPrototypeGetter = !fails$3(function () {
@@ -2969,7 +2848,7 @@ var correctPrototypeGetter = !fails$3(function () {
2969
2848
 
2970
2849
  var hasOwn = hasOwnProperty_1;
2971
2850
  var isCallable$2 = isCallable$k;
2972
- var toObject$1 = toObject$5;
2851
+ var toObject$2 = toObject$5;
2973
2852
  var sharedKey = sharedKey$3;
2974
2853
  var CORRECT_PROTOTYPE_GETTER = correctPrototypeGetter;
2975
2854
 
@@ -2981,7 +2860,7 @@ var ObjectPrototype = $Object.prototype;
2981
2860
  // https://tc39.es/ecma262/#sec-object.getprototypeof
2982
2861
  // eslint-disable-next-line es/no-object-getprototypeof -- safe
2983
2862
  var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : function (O) {
2984
- var object = toObject$1(O);
2863
+ var object = toObject$2(O);
2985
2864
  if (hasOwn(object, IE_PROTO)) return object[IE_PROTO];
2986
2865
  var constructor = object.constructor;
2987
2866
  if (isCallable$2(constructor) && object instanceof constructor) {
@@ -2991,12 +2870,12 @@ var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : f
2991
2870
 
2992
2871
  var fails$2 = fails$h;
2993
2872
  var isCallable$1 = isCallable$k;
2994
- var isObject = isObject$a;
2873
+ var isObject$1 = isObject$a;
2995
2874
  var getPrototypeOf$1 = objectGetPrototypeOf;
2996
2875
  var defineBuiltIn$1 = defineBuiltIn$6;
2997
- var wellKnownSymbol$2 = wellKnownSymbol$h;
2876
+ var wellKnownSymbol$3 = wellKnownSymbol$h;
2998
2877
 
2999
- var ITERATOR$3 = wellKnownSymbol$2('iterator');
2878
+ var ITERATOR$3 = wellKnownSymbol$3('iterator');
3000
2879
  var BUGGY_SAFARI_ITERATORS$1 = false;
3001
2880
 
3002
2881
  // `%IteratorPrototype%` object
@@ -3014,7 +2893,7 @@ if ([].keys) {
3014
2893
  }
3015
2894
  }
3016
2895
 
3017
- var NEW_ITERATOR_PROTOTYPE = !isObject(IteratorPrototype$2) || fails$2(function () {
2896
+ var NEW_ITERATOR_PROTOTYPE = !isObject$1(IteratorPrototype$2) || fails$2(function () {
3018
2897
  var test = {};
3019
2898
  // FF44- legacy iterators case
3020
2899
  return IteratorPrototype$2[ITERATOR$3].call(test) !== test;
@@ -3051,7 +2930,7 @@ var iteratorCreateConstructor = function (IteratorConstructor, NAME, next, ENUME
3051
2930
  return IteratorConstructor;
3052
2931
  };
3053
2932
 
3054
- var $$2 = _export;
2933
+ var $$3 = _export;
3055
2934
  var call = functionCall;
3056
2935
  var FunctionName = functionName;
3057
2936
  var isCallable = isCallable$k;
@@ -3061,7 +2940,7 @@ var setPrototypeOf = objectSetPrototypeOf;
3061
2940
  var setToStringTag = setToStringTag$3;
3062
2941
  var createNonEnumerableProperty$1 = createNonEnumerableProperty$4;
3063
2942
  var defineBuiltIn = defineBuiltIn$6;
3064
- var wellKnownSymbol$1 = wellKnownSymbol$h;
2943
+ var wellKnownSymbol$2 = wellKnownSymbol$h;
3065
2944
  var Iterators$1 = iterators;
3066
2945
  var IteratorsCore = iteratorsCore;
3067
2946
 
@@ -3069,7 +2948,7 @@ var PROPER_FUNCTION_NAME = FunctionName.PROPER;
3069
2948
  var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
3070
2949
  var IteratorPrototype = IteratorsCore.IteratorPrototype;
3071
2950
  var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
3072
- var ITERATOR$2 = wellKnownSymbol$1('iterator');
2951
+ var ITERATOR$2 = wellKnownSymbol$2('iterator');
3073
2952
  var KEYS = 'keys';
3074
2953
  var VALUES = 'values';
3075
2954
  var ENTRIES = 'entries';
@@ -3136,7 +3015,7 @@ var iteratorDefine = function (Iterable, NAME, IteratorConstructor, next, DEFAUL
3136
3015
  if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
3137
3016
  defineBuiltIn(IterablePrototype, KEY, methods[KEY]);
3138
3017
  }
3139
- } else $$2({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
3018
+ } else $$3({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
3140
3019
  }
3141
3020
 
3142
3021
  // define iterator
@@ -3155,7 +3034,7 @@ var createIterResultObject$1 = function (value, done) {
3155
3034
  };
3156
3035
 
3157
3036
  var toIndexedObject = toIndexedObject$5;
3158
- var addToUnscopables = addToUnscopables$3;
3037
+ var addToUnscopables$1 = addToUnscopables$3;
3159
3038
  var Iterators = iterators;
3160
3039
  var InternalStateModule = internalState;
3161
3040
  var defineProperty = objectDefineProperty.f;
@@ -3206,9 +3085,9 @@ var es_array_iterator = defineIterator(Array, 'Array', function (iterated, kind)
3206
3085
  var values = Iterators.Arguments = Iterators.Array;
3207
3086
 
3208
3087
  // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
3209
- addToUnscopables('keys');
3210
- addToUnscopables('values');
3211
- addToUnscopables('entries');
3088
+ addToUnscopables$1('keys');
3089
+ addToUnscopables$1('values');
3090
+ addToUnscopables$1('entries');
3212
3091
 
3213
3092
  // V8 ~ Chrome 45- bug
3214
3093
  if (DESCRIPTORS && values.name !== 'values') try {
@@ -3264,10 +3143,10 @@ var DOMIterables = domIterables;
3264
3143
  var DOMTokenListPrototype = domTokenListPrototype;
3265
3144
  var ArrayIteratorMethods = es_array_iterator;
3266
3145
  var createNonEnumerableProperty = createNonEnumerableProperty$4;
3267
- var wellKnownSymbol = wellKnownSymbol$h;
3146
+ var wellKnownSymbol$1 = wellKnownSymbol$h;
3268
3147
 
3269
- var ITERATOR$1 = wellKnownSymbol('iterator');
3270
- var TO_STRING_TAG = wellKnownSymbol('toStringTag');
3148
+ var ITERATOR$1 = wellKnownSymbol$1('iterator');
3149
+ var TO_STRING_TAG = wellKnownSymbol$1('toStringTag');
3271
3150
  var ArrayValues = ArrayIteratorMethods.values;
3272
3151
 
3273
3152
  var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
@@ -3298,54 +3177,115 @@ for (var COLLECTION_NAME in DOMIterables) {
3298
3177
 
3299
3178
  handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
3300
3179
 
3301
- class ElementSeenObserver {
3302
- constructor(_options) {
3303
- this._options = _options;
3304
- this._elementDelays = new WeakMap();
3305
- this._intersectionTimers = new WeakMap();
3306
- if (typeof IntersectionObserver !== 'undefined') {
3307
- this._intersectionObserver = new IntersectionObserver(this.onIntersection.bind(this));
3308
- }
3309
- }
3310
- onIntersection(entries) {
3311
- entries.forEach(entry => {
3312
- const {
3313
- isIntersecting,
3314
- target
3315
- } = entry;
3316
- if (isIntersecting) {
3317
- const delay = this._elementDelays.get(target);
3318
- const timeOut = window.setTimeout(() => {
3319
- this._options.onElementSeen(target);
3320
- }, delay);
3321
- this._intersectionTimers.set(target, timeOut);
3180
+ var classof = classofRaw$2;
3181
+
3182
+ // `IsArray` abstract operation
3183
+ // https://tc39.es/ecma262/#sec-isarray
3184
+ // eslint-disable-next-line es/no-array-isarray -- safe
3185
+ var isArray$2 = Array.isArray || function isArray(argument) {
3186
+ return classof(argument) == 'Array';
3187
+ };
3188
+
3189
+ var $TypeError$1 = TypeError;
3190
+ var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991
3191
+
3192
+ var doesNotExceedSafeInteger$1 = function (it) {
3193
+ if (it > MAX_SAFE_INTEGER) throw $TypeError$1('Maximum allowed index exceeded');
3194
+ return it;
3195
+ };
3196
+
3197
+ var isArray$1 = isArray$2;
3198
+ var lengthOfArrayLike$2 = lengthOfArrayLike$5;
3199
+ var doesNotExceedSafeInteger = doesNotExceedSafeInteger$1;
3200
+ var bind = functionBindContext;
3201
+
3202
+ // `FlattenIntoArray` abstract operation
3203
+ // https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
3204
+ var flattenIntoArray$1 = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
3205
+ var targetIndex = start;
3206
+ var sourceIndex = 0;
3207
+ var mapFn = mapper ? bind(mapper, thisArg) : false;
3208
+ var element, elementLen;
3209
+
3210
+ while (sourceIndex < sourceLen) {
3211
+ if (sourceIndex in source) {
3212
+ element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
3213
+
3214
+ if (depth > 0 && isArray$1(element)) {
3215
+ elementLen = lengthOfArrayLike$2(element);
3216
+ targetIndex = flattenIntoArray$1(target, original, element, elementLen, targetIndex, depth - 1) - 1;
3322
3217
  } else {
3323
- const timeOut = this._intersectionTimers.get(target);
3324
- if (typeof timeOut !== 'undefined') {
3325
- window.clearTimeout(timeOut);
3326
- }
3218
+ doesNotExceedSafeInteger(targetIndex + 1);
3219
+ target[targetIndex] = element;
3327
3220
  }
3328
- });
3329
- }
3330
- observe(element, options) {
3331
- var _a, _b;
3332
- this._elementDelays.set(element, (_a = options === null || options === void 0 ? void 0 : options.delay) !== null && _a !== void 0 ? _a : 2000);
3333
- (_b = this._intersectionObserver) === null || _b === void 0 ? void 0 : _b.observe(element);
3334
- }
3335
- unobserve(element) {
3336
- var _a;
3337
- (_a = this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.unobserve(element);
3221
+
3222
+ targetIndex++;
3223
+ }
3224
+ sourceIndex++;
3338
3225
  }
3339
- }
3226
+ return targetIndex;
3227
+ };
3228
+
3229
+ var flattenIntoArray_1 = flattenIntoArray$1;
3340
3230
 
3341
- const acceptsCredentials = plugin => {
3342
- return typeof plugin === 'object' && plugin !== null && 'setCredentials' in plugin && typeof plugin.setCredentials === 'function';
3231
+ var isArray = isArray$2;
3232
+ var isConstructor = isConstructor$2;
3233
+ var isObject = isObject$a;
3234
+ var wellKnownSymbol = wellKnownSymbol$h;
3235
+
3236
+ var SPECIES = wellKnownSymbol('species');
3237
+ var $Array = Array;
3238
+
3239
+ // a part of `ArraySpeciesCreate` abstract operation
3240
+ // https://tc39.es/ecma262/#sec-arrayspeciescreate
3241
+ var arraySpeciesConstructor$1 = function (originalArray) {
3242
+ var C;
3243
+ if (isArray(originalArray)) {
3244
+ C = originalArray.constructor;
3245
+ // cross-realm fallback
3246
+ if (isConstructor(C) && (C === $Array || isArray(C.prototype))) C = undefined;
3247
+ else if (isObject(C)) {
3248
+ C = C[SPECIES];
3249
+ if (C === null) C = undefined;
3250
+ }
3251
+ } return C === undefined ? $Array : C;
3343
3252
  };
3344
3253
 
3345
- const isInterestedInHiddenPage = arg => {
3346
- return typeof arg === 'object' && arg !== null && PAGE_HIDDEN in arg && typeof arg[PAGE_HIDDEN] === 'function';
3254
+ var arraySpeciesConstructor = arraySpeciesConstructor$1;
3255
+
3256
+ // `ArraySpeciesCreate` abstract operation
3257
+ // https://tc39.es/ecma262/#sec-arrayspeciescreate
3258
+ var arraySpeciesCreate$1 = function (originalArray, length) {
3259
+ return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length);
3347
3260
  };
3348
3261
 
3262
+ var $$2 = _export;
3263
+ var flattenIntoArray = flattenIntoArray_1;
3264
+ var toObject$1 = toObject$5;
3265
+ var lengthOfArrayLike$1 = lengthOfArrayLike$5;
3266
+ var toIntegerOrInfinity = toIntegerOrInfinity$3;
3267
+ var arraySpeciesCreate = arraySpeciesCreate$1;
3268
+
3269
+ // `Array.prototype.flat` method
3270
+ // https://tc39.es/ecma262/#sec-array.prototype.flat
3271
+ $$2({ target: 'Array', proto: true }, {
3272
+ flat: function flat(/* depthArg = 1 */) {
3273
+ var depthArg = arguments.length ? arguments[0] : undefined;
3274
+ var O = toObject$1(this);
3275
+ var sourceLen = lengthOfArrayLike$1(O);
3276
+ var A = arraySpeciesCreate(O, 0);
3277
+ A.length = flattenIntoArray(A, O, O, sourceLen, 0, depthArg === undefined ? 1 : toIntegerOrInfinity(depthArg));
3278
+ return A;
3279
+ }
3280
+ });
3281
+
3282
+ // this method was added to unscopables after implementation
3283
+ // in popular engines, so it's moved to a separate module
3284
+ var addToUnscopables = addToUnscopables$3;
3285
+
3286
+ // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
3287
+ addToUnscopables('flat');
3288
+
3349
3289
  class Ninetailed {
3350
3290
  constructor(ninetailedApiClientInstanceOrOptions, {
3351
3291
  plugins,
@@ -3354,7 +3294,8 @@ class Ninetailed {
3354
3294
  locale,
3355
3295
  requestTimeout,
3356
3296
  onLog,
3357
- onError
3297
+ onError,
3298
+ buildClientContext
3358
3299
  } = {}) {
3359
3300
  this.isInitialized = false;
3360
3301
  this.page = (data, options) => __awaiter(this, void 0, void 0, function* () {
@@ -3401,28 +3342,6 @@ class Ninetailed {
3401
3342
  type: HAS_SEEN_EXPERIENCE
3402
3343
  }));
3403
3344
  };
3404
- this.observeElement = (payload, options) => {
3405
- const {
3406
- element
3407
- } = payload,
3408
- remaingPayload = __rest(payload, ["element"]);
3409
- this.observedElements.set(element, remaingPayload);
3410
- this.elementSeenObserver.observe(element, options);
3411
- };
3412
- this.unobserveElement = element => {
3413
- this.observedElements.delete(element);
3414
- this.elementSeenObserver.unobserve(element);
3415
- };
3416
- this.onElementSeen = element => {
3417
- const payload = this.observedElements.get(element);
3418
- if (typeof payload !== 'undefined') {
3419
- this.instance.dispatch(Object.assign(Object.assign({
3420
- element
3421
- }, payload), {
3422
- type: HAS_SEEN_ELEMENT
3423
- }));
3424
- }
3425
- };
3426
3345
  this.identify = (uid, traits, options) => __awaiter(this, void 0, void 0, function* () {
3427
3346
  try {
3428
3347
  const result = Traits.default({}).safeParse(traits);
@@ -3490,18 +3409,6 @@ class Ninetailed {
3490
3409
  this.onIsInitialized(resolve);
3491
3410
  });
3492
3411
  };
3493
- this.onVisibilityChange = () => {
3494
- if (typeof document === 'undefined') {
3495
- return;
3496
- }
3497
- document.addEventListener('visibilitychange', () => {
3498
- if (document.visibilityState === 'hidden') {
3499
- this.instance.dispatch({
3500
- type: PAGE_HIDDEN
3501
- });
3502
- }
3503
- });
3504
- };
3505
3412
  if (ninetailedApiClientInstanceOrOptions instanceof NinetailedApiClient) {
3506
3413
  this.apiClient = ninetailedApiClientInstanceOrOptions;
3507
3414
  } else {
@@ -3519,15 +3426,15 @@ class Ninetailed {
3519
3426
  preview
3520
3427
  });
3521
3428
  }
3522
- this.plugins = (plugins !== null && plugins !== void 0 ? plugins : []).flat();
3523
- this.plugins.forEach(plugin => {
3524
- if (acceptsCredentials(plugin) && this.clientId && this.environment) {
3525
- plugin.setCredentials({
3429
+ this.plugins = [...(plugins || []).map(plugin => {
3430
+ if ('setCredentials' in plugin && typeof plugin['setCredentials'] === 'function') {
3431
+ plugin['setCredentials']({
3526
3432
  clientId: this.clientId,
3527
3433
  environment: this.environment
3528
3434
  });
3529
3435
  }
3530
- });
3436
+ return plugin;
3437
+ }).flat()];
3531
3438
  if (profile) {
3532
3439
  this._profileState = {
3533
3440
  status: 'success',
@@ -3555,6 +3462,7 @@ class Ninetailed {
3555
3462
  profile,
3556
3463
  locale,
3557
3464
  requestTimeout,
3465
+ buildClientContext,
3558
3466
  ninetailed: this
3559
3467
  });
3560
3468
  this.instance = Analytics({
@@ -3575,14 +3483,6 @@ class Ninetailed {
3575
3483
  });
3576
3484
  }
3577
3485
  });
3578
- this.observedElements = new WeakMap();
3579
- this.elementSeenObserver = new ElementSeenObserver({
3580
- onElementSeen: this.onElementSeen.bind(this)
3581
- });
3582
- const hasPluginsInterestedInHiddenPage = this.plugins.some(isInterestedInHiddenPage);
3583
- if (hasPluginsInterestedInHiddenPage) {
3584
- this.onVisibilityChange();
3585
- }
3586
3486
  this.registerWindowHandlers();
3587
3487
  }
3588
3488
  get profileState() {
@@ -3981,4 +3881,4 @@ const makeExperienceSelectMiddleware = ({
3981
3881
  };
3982
3882
  };
3983
3883
 
3984
- export { ANONYMOUS_ID, CONSENT, DEBUG_FLAG, EMPTY_MERGE_ID, HAS_SEEN_COMPONENT, HAS_SEEN_ELEMENT, HAS_SEEN_EXPERIENCE, LEGACY_ANONYMOUS_ID, Ninetailed, NinetailedPlugin, OnChangeEmitter, PAGE_HIDDEN, PLUGIN_NAME, PROFILE_CHANGE, PROFILE_FALLBACK_CACHE, PROFILE_RESET, SET_ENABLED_FEATURES, TrackComponentProperties, TrackExperienceProperties, buildClientNinetailedRequestContext, decodeExperienceVariantsMap, makeExperienceSelectMiddleware, ninetailedPlugin, selectPluginsHavingExperienceSelectionMiddleware, selectPluginsHavingOnChangeEmitter, selectVariant };
3884
+ export { ANONYMOUS_ID, CONSENT, DEBUG_FLAG, EMPTY_MERGE_ID, HAS_SEEN_COMPONENT, HAS_SEEN_EXPERIENCE, LEGACY_ANONYMOUS_ID, Ninetailed, NinetailedPlugin, OnChangeEmitter, PLUGIN_NAME, PROFILE_CHANGE, PROFILE_FALLBACK_CACHE, PROFILE_RESET, SET_ENABLED_FEATURES, TrackComponentProperties, TrackExperienceProperties, decodeExperienceVariantsMap, makeExperienceSelectMiddleware, ninetailedPlugin, selectPluginsHavingExperienceSelectionMiddleware, selectPluginsHavingOnChangeEmitter, selectVariant };
@@ -1,7 +1,6 @@
1
1
  /// <reference types="analytics" />
2
- import { Locale, Traits, Profile, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions } from '@ninetailed/experience.js-shared';
3
- import { EventFunctionOptions, NinetailedInstance, NinetailedPlugin, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackHasSeenExperience, ElementSeenPayload } from './types';
4
- import { ObserveOptions } from './ElementSeenObserver';
2
+ import { Locale, Traits, Profile, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
3
+ import { EventFunctionOptions, NinetailedInstance, NinetailedPlugin, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackHasSeenExperience } from './types';
5
4
  declare global {
6
5
  interface Window {
7
6
  ninetailed?: {
@@ -20,6 +19,7 @@ type Options = {
20
19
  requestTimeout?: number;
21
20
  onLog?: OnLogHandler;
22
21
  onError?: OnErrorHandler;
22
+ buildClientContext?: () => NinetailedRequestContext;
23
23
  };
24
24
  type NinetailedApiClientInstanceOrOptions = NinetailedApiClient | NinetailedApiClientOptions;
25
25
  export declare class Ninetailed implements NinetailedInstance {
@@ -28,20 +28,15 @@ export declare class Ninetailed implements NinetailedInstance {
28
28
  private isInitialized;
29
29
  private readonly apiClient;
30
30
  private readonly eventQueue;
31
- private readonly elementSeenObserver;
32
- private readonly observedElements;
33
31
  private readonly clientId;
34
32
  private readonly environment;
35
33
  readonly plugins: NinetailedPlugin[];
36
34
  readonly logger: Logger;
37
- constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, profile, locale, requestTimeout, onLog, onError, }?: Options);
35
+ constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, profile, locale, requestTimeout, onLog, onError, buildClientContext, }?: Options);
38
36
  page: (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
39
37
  track: (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
40
38
  trackHasSeenComponent: TrackHasSeenComponent;
41
39
  trackHasSeenExperience: TrackHasSeenExperience;
42
- observeElement: (payload: ElementSeenPayload, options?: ObserveOptions) => void;
43
- unobserveElement: (element: Element) => void;
44
- private onElementSeen;
45
40
  identify: (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
46
41
  reset: () => Promise<void>;
47
42
  debug: (enabled: boolean) => Promise<void>;
@@ -51,6 +46,5 @@ export declare class Ninetailed implements NinetailedInstance {
51
46
  get profileState(): ProfileState;
52
47
  private buildOptions;
53
48
  private registerWindowHandlers;
54
- private onVisibilityChange;
55
49
  }
56
50
  export {};
@@ -1,16 +1,17 @@
1
1
  import { AnalyticsPlugin } from 'analytics';
2
- import { Profile, Locale, NinetailedApiClient } from '@ninetailed/experience.js-shared';
2
+ import { Profile, Locale, NinetailedApiClient, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
3
3
  import { NinetailedInstance, FlushResult } from '../types';
4
4
  type AnalyticsPluginNinetailedConfig = {
5
5
  apiClient: NinetailedApiClient;
6
6
  profile?: Profile;
7
7
  locale?: Locale;
8
8
  requestTimeout?: number;
9
+ buildClientContext?: () => NinetailedRequestContext;
9
10
  ninetailed: NinetailedInstance;
10
11
  };
11
12
  export declare const PLUGIN_NAME = "ninetailed";
12
13
  export interface NinetailedEventQueue extends AnalyticsPlugin {
13
14
  flush: () => Promise<FlushResult>;
14
15
  }
15
- export declare const ninetailedPlugin: ({ apiClient, profile, locale, ninetailed, }: AnalyticsPluginNinetailedConfig) => NinetailedEventQueue;
16
+ export declare const ninetailedPlugin: ({ apiClient, profile, locale, ninetailed, buildClientContext, }: AnalyticsPluginNinetailedConfig) => NinetailedEventQueue;
16
17
  export {};
@@ -1,3 +1,2 @@
1
1
  export * from './get-analytics-plugin';
2
2
  export * from './constants';
3
- export * from './Events';
@@ -1,4 +1,2 @@
1
1
  export declare const HAS_SEEN_EXPERIENCE = "has_seen_experience";
2
2
  export declare const HAS_SEEN_COMPONENT = "has_seen_component";
3
- export declare const HAS_SEEN_ELEMENT = "has_seen_element";
4
- export declare const PAGE_HIDDEN = "page_hidden";