@ninetailed/experience.js 7.11.1 → 7.12.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 +62 -3
- package/index.esm.js +63 -4
- package/package.json +3 -3
- package/src/lib/Ninetailed.d.ts +13 -1
- package/src/lib/NinetailedCorePlugin/NinetailedCorePlugin.d.ts +3 -0
- package/src/lib/NinetailedCorePlugin/actions.d.ts +3 -1
- package/src/lib/NinetailedCorePlugin/constants.d.ts +1 -0
- package/src/lib/types/index.d.ts +20 -1
package/index.cjs.js
CHANGED
|
@@ -98,6 +98,7 @@ const ANONYMOUS_ID = '__nt_anonymous_id__';
|
|
|
98
98
|
const DEBUG_FLAG = '__nt_debug__';
|
|
99
99
|
const PROFILE_FALLBACK_CACHE = '__nt_profile__';
|
|
100
100
|
const EXPERIENCES_FALLBACK_CACHE = '__nt_experiences__';
|
|
101
|
+
const CHANGES_FALLBACK_CACHE = '__nt_changes__';
|
|
101
102
|
const PROFILE_CHANGE = 'profile-change';
|
|
102
103
|
const PROFILE_RESET = 'profile-reset';
|
|
103
104
|
const CONSENT = '__nt-consent__';
|
|
@@ -343,19 +344,31 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
343
344
|
clearFallbackExperiences() {
|
|
344
345
|
this.instance.storage.removeItem(EXPERIENCES_FALLBACK_CACHE);
|
|
345
346
|
}
|
|
347
|
+
setFallbackChanges(changes) {
|
|
348
|
+
this.instance.storage.setItem(CHANGES_FALLBACK_CACHE, changes);
|
|
349
|
+
}
|
|
350
|
+
getFallbackChanges() {
|
|
351
|
+
return this.instance.storage.getItem(CHANGES_FALLBACK_CACHE) || [];
|
|
352
|
+
}
|
|
353
|
+
clearFallbackChanges() {
|
|
354
|
+
this.instance.storage.removeItem(CHANGES_FALLBACK_CACHE);
|
|
355
|
+
}
|
|
346
356
|
clearCaches() {
|
|
347
357
|
this.clearAnonymousId();
|
|
348
358
|
this.clearFallbackProfile();
|
|
349
359
|
this.clearFallbackExperiences();
|
|
360
|
+
this.clearFallbackChanges();
|
|
350
361
|
}
|
|
351
362
|
populateCaches({
|
|
352
363
|
experiences,
|
|
353
364
|
profile,
|
|
354
|
-
anonymousId
|
|
365
|
+
anonymousId,
|
|
366
|
+
changes
|
|
355
367
|
}) {
|
|
356
368
|
this.setAnonymousId(anonymousId);
|
|
357
369
|
this.setFallbackProfile(profile);
|
|
358
370
|
this.setFallbackExperiences(experiences);
|
|
371
|
+
this.setFallbackChanges(changes);
|
|
359
372
|
}
|
|
360
373
|
_flush() {
|
|
361
374
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -371,7 +384,8 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
371
384
|
const anonymousId = this.getAnonymousId();
|
|
372
385
|
const {
|
|
373
386
|
profile,
|
|
374
|
-
experiences
|
|
387
|
+
experiences,
|
|
388
|
+
changes
|
|
375
389
|
} = yield this.apiClient.upsertProfile({
|
|
376
390
|
profileId: anonymousId,
|
|
377
391
|
events
|
|
@@ -382,7 +396,8 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
382
396
|
this.populateCaches({
|
|
383
397
|
anonymousId: profile.id,
|
|
384
398
|
profile,
|
|
385
|
-
experiences
|
|
399
|
+
experiences,
|
|
400
|
+
changes
|
|
386
401
|
});
|
|
387
402
|
experience_jsShared.logger.debug('Profile from api: ', profile);
|
|
388
403
|
experience_jsShared.logger.debug('Experiences from api: ', experiences);
|
|
@@ -390,6 +405,7 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
390
405
|
type: PROFILE_CHANGE,
|
|
391
406
|
profile,
|
|
392
407
|
experiences,
|
|
408
|
+
changes,
|
|
393
409
|
error: undefined
|
|
394
410
|
});
|
|
395
411
|
yield delay(20);
|
|
@@ -400,12 +416,14 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
400
416
|
experience_jsShared.logger.debug('An error occurred during flushing the events: ', error);
|
|
401
417
|
const fallbackProfile = this.getFallbackProfile();
|
|
402
418
|
const fallbackExperiences = this.getFallbackExperiences();
|
|
419
|
+
const fallbackChanges = this.getFallbackChanges();
|
|
403
420
|
if (fallbackProfile) {
|
|
404
421
|
experience_jsShared.logger.debug('Found a fallback profile - will use this.');
|
|
405
422
|
this.instance.dispatch({
|
|
406
423
|
type: PROFILE_CHANGE,
|
|
407
424
|
profile: fallbackProfile,
|
|
408
425
|
experiences: fallbackExperiences,
|
|
426
|
+
changes: fallbackChanges,
|
|
409
427
|
error: undefined
|
|
410
428
|
});
|
|
411
429
|
} else {
|
|
@@ -413,6 +431,7 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
413
431
|
this.instance.dispatch({
|
|
414
432
|
type: PROFILE_CHANGE,
|
|
415
433
|
profile: null,
|
|
434
|
+
changes: fallbackChanges,
|
|
416
435
|
experiences: fallbackExperiences,
|
|
417
436
|
error: error
|
|
418
437
|
});
|
|
@@ -850,6 +869,7 @@ class Ninetailed {
|
|
|
850
869
|
cb(Object.assign(Object.assign({}, this._profileState), {
|
|
851
870
|
status: 'success',
|
|
852
871
|
profile: payload.profile,
|
|
872
|
+
changes: payload.changes,
|
|
853
873
|
experiences: payload.experiences,
|
|
854
874
|
error: null
|
|
855
875
|
}));
|
|
@@ -1018,6 +1038,18 @@ class Ninetailed {
|
|
|
1018
1038
|
removeMiddlewareChangeListeners();
|
|
1019
1039
|
};
|
|
1020
1040
|
};
|
|
1041
|
+
/**
|
|
1042
|
+
* Registers a callback to be notified when changes occur in the profile state.
|
|
1043
|
+
*
|
|
1044
|
+
* @param cb - Callback function that receives the changes state
|
|
1045
|
+
* @returns Function to unsubscribe from changes updates
|
|
1046
|
+
*/
|
|
1047
|
+
this.onChangesChange = cb => {
|
|
1048
|
+
this.notifyChangesCallback(cb, this._profileState);
|
|
1049
|
+
return this.onProfileChange(profileState => {
|
|
1050
|
+
this.notifyChangesCallback(cb, profileState);
|
|
1051
|
+
});
|
|
1052
|
+
};
|
|
1021
1053
|
this.onIsInitialized = onIsInitializedCallback => {
|
|
1022
1054
|
if (typeof onIsInitializedCallback === 'function') {
|
|
1023
1055
|
if (this.isInitialized) {
|
|
@@ -1105,6 +1137,7 @@ class Ninetailed {
|
|
|
1105
1137
|
status: 'loading',
|
|
1106
1138
|
profile: null,
|
|
1107
1139
|
experiences: null,
|
|
1140
|
+
changes: null,
|
|
1108
1141
|
error: null,
|
|
1109
1142
|
from: 'api'
|
|
1110
1143
|
};
|
|
@@ -1179,6 +1212,31 @@ class Ninetailed {
|
|
|
1179
1212
|
});
|
|
1180
1213
|
});
|
|
1181
1214
|
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Helper method to extract changes state from profile state and notify callback
|
|
1217
|
+
* @private
|
|
1218
|
+
*/
|
|
1219
|
+
notifyChangesCallback(cb, profileState) {
|
|
1220
|
+
if (profileState.status === 'loading') {
|
|
1221
|
+
cb({
|
|
1222
|
+
status: 'loading',
|
|
1223
|
+
changes: null,
|
|
1224
|
+
error: null
|
|
1225
|
+
});
|
|
1226
|
+
} else if (profileState.status === 'error') {
|
|
1227
|
+
cb({
|
|
1228
|
+
status: 'error',
|
|
1229
|
+
changes: null,
|
|
1230
|
+
error: profileState.error
|
|
1231
|
+
});
|
|
1232
|
+
} else {
|
|
1233
|
+
cb({
|
|
1234
|
+
status: 'success',
|
|
1235
|
+
changes: profileState.changes,
|
|
1236
|
+
error: null
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1182
1240
|
// Always throws, never returns
|
|
1183
1241
|
handleMethodError(error, method) {
|
|
1184
1242
|
experience_jsShared.logger.error(error);
|
|
@@ -1332,6 +1390,7 @@ Object.defineProperty(exports, 'selectHasExperienceVariants', {
|
|
|
1332
1390
|
get: function () { return experience_jsShared.selectHasVariants; }
|
|
1333
1391
|
});
|
|
1334
1392
|
exports.ANONYMOUS_ID = ANONYMOUS_ID;
|
|
1393
|
+
exports.CHANGES_FALLBACK_CACHE = CHANGES_FALLBACK_CACHE;
|
|
1335
1394
|
exports.COMPONENT = COMPONENT;
|
|
1336
1395
|
exports.COMPONENT_START = COMPONENT_START;
|
|
1337
1396
|
exports.CONSENT = CONSENT;
|
package/index.esm.js
CHANGED
|
@@ -54,6 +54,7 @@ const ANONYMOUS_ID = '__nt_anonymous_id__';
|
|
|
54
54
|
const DEBUG_FLAG = '__nt_debug__';
|
|
55
55
|
const PROFILE_FALLBACK_CACHE = '__nt_profile__';
|
|
56
56
|
const EXPERIENCES_FALLBACK_CACHE = '__nt_experiences__';
|
|
57
|
+
const CHANGES_FALLBACK_CACHE = '__nt_changes__';
|
|
57
58
|
const PROFILE_CHANGE = 'profile-change';
|
|
58
59
|
const PROFILE_RESET = 'profile-reset';
|
|
59
60
|
const CONSENT = '__nt-consent__';
|
|
@@ -294,19 +295,31 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
294
295
|
clearFallbackExperiences() {
|
|
295
296
|
this.instance.storage.removeItem(EXPERIENCES_FALLBACK_CACHE);
|
|
296
297
|
}
|
|
298
|
+
setFallbackChanges(changes) {
|
|
299
|
+
this.instance.storage.setItem(CHANGES_FALLBACK_CACHE, changes);
|
|
300
|
+
}
|
|
301
|
+
getFallbackChanges() {
|
|
302
|
+
return this.instance.storage.getItem(CHANGES_FALLBACK_CACHE) || [];
|
|
303
|
+
}
|
|
304
|
+
clearFallbackChanges() {
|
|
305
|
+
this.instance.storage.removeItem(CHANGES_FALLBACK_CACHE);
|
|
306
|
+
}
|
|
297
307
|
clearCaches() {
|
|
298
308
|
this.clearAnonymousId();
|
|
299
309
|
this.clearFallbackProfile();
|
|
300
310
|
this.clearFallbackExperiences();
|
|
311
|
+
this.clearFallbackChanges();
|
|
301
312
|
}
|
|
302
313
|
populateCaches({
|
|
303
314
|
experiences,
|
|
304
315
|
profile,
|
|
305
|
-
anonymousId
|
|
316
|
+
anonymousId,
|
|
317
|
+
changes
|
|
306
318
|
}) {
|
|
307
319
|
this.setAnonymousId(anonymousId);
|
|
308
320
|
this.setFallbackProfile(profile);
|
|
309
321
|
this.setFallbackExperiences(experiences);
|
|
322
|
+
this.setFallbackChanges(changes);
|
|
310
323
|
}
|
|
311
324
|
async _flush() {
|
|
312
325
|
const events = Object.assign([], this.queue);
|
|
@@ -321,7 +334,8 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
321
334
|
const anonymousId = this.getAnonymousId();
|
|
322
335
|
const {
|
|
323
336
|
profile,
|
|
324
|
-
experiences
|
|
337
|
+
experiences,
|
|
338
|
+
changes
|
|
325
339
|
} = await this.apiClient.upsertProfile({
|
|
326
340
|
profileId: anonymousId,
|
|
327
341
|
events
|
|
@@ -332,7 +346,8 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
332
346
|
this.populateCaches({
|
|
333
347
|
anonymousId: profile.id,
|
|
334
348
|
profile,
|
|
335
|
-
experiences
|
|
349
|
+
experiences,
|
|
350
|
+
changes
|
|
336
351
|
});
|
|
337
352
|
logger.debug('Profile from api: ', profile);
|
|
338
353
|
logger.debug('Experiences from api: ', experiences);
|
|
@@ -340,6 +355,7 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
340
355
|
type: PROFILE_CHANGE,
|
|
341
356
|
profile,
|
|
342
357
|
experiences,
|
|
358
|
+
changes,
|
|
343
359
|
error: undefined
|
|
344
360
|
});
|
|
345
361
|
await delay(20);
|
|
@@ -350,12 +366,14 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
350
366
|
logger.debug('An error occurred during flushing the events: ', error);
|
|
351
367
|
const fallbackProfile = this.getFallbackProfile();
|
|
352
368
|
const fallbackExperiences = this.getFallbackExperiences();
|
|
369
|
+
const fallbackChanges = this.getFallbackChanges();
|
|
353
370
|
if (fallbackProfile) {
|
|
354
371
|
logger.debug('Found a fallback profile - will use this.');
|
|
355
372
|
this.instance.dispatch({
|
|
356
373
|
type: PROFILE_CHANGE,
|
|
357
374
|
profile: fallbackProfile,
|
|
358
375
|
experiences: fallbackExperiences,
|
|
376
|
+
changes: fallbackChanges,
|
|
359
377
|
error: undefined
|
|
360
378
|
});
|
|
361
379
|
} else {
|
|
@@ -363,6 +381,7 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
363
381
|
this.instance.dispatch({
|
|
364
382
|
type: PROFILE_CHANGE,
|
|
365
383
|
profile: null,
|
|
384
|
+
changes: fallbackChanges,
|
|
366
385
|
experiences: fallbackExperiences,
|
|
367
386
|
error: error
|
|
368
387
|
});
|
|
@@ -833,6 +852,7 @@ class Ninetailed {
|
|
|
833
852
|
cb(Object.assign({}, this._profileState, {
|
|
834
853
|
status: 'success',
|
|
835
854
|
profile: payload.profile,
|
|
855
|
+
changes: payload.changes,
|
|
836
856
|
experiences: payload.experiences,
|
|
837
857
|
error: null
|
|
838
858
|
}));
|
|
@@ -1001,6 +1021,18 @@ class Ninetailed {
|
|
|
1001
1021
|
removeMiddlewareChangeListeners();
|
|
1002
1022
|
};
|
|
1003
1023
|
};
|
|
1024
|
+
/**
|
|
1025
|
+
* Registers a callback to be notified when changes occur in the profile state.
|
|
1026
|
+
*
|
|
1027
|
+
* @param cb - Callback function that receives the changes state
|
|
1028
|
+
* @returns Function to unsubscribe from changes updates
|
|
1029
|
+
*/
|
|
1030
|
+
this.onChangesChange = cb => {
|
|
1031
|
+
this.notifyChangesCallback(cb, this._profileState);
|
|
1032
|
+
return this.onProfileChange(profileState => {
|
|
1033
|
+
this.notifyChangesCallback(cb, profileState);
|
|
1034
|
+
});
|
|
1035
|
+
};
|
|
1004
1036
|
this.onIsInitialized = onIsInitializedCallback => {
|
|
1005
1037
|
if (typeof onIsInitializedCallback === 'function') {
|
|
1006
1038
|
if (this.isInitialized) {
|
|
@@ -1088,6 +1120,7 @@ class Ninetailed {
|
|
|
1088
1120
|
status: 'loading',
|
|
1089
1121
|
profile: null,
|
|
1090
1122
|
experiences: null,
|
|
1123
|
+
changes: null,
|
|
1091
1124
|
error: null,
|
|
1092
1125
|
from: 'api'
|
|
1093
1126
|
};
|
|
@@ -1167,6 +1200,32 @@ class Ninetailed {
|
|
|
1167
1200
|
});
|
|
1168
1201
|
});
|
|
1169
1202
|
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Helper method to extract changes state from profile state and notify callback
|
|
1205
|
+
* @private
|
|
1206
|
+
*/
|
|
1207
|
+
notifyChangesCallback(cb, profileState) {
|
|
1208
|
+
if (profileState.status === 'loading') {
|
|
1209
|
+
cb({
|
|
1210
|
+
status: 'loading',
|
|
1211
|
+
changes: null,
|
|
1212
|
+
error: null
|
|
1213
|
+
});
|
|
1214
|
+
} else if (profileState.status === 'error') {
|
|
1215
|
+
cb({
|
|
1216
|
+
status: 'error',
|
|
1217
|
+
changes: null,
|
|
1218
|
+
error: profileState.error
|
|
1219
|
+
});
|
|
1220
|
+
} else {
|
|
1221
|
+
cb({
|
|
1222
|
+
status: 'success',
|
|
1223
|
+
changes: profileState.changes,
|
|
1224
|
+
error: null
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1170
1229
|
// Always throws, never returns
|
|
1171
1230
|
handleMethodError(error, method) {
|
|
1172
1231
|
logger.error(error);
|
|
@@ -1284,4 +1343,4 @@ const selectVariant = (baseline, variants, {
|
|
|
1284
1343
|
};
|
|
1285
1344
|
};
|
|
1286
1345
|
|
|
1287
|
-
export { ANONYMOUS_ID, COMPONENT, COMPONENT_START, CONSENT, DEBUG_FLAG, EMPTY_MERGE_ID, EXPERIENCES_FALLBACK_CACHE, EventBuilder, HAS_SEEN_STICKY_COMPONENT, LEGACY_ANONYMOUS_ID, Ninetailed, NinetailedCorePlugin, OnChangeEmitter, PAGE_HIDDEN, PLUGIN_NAME, PROFILE_CHANGE, PROFILE_FALLBACK_CACHE, PROFILE_RESET, SET_ENABLED_FEATURES, buildClientNinetailedRequestContext, decodeExperienceVariantsMap, makeExperienceSelectMiddleware, selectPluginsHavingExperienceSelectionMiddleware, selectPluginsHavingOnChangeEmitter, selectVariant };
|
|
1346
|
+
export { ANONYMOUS_ID, CHANGES_FALLBACK_CACHE, COMPONENT, COMPONENT_START, CONSENT, DEBUG_FLAG, EMPTY_MERGE_ID, EXPERIENCES_FALLBACK_CACHE, EventBuilder, HAS_SEEN_STICKY_COMPONENT, LEGACY_ANONYMOUS_ID, Ninetailed, NinetailedCorePlugin, OnChangeEmitter, PAGE_HIDDEN, PLUGIN_NAME, PROFILE_CHANGE, PROFILE_FALLBACK_CACHE, PROFILE_RESET, SET_ENABLED_FEATURES, buildClientNinetailedRequestContext, decodeExperienceVariantsMap, makeExperienceSelectMiddleware, selectPluginsHavingExperienceSelectionMiddleware, selectPluginsHavingOnChangeEmitter, selectVariant };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.12.0",
|
|
4
4
|
"description": "Ninetailed SDK for javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"directory": "packages/sdks/javascript"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@ninetailed/experience.js-plugin-analytics": "7.
|
|
13
|
-
"@ninetailed/experience.js-shared": "7.
|
|
12
|
+
"@ninetailed/experience.js-plugin-analytics": "7.12.0",
|
|
13
|
+
"@ninetailed/experience.js-shared": "7.12.0",
|
|
14
14
|
"analytics": "0.8.1",
|
|
15
15
|
"uuid": "9.0.0"
|
|
16
16
|
},
|
package/src/lib/Ninetailed.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="analytics" />
|
|
2
2
|
import { Locale, Traits, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions, NinetailedRequestContext, Reference, Event } from '@ninetailed/experience.js-shared';
|
|
3
3
|
import { OnInitProfileId } from './NinetailedCorePlugin';
|
|
4
|
-
import { EventFunctionOptions, NinetailedInstance, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackComponentView } from './types';
|
|
4
|
+
import { EventFunctionOptions, NinetailedInstance, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackComponentView, OnChangesChangeCallback } from './types';
|
|
5
5
|
import { ObserveOptions } from './ElementSeenObserver';
|
|
6
6
|
import { OnSelectVariantArgs, OnSelectVariantCallback } from './types/OnSelectVariant';
|
|
7
7
|
import { ElementSeenPayload, NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
|
|
@@ -80,6 +80,18 @@ export declare class Ninetailed implements NinetailedInstance {
|
|
|
80
80
|
debug: (enabled: boolean) => Promise<void>;
|
|
81
81
|
onProfileChange: (cb: OnProfileChangeCallback) => import("analytics").DetachListeners;
|
|
82
82
|
onSelectVariant: <Baseline extends Reference, Variant extends Reference>({ baseline, experiences }: OnSelectVariantArgs<Baseline, Variant>, cb: OnSelectVariantCallback<Baseline, Variant>) => () => void;
|
|
83
|
+
/**
|
|
84
|
+
* Registers a callback to be notified when changes occur in the profile state.
|
|
85
|
+
*
|
|
86
|
+
* @param cb - Callback function that receives the changes state
|
|
87
|
+
* @returns Function to unsubscribe from changes updates
|
|
88
|
+
*/
|
|
89
|
+
onChangesChange: (cb: OnChangesChangeCallback) => import("analytics").DetachListeners;
|
|
90
|
+
/**
|
|
91
|
+
* Helper method to extract changes state from profile state and notify callback
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
private notifyChangesCallback;
|
|
83
95
|
private handleMethodError;
|
|
84
96
|
onIsInitialized: (onIsInitializedCallback: OnIsInitializedCallback) => void;
|
|
85
97
|
private waitUntilInitialized;
|
|
@@ -76,6 +76,9 @@ export declare class NinetailedCorePlugin extends NinetailedAnalyticsPlugin impl
|
|
|
76
76
|
private setFallbackExperiences;
|
|
77
77
|
private getFallbackExperiences;
|
|
78
78
|
private clearFallbackExperiences;
|
|
79
|
+
private setFallbackChanges;
|
|
80
|
+
private getFallbackChanges;
|
|
81
|
+
private clearFallbackChanges;
|
|
79
82
|
private clearCaches;
|
|
80
83
|
private populateCaches;
|
|
81
84
|
private _flush;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HAS_SEEN_COMPONENT, HAS_SEEN_ELEMENT } from '@ninetailed/experience.js-plugin-analytics';
|
|
2
|
-
import { PROFILE_CHANGE, Profile, SelectedVariantInfo, PROFILE_RESET } from '@ninetailed/experience.js-shared';
|
|
2
|
+
import { PROFILE_CHANGE, Profile, SelectedVariantInfo, PROFILE_RESET, Change } from '@ninetailed/experience.js-shared';
|
|
3
3
|
import { HAS_SEEN_STICKY_COMPONENT, PAGE_HIDDEN } from '../constants';
|
|
4
4
|
type ReadyAction = {
|
|
5
5
|
type: 'ready';
|
|
@@ -16,11 +16,13 @@ type ProfileChangeAction = {
|
|
|
16
16
|
type: typeof PROFILE_CHANGE;
|
|
17
17
|
profile: Profile;
|
|
18
18
|
experiences: SelectedVariantInfo[];
|
|
19
|
+
changes: Change[];
|
|
19
20
|
error: undefined | null;
|
|
20
21
|
} | {
|
|
21
22
|
type: typeof PROFILE_CHANGE;
|
|
22
23
|
profile: Profile | null;
|
|
23
24
|
experiences: SelectedVariantInfo[];
|
|
25
|
+
changes: Change[];
|
|
24
26
|
error: Error;
|
|
25
27
|
};
|
|
26
28
|
type ProfileResetAction = {
|
|
@@ -3,6 +3,7 @@ export declare const ANONYMOUS_ID = "__nt_anonymous_id__";
|
|
|
3
3
|
export declare const DEBUG_FLAG = "__nt_debug__";
|
|
4
4
|
export declare const PROFILE_FALLBACK_CACHE = "__nt_profile__";
|
|
5
5
|
export declare const EXPERIENCES_FALLBACK_CACHE = "__nt_experiences__";
|
|
6
|
+
export declare const CHANGES_FALLBACK_CACHE = "__nt_changes__";
|
|
6
7
|
export declare const PROFILE_CHANGE = "profile-change";
|
|
7
8
|
export declare const PROFILE_RESET = "profile-reset";
|
|
8
9
|
export declare const CONSENT = "__nt-consent__";
|
package/src/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DetachListeners } from 'analytics';
|
|
2
|
-
import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo, Reference, Event } from '@ninetailed/experience.js-shared';
|
|
2
|
+
import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo, Reference, Event, Change } from '@ninetailed/experience.js-shared';
|
|
3
3
|
import { ElementSeenPayload, NinetailedPlugin, TrackComponentProperties } from '@ninetailed/experience.js-plugin-analytics';
|
|
4
4
|
import { type Ninetailed } from '../Ninetailed';
|
|
5
5
|
import { OnSelectVariant } from './OnSelectVariant';
|
|
@@ -8,21 +8,37 @@ export type ProfileState = {
|
|
|
8
8
|
status: 'loading';
|
|
9
9
|
profile: null;
|
|
10
10
|
experiences: null;
|
|
11
|
+
changes: null;
|
|
11
12
|
error: null;
|
|
12
13
|
from: 'api' | 'hydrated';
|
|
13
14
|
} | {
|
|
14
15
|
status: 'success';
|
|
15
16
|
profile: Profile;
|
|
16
17
|
experiences: SelectedVariantInfo[];
|
|
18
|
+
changes: Change[];
|
|
17
19
|
error: null;
|
|
18
20
|
from: 'api' | 'hydrated';
|
|
19
21
|
} | {
|
|
20
22
|
status: 'error';
|
|
21
23
|
profile: Profile | null;
|
|
22
24
|
experiences: SelectedVariantInfo[] | null;
|
|
25
|
+
changes: Change[] | null;
|
|
23
26
|
error: Error;
|
|
24
27
|
from: 'api' | 'hydrated';
|
|
25
28
|
};
|
|
29
|
+
export type ChangesState = {
|
|
30
|
+
status: 'loading';
|
|
31
|
+
changes: null;
|
|
32
|
+
error: null;
|
|
33
|
+
} | {
|
|
34
|
+
status: 'success';
|
|
35
|
+
changes: Change[];
|
|
36
|
+
error: null;
|
|
37
|
+
} | {
|
|
38
|
+
status: 'error';
|
|
39
|
+
changes: null;
|
|
40
|
+
error: Error;
|
|
41
|
+
};
|
|
26
42
|
export type OnIsInitializedCallback = () => void;
|
|
27
43
|
export type OnIsInitialized = (cb: OnIsInitializedCallback) => void;
|
|
28
44
|
export type EventFunctionOptions = {
|
|
@@ -42,6 +58,7 @@ export type Result<T> = {
|
|
|
42
58
|
error: Error;
|
|
43
59
|
};
|
|
44
60
|
export type OnProfileChangeCallback = (profile: ProfileState) => void;
|
|
61
|
+
export type OnChangesChangeCallback = (changesState: ChangesState) => void;
|
|
45
62
|
export type Page = (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<FlushResult>;
|
|
46
63
|
export type Track = (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<FlushResult>;
|
|
47
64
|
export type TrackHasSeenComponent = (properties: TrackComponentProperties) => Promise<void>;
|
|
@@ -51,6 +68,7 @@ export type Batch = (events: Event[]) => Promise<FlushResult>;
|
|
|
51
68
|
export type Reset = () => void;
|
|
52
69
|
export type Debug = (enable: boolean) => void;
|
|
53
70
|
export type OnProfileChange = (cb: OnProfileChangeCallback) => DetachListeners;
|
|
71
|
+
export type OnChangesChange = (cb: OnChangesChangeCallback) => DetachListeners;
|
|
54
72
|
type ObserveElement = Ninetailed['observeElement'];
|
|
55
73
|
type UnObserveElement = Ninetailed['unobserveElement'];
|
|
56
74
|
export interface NinetailedInstance<TBaseline extends Reference = Reference, TVariant extends Reference = Reference> {
|
|
@@ -67,6 +85,7 @@ export interface NinetailedInstance<TBaseline extends Reference = Reference, TVa
|
|
|
67
85
|
debug: Debug;
|
|
68
86
|
profileState: ProfileState;
|
|
69
87
|
onProfileChange: OnProfileChange;
|
|
88
|
+
onChangesChange: OnChangesChange;
|
|
70
89
|
plugins: NinetailedPlugin[];
|
|
71
90
|
logger: Logger;
|
|
72
91
|
eventBuilder: EventBuilder;
|