@ninetailed/experience.js 7.13.0-beta.1 → 7.14.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 +14 -1
- package/index.esm.js +19 -3
- package/package.json +3 -3
- package/src/index.d.ts +1 -0
- package/src/lib/Ninetailed.d.ts +2 -1
- package/src/lib/NinetailedCorePlugin/actions.d.ts +7 -3
- package/src/lib/types/index.d.ts +3 -1
- package/src/lib/types/interfaces/InterestedInSeenVariables.d.ts +4 -0
- package/src/lib/utils/EventBuilder.d.ts +3 -1
package/index.cjs.js
CHANGED
|
@@ -137,12 +137,14 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
137
137
|
messageId: payload.meta.rid,
|
|
138
138
|
timestamp: payload.meta.ts,
|
|
139
139
|
componentId: payload.componentId,
|
|
140
|
+
componentType: payload.componentType,
|
|
140
141
|
experienceId: payload.experienceId,
|
|
141
142
|
variantIndex: payload.variantIndex,
|
|
142
143
|
ctx
|
|
143
144
|
}));
|
|
144
145
|
});
|
|
145
146
|
this.methods = {
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
146
148
|
reset: (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
147
149
|
experience_jsShared.logger.debug('Resetting profile.');
|
|
148
150
|
const instance = args[args.length - 1];
|
|
@@ -161,6 +163,7 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
161
163
|
experience_jsShared.logger.info('Profile reset successful.');
|
|
162
164
|
yield delay(10);
|
|
163
165
|
}),
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
164
167
|
debug: (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
165
168
|
const enabled = args[0];
|
|
166
169
|
const instance = args[args.length - 1];
|
|
@@ -286,6 +289,7 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
|
|
|
286
289
|
onTrackComponent() {
|
|
287
290
|
return Promise.resolve();
|
|
288
291
|
}
|
|
292
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
289
293
|
setItemStart({
|
|
290
294
|
abort,
|
|
291
295
|
payload
|
|
@@ -764,9 +768,10 @@ class EventBuilder {
|
|
|
764
768
|
userId: userId || ''
|
|
765
769
|
}));
|
|
766
770
|
}
|
|
767
|
-
component(componentId, experienceId, variantIndex, data) {
|
|
771
|
+
component(componentId, componentType, experienceId, variantIndex, data) {
|
|
768
772
|
return experience_jsShared.buildComponentViewEvent(Object.assign(Object.assign({}, this.buildEventBase(data)), {
|
|
769
773
|
componentId,
|
|
774
|
+
componentType: componentType || 'Entry',
|
|
770
775
|
experienceId: experienceId || '',
|
|
771
776
|
variantIndex: variantIndex || 0
|
|
772
777
|
}));
|
|
@@ -910,6 +915,13 @@ class Ninetailed {
|
|
|
910
915
|
type: experience_jsPluginAnalytics.HAS_SEEN_COMPONENT
|
|
911
916
|
}));
|
|
912
917
|
});
|
|
918
|
+
this.trackVariableComponentView = properties => {
|
|
919
|
+
const validatedVariable = experience_jsShared.SerializableObject.parse(properties.variable);
|
|
920
|
+
return this.instance.dispatch(Object.assign(Object.assign({}, properties), {
|
|
921
|
+
type: experience_jsPluginAnalytics.HAS_SEEN_VARIABLE,
|
|
922
|
+
variable: validatedVariable
|
|
923
|
+
}));
|
|
924
|
+
};
|
|
913
925
|
this.trackComponentView = properties => {
|
|
914
926
|
return this.instance.dispatch(Object.assign(Object.assign({}, properties), {
|
|
915
927
|
type: experience_jsPluginAnalytics.HAS_SEEN_ELEMENT,
|
|
@@ -1352,6 +1364,7 @@ class Ninetailed {
|
|
|
1352
1364
|
}
|
|
1353
1365
|
logInvalidElement(element) {
|
|
1354
1366
|
const isObject = typeof element === 'object' && element !== null;
|
|
1367
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1355
1368
|
const constructorName = isObject ? element.constructor.name : '';
|
|
1356
1369
|
const isConstructorNameNotObject = constructorName && constructorName !== 'Object';
|
|
1357
1370
|
experience_jsShared.logger.warn(`ElementSeenObserver.observeElement was called with an invalid element. Expected an Element but got ${typeof element}${isConstructorNameNotObject ? ` of type ${constructorName}` : ''}. This call will be ignored.`);
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FEATURES, buildComponentViewEvent, logger, ConsoleLogSink, buildPageEvent, buildTrackEvent, buildIdentifyEvent, unionBy, pipe, PageviewProperties, Properties, Traits, isPageViewEvent, isTrackEvent, isIdentifyEvent, isComponentViewEvent, selectHasVariants, selectExperience, selectVariant as selectVariant$1, selectBaselineWithVariants, OnLogLogSink, OnErrorLogSink, NinetailedApiClient } from '@ninetailed/experience.js-shared';
|
|
1
|
+
import { FEATURES, buildComponentViewEvent, logger, ConsoleLogSink, buildPageEvent, buildTrackEvent, buildIdentifyEvent, unionBy, pipe, PageviewProperties, Properties, Traits, isPageViewEvent, isTrackEvent, isIdentifyEvent, isComponentViewEvent, SerializableObject, selectHasVariants, selectExperience, selectVariant as selectVariant$1, selectBaselineWithVariants, OnLogLogSink, OnErrorLogSink, NinetailedApiClient } from '@ninetailed/experience.js-shared';
|
|
2
2
|
export { EXPERIENCE_TRAIT_PREFIX, isExperienceMatch, selectActiveExperiments, selectDistribution, selectExperience, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectVariant as selectExperienceVariant, selectVariants as selectExperienceVariants, selectHasVariants as selectHasExperienceVariants } from '@ninetailed/experience.js-shared';
|
|
3
|
-
import { NinetailedAnalyticsPlugin, HAS_SEEN_COMPONENT, HAS_SEEN_ELEMENT, hasComponentViewTrackingThreshold } from '@ninetailed/experience.js-plugin-analytics';
|
|
3
|
+
import { NinetailedAnalyticsPlugin, HAS_SEEN_COMPONENT, HAS_SEEN_VARIABLE, HAS_SEEN_ELEMENT, hasComponentViewTrackingThreshold } from '@ninetailed/experience.js-plugin-analytics';
|
|
4
4
|
import Analytics from 'analytics';
|
|
5
5
|
import { v4 } from 'uuid';
|
|
6
6
|
|
|
@@ -62,6 +62,9 @@ const SET_ENABLED_FEATURES = 'setEnabledFeatures';
|
|
|
62
62
|
const EMPTY_MERGE_ID = 'nt:empty-merge-id';
|
|
63
63
|
|
|
64
64
|
const PLUGIN_NAME = 'ninetailed:core';
|
|
65
|
+
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
|
|
65
68
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
66
69
|
class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
67
70
|
constructor({
|
|
@@ -99,12 +102,14 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
99
102
|
messageId: payload.meta.rid,
|
|
100
103
|
timestamp: payload.meta.ts,
|
|
101
104
|
componentId: payload.componentId,
|
|
105
|
+
componentType: payload.componentType,
|
|
102
106
|
experienceId: payload.experienceId,
|
|
103
107
|
variantIndex: payload.variantIndex,
|
|
104
108
|
ctx
|
|
105
109
|
}));
|
|
106
110
|
};
|
|
107
111
|
this.methods = {
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
113
|
reset: async function (...args) {
|
|
109
114
|
logger.debug('Resetting profile.');
|
|
110
115
|
const instance = args[args.length - 1];
|
|
@@ -123,6 +128,7 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
123
128
|
logger.info('Profile reset successful.');
|
|
124
129
|
await delay(10);
|
|
125
130
|
},
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
132
|
debug: async function (...args) {
|
|
127
133
|
const enabled = args[0];
|
|
128
134
|
const instance = args[args.length - 1];
|
|
@@ -239,6 +245,7 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
|
|
|
239
245
|
onTrackComponent() {
|
|
240
246
|
return Promise.resolve();
|
|
241
247
|
}
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
242
249
|
setItemStart({
|
|
243
250
|
abort,
|
|
244
251
|
payload
|
|
@@ -735,9 +742,10 @@ class EventBuilder {
|
|
|
735
742
|
userId: userId || ''
|
|
736
743
|
}));
|
|
737
744
|
}
|
|
738
|
-
component(componentId, experienceId, variantIndex, data) {
|
|
745
|
+
component(componentId, componentType, experienceId, variantIndex, data) {
|
|
739
746
|
return buildComponentViewEvent(Object.assign({}, this.buildEventBase(data), {
|
|
740
747
|
componentId,
|
|
748
|
+
componentType: componentType || 'Entry',
|
|
741
749
|
experienceId: experienceId || '',
|
|
742
750
|
variantIndex: variantIndex || 0
|
|
743
751
|
}));
|
|
@@ -897,6 +905,13 @@ class Ninetailed {
|
|
|
897
905
|
type: HAS_SEEN_COMPONENT
|
|
898
906
|
}));
|
|
899
907
|
};
|
|
908
|
+
this.trackVariableComponentView = properties => {
|
|
909
|
+
const validatedVariable = SerializableObject.parse(properties.variable);
|
|
910
|
+
return this.instance.dispatch(Object.assign({}, properties, {
|
|
911
|
+
type: HAS_SEEN_VARIABLE,
|
|
912
|
+
variable: validatedVariable
|
|
913
|
+
}));
|
|
914
|
+
};
|
|
900
915
|
this.trackComponentView = properties => {
|
|
901
916
|
return this.instance.dispatch(Object.assign({}, properties, {
|
|
902
917
|
type: HAS_SEEN_ELEMENT,
|
|
@@ -1346,6 +1361,7 @@ class Ninetailed {
|
|
|
1346
1361
|
}
|
|
1347
1362
|
logInvalidElement(element) {
|
|
1348
1363
|
const isObject = typeof element === 'object' && element !== null;
|
|
1364
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1349
1365
|
const constructorName = isObject ? element.constructor.name : '';
|
|
1350
1366
|
const isConstructorNameNotObject = constructorName && constructorName !== 'Object';
|
|
1351
1367
|
logger.warn(`ElementSeenObserver.observeElement was called with an invalid element. Expected an Element but got ${typeof element}${isConstructorNameNotObject ? ` of type ${constructorName}` : ''}. This call will be ignored.`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.14.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.14.0",
|
|
13
|
+
"@ninetailed/experience.js-shared": "7.14.0",
|
|
14
14
|
"analytics": "0.8.1",
|
|
15
15
|
"uuid": "9.0.0"
|
|
16
16
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './lib/types/interfaces/RequiresEventBuilder';
|
|
|
10
10
|
export * from './lib/types/interfaces/HasExperienceSelectionMiddleware';
|
|
11
11
|
export * from './lib/types/interfaces/HasChangesModificationMiddleware';
|
|
12
12
|
export * from './lib/types/interfaces/InterestedInSeenElements';
|
|
13
|
+
export * from './lib/types/interfaces/InterestedInSeenVariables';
|
|
13
14
|
export * from './lib/types/interfaces/InterestedInProfileChange';
|
|
14
15
|
export * from './lib/types/interfaces/InterestedInHiddenPage';
|
|
15
16
|
export * from './lib/types/interfaces/AcceptsCredentials';
|
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, OnChangesChangeCallback } from './types';
|
|
4
|
+
import { EventFunctionOptions, NinetailedInstance, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackComponentView, OnChangesChangeCallback, TrackVariableComponentView } 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';
|
|
@@ -68,6 +68,7 @@ export declare class Ninetailed implements NinetailedInstance {
|
|
|
68
68
|
* Will be removed in the next version of the SDK
|
|
69
69
|
*/
|
|
70
70
|
trackHasSeenComponent: TrackHasSeenComponent;
|
|
71
|
+
trackVariableComponentView: TrackVariableComponentView;
|
|
71
72
|
trackComponentView: TrackComponentView;
|
|
72
73
|
private get pluginsWithCustomComponentViewThreshold();
|
|
73
74
|
observeElement: (payload: ElementSeenPayload, options?: ObserveOptions) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HAS_SEEN_COMPONENT, HAS_SEEN_ELEMENT } from '@ninetailed/experience.js-plugin-analytics';
|
|
2
|
-
import { PROFILE_CHANGE, Profile, SelectedVariantInfo, PROFILE_RESET, Change } from '@ninetailed/experience.js-shared';
|
|
1
|
+
import { HAS_SEEN_COMPONENT, HAS_SEEN_ELEMENT, HAS_SEEN_VARIABLE } from '@ninetailed/experience.js-plugin-analytics';
|
|
2
|
+
import { PROFILE_CHANGE, Profile, SelectedVariantInfo, PROFILE_RESET, Change, SerializableObject } from '@ninetailed/experience.js-shared';
|
|
3
3
|
import { HAS_SEEN_STICKY_COMPONENT, PAGE_HIDDEN } from '../constants';
|
|
4
4
|
type ReadyAction = {
|
|
5
5
|
type: 'ready';
|
|
@@ -9,6 +9,10 @@ type HasSeenElementAction = {
|
|
|
9
9
|
seenFor: number | undefined;
|
|
10
10
|
element: Element;
|
|
11
11
|
};
|
|
12
|
+
type HasSeenVariableAction = {
|
|
13
|
+
type: typeof HAS_SEEN_VARIABLE;
|
|
14
|
+
variable: SerializableObject;
|
|
15
|
+
};
|
|
12
16
|
type PageHiddenAction = {
|
|
13
17
|
type: typeof PAGE_HIDDEN;
|
|
14
18
|
};
|
|
@@ -44,7 +48,7 @@ type ProfileHasSeenComponentAction = {
|
|
|
44
48
|
};
|
|
45
49
|
isPersonalized: boolean;
|
|
46
50
|
};
|
|
47
|
-
export type DispatchAction = ReadyAction | ProfileChangeAction | ProfileResetAction | ProfileHasSeenStickyComponentAction | HasSeenElementAction | ProfileHasSeenComponentAction | PageHiddenAction;
|
|
51
|
+
export type DispatchAction = ReadyAction | ProfileChangeAction | ProfileResetAction | ProfileHasSeenStickyComponentAction | HasSeenElementAction | HasSeenVariableAction | ProfileHasSeenComponentAction | PageHiddenAction;
|
|
48
52
|
type RemoveTypeField<Type> = {
|
|
49
53
|
[Property in keyof Type as Exclude<Property, 'type'>]: Type[Property];
|
|
50
54
|
};
|
package/src/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DetachListeners } from 'analytics';
|
|
2
2
|
import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo, Reference, Event, Change } from '@ninetailed/experience.js-shared';
|
|
3
|
-
import { ElementSeenPayload, NinetailedPlugin, TrackComponentProperties } from '@ninetailed/experience.js-plugin-analytics';
|
|
3
|
+
import { ElementSeenPayload, VariableSeenPayload, NinetailedPlugin, TrackComponentProperties } from '@ninetailed/experience.js-plugin-analytics';
|
|
4
4
|
import { type Ninetailed } from '../Ninetailed';
|
|
5
5
|
import { OnSelectVariant } from './OnSelectVariant';
|
|
6
6
|
import { EventBuilder } from '../utils/EventBuilder';
|
|
@@ -63,6 +63,7 @@ export type Page = (data?: Partial<PageviewProperties>, options?: EventFunctionO
|
|
|
63
63
|
export type Track = (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<FlushResult>;
|
|
64
64
|
export type TrackHasSeenComponent = (properties: TrackComponentProperties) => Promise<void>;
|
|
65
65
|
export type TrackComponentView = (properties: Omit<ElementSeenPayload, 'seenFor'>) => Promise<void>;
|
|
66
|
+
export type TrackVariableComponentView = (properties: VariableSeenPayload) => Promise<void>;
|
|
66
67
|
export type Identify = (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<FlushResult>;
|
|
67
68
|
export type Batch = (events: Event[]) => Promise<FlushResult>;
|
|
68
69
|
export type Reset = () => void;
|
|
@@ -79,6 +80,7 @@ export interface NinetailedInstance<TBaseline extends Reference = Reference, TVa
|
|
|
79
80
|
*/
|
|
80
81
|
trackHasSeenComponent: TrackHasSeenComponent;
|
|
81
82
|
trackComponentView: TrackComponentView;
|
|
83
|
+
trackVariableComponentView: TrackVariableComponentView;
|
|
82
84
|
identify: Identify;
|
|
83
85
|
batch: Batch;
|
|
84
86
|
reset: Reset;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BuildPageEventArgs, BuildTrackEventArgs, IdentifyEventArgs, NinetailedRequestContext, Properties } from '@ninetailed/experience.js-shared';
|
|
2
|
+
import type { ComponentViewEventComponentType } from '@ninetailed/experience.js-plugin-analytics';
|
|
2
3
|
type PageData = Partial<Omit<BuildPageEventArgs, 'ctx' | 'properties'>>;
|
|
3
4
|
type TrackData = Partial<Omit<BuildTrackEventArgs, 'ctx' | 'event' | 'properties'>>;
|
|
4
5
|
type IdentifyData = Partial<Omit<IdentifyEventArgs, 'ctx' | 'userId' | 'traits'>>;
|
|
@@ -168,7 +169,7 @@ export declare class EventBuilder {
|
|
|
168
169
|
userId?: string | undefined;
|
|
169
170
|
traits: Properties;
|
|
170
171
|
};
|
|
171
|
-
component(componentId: string, experienceId?: string, variantIndex?: number, data?: ComponentData): {
|
|
172
|
+
component(componentId: string, componentType: ComponentViewEventComponentType, experienceId?: string, variantIndex?: number, data?: ComponentData): {
|
|
172
173
|
channel: import("@ninetailed/experience.js-shared").EventChanel;
|
|
173
174
|
context: {
|
|
174
175
|
app?: {
|
|
@@ -219,6 +220,7 @@ export declare class EventBuilder {
|
|
|
219
220
|
sentAt: string;
|
|
220
221
|
type: import("@ninetailed/experience.js-shared").EventType;
|
|
221
222
|
userId?: string | undefined;
|
|
223
|
+
componentType: import("@ninetailed/experience.js-shared").ComponentViewEventComponentType;
|
|
222
224
|
componentId: string;
|
|
223
225
|
experienceId?: string | undefined;
|
|
224
226
|
variantIndex?: number | undefined;
|