@ninetailed/experience.js 5.0.0-beta.3 → 6.0.1-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.
@@ -0,0 +1,16 @@
1
+ export type ElementSeenObserverOptions = {
2
+ onElementSeen: (element: Element) => void;
3
+ };
4
+ export type ObserveOptions = {
5
+ delay?: number;
6
+ };
7
+ export declare class ElementSeenObserver {
8
+ private _options;
9
+ private _intersectionObserver?;
10
+ private _elementDelays;
11
+ private _intersectionTimers;
12
+ constructor(_options: ElementSeenObserverOptions);
13
+ private onIntersection;
14
+ observe(element: Element, options?: ObserveOptions): void;
15
+ unobserve(element: Element): void;
16
+ }
@@ -1,6 +1,7 @@
1
1
  /// <reference types="analytics" />
2
- import { Locale, Traits, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions } from '@ninetailed/experience.js-shared';
3
- import { EventFunctionOptions, NinetailedInstance, NinetailedPlugin, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackHasSeenExperience } from './types';
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';
4
5
  declare global {
5
6
  interface Window {
6
7
  ninetailed?: {
@@ -15,9 +16,11 @@ type Options = {
15
16
  url?: string;
16
17
  locale?: Locale;
17
18
  plugins?: (NinetailedPlugin | NinetailedPlugin[])[];
19
+ profile?: Profile;
18
20
  requestTimeout?: number;
19
21
  onLog?: OnLogHandler;
20
22
  onError?: OnErrorHandler;
23
+ componentViewTrackingThreshold?: number;
21
24
  };
22
25
  type NinetailedApiClientInstanceOrOptions = NinetailedApiClient | NinetailedApiClientOptions;
23
26
  export declare class Ninetailed implements NinetailedInstance {
@@ -26,15 +29,29 @@ export declare class Ninetailed implements NinetailedInstance {
26
29
  private isInitialized;
27
30
  private readonly apiClient;
28
31
  private readonly eventQueue;
32
+ private readonly elementSeenObserver;
33
+ private readonly observedElements;
29
34
  private readonly clientId;
30
35
  private readonly environment;
31
36
  readonly plugins: NinetailedPlugin[];
32
37
  readonly logger: Logger;
33
- constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, locale, requestTimeout, onLog, onError }?: Options);
38
+ private readonly componentViewTrackingThreshold;
39
+ constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, profile, locale, requestTimeout, onLog, onError, componentViewTrackingThreshold, }?: Options);
34
40
  page: (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
35
41
  track: (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
42
+ /**
43
+ * @deprecated The legacy datamodel is not recommended anymore
44
+ * Will be removed in version 5 of the SDK
45
+ */
36
46
  trackHasSeenComponent: TrackHasSeenComponent;
47
+ /**
48
+ * @deprecated Use the Ninetailed provided observers instead
49
+ * Will be removed in version 5 of the SDK
50
+ */
37
51
  trackHasSeenExperience: TrackHasSeenExperience;
52
+ observeElement: (payload: ElementSeenPayload, options?: ObserveOptions) => void;
53
+ unobserveElement: (element: Element) => void;
54
+ private onElementSeen;
38
55
  identify: (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
39
56
  reset: () => Promise<void>;
40
57
  debug: (enabled: boolean) => Promise<void>;
@@ -44,5 +61,6 @@ export declare class Ninetailed implements NinetailedInstance {
44
61
  get profileState(): ProfileState;
45
62
  private buildOptions;
46
63
  private registerWindowHandlers;
64
+ private onVisibilityChange;
47
65
  }
48
66
  export {};
@@ -2,7 +2,6 @@ export declare const LEGACY_ANONYMOUS_ID = "__anon_id";
2
2
  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
- export declare const EXPERIENCES_FALLBACK_CACHE = "__nt_experiences__";
6
5
  export declare const PROFILE_CHANGE = "profile-change";
7
6
  export declare const PROFILE_RESET = "profile-reset";
8
7
  export declare const CONSENT = "__nt-consent__";
@@ -1,2 +1,3 @@
1
1
  export * from './get-analytics-plugin';
2
2
  export * from './constants';
3
+ export * from './Events';
@@ -1,2 +1,3 @@
1
- export declare const HAS_SEEN_EXPERIENCE = "has_seen_experience";
2
1
  export declare const HAS_SEEN_COMPONENT = "has_seen_component";
2
+ export declare const HAS_SEEN_ELEMENT = "has_seen_element";
3
+ export declare const PAGE_HIDDEN = "page_hidden";
@@ -1,4 +1,4 @@
1
1
  export * from './types';
2
- export { EXPERIENCE_TRAIT_PREFIX, selectDistribution, isExperienceMatch, selectVariantClientSide as selectExperienceVariantClientSide, selectHasVariants as selectHasExperienceVariants, selectVariants as selectExperienceVariants, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectExperience, selectEligibleExperiences, selectActiveExperiments, } from '@ninetailed/experience.js-shared';
2
+ export { EXPERIENCE_TRAIT_PREFIX, selectDistribution, isExperienceMatch, selectVariant as selectExperienceVariant, selectHasVariants as selectHasExperienceVariants, selectVariants as selectExperienceVariants, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectExperience, selectEligibleExperiences, selectActiveExperiments, } from '@ninetailed/experience.js-shared';
3
3
  export { decodeExperienceVariantsMap } from './decodeExperienceVariantsMap';
4
4
  export { makeExperienceSelectMiddleware } from './makeExperienceSelectMiddleware';
@@ -11,9 +11,10 @@ type MakeExperienceSelectMiddlewareArg<Variant extends Reference> = {
11
11
  export declare const makeExperienceSelectMiddleware: <Variant extends Reference>({ plugins, onChange, experiences, baseline, profile, }: MakeExperienceSelectMiddlewareArg<Variant>) => {
12
12
  addListeners: () => void;
13
13
  removeListeners: () => void;
14
- middleware: ({ experience, variant, }: ExperienceSelectionMiddlewareReturnArg<Variant | VariantRef>) => {
14
+ middleware: ({ experience, variant, variantIndex, }: ExperienceSelectionMiddlewareReturnArg<Variant | VariantRef>) => {
15
15
  experience: ExperienceConfiguration<Variant | VariantRef> | null;
16
- variant: Variant | VariantRef | null;
16
+ variant: Variant | VariantRef;
17
+ variantIndex: number;
17
18
  };
18
19
  };
19
20
  export {};
@@ -0,0 +1,2 @@
1
+ import { AcceptsCredentials } from '../types/interfaces/AcceptsCredentials';
2
+ export declare const acceptsCredentials: (plugin: unknown) => plugin is AcceptsCredentials;
@@ -0,0 +1,2 @@
1
+ import { InterestedInHiddenPage } from '../types/interfaces/InterestedInHiddenPage';
2
+ export declare const isInterestedInHiddenPage: (arg: unknown) => arg is InterestedInHiddenPage;
@@ -0,0 +1,2 @@
1
+ import { InterestedInSeenElements } from '../types/interfaces/InterestedInSeenElements';
2
+ export declare const isInterestedInSeenElements: (arg: unknown) => arg is InterestedInSeenElements;
@@ -0,0 +1,4 @@
1
+ export type Credentials = {
2
+ clientId: string;
3
+ environment: string;
4
+ };
@@ -0,0 +1,82 @@
1
+ import { z } from 'zod';
2
+ export declare const ElementSeenPayloadSchema: z.ZodObject<{
3
+ element: z.ZodAny;
4
+ experience: z.ZodNullable<z.ZodOptional<z.ZodObject<{
5
+ id: z.ZodString;
6
+ type: z.ZodUnion<[z.ZodLiteral<"nt_experiment">, z.ZodLiteral<"nt_personalization">]>;
7
+ name: z.ZodOptional<z.ZodString>;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ id: string;
11
+ type: "nt_experiment" | "nt_personalization";
12
+ name?: string | undefined;
13
+ description?: string | undefined;
14
+ }, {
15
+ id: string;
16
+ type: "nt_experiment" | "nt_personalization";
17
+ name?: string | undefined;
18
+ description?: string | undefined;
19
+ }>>>;
20
+ audience: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodObject<{
21
+ id: z.ZodString;
22
+ name: z.ZodOptional<z.ZodString>;
23
+ description: z.ZodOptional<z.ZodString>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ id: string;
26
+ name?: string | undefined;
27
+ description?: string | undefined;
28
+ }, {
29
+ id: string;
30
+ name?: string | undefined;
31
+ description?: string | undefined;
32
+ }>>>>;
33
+ variant: z.ZodObject<{
34
+ id: z.ZodString;
35
+ }, "strip", z.ZodUnknown, z.objectOutputType<{
36
+ id: z.ZodString;
37
+ }, z.ZodUnknown, "strip">, z.objectInputType<{
38
+ id: z.ZodString;
39
+ }, z.ZodUnknown, "strip">>;
40
+ variantIndex: z.ZodNumber;
41
+ }, "strip", z.ZodTypeAny, {
42
+ audience: {
43
+ id: string;
44
+ name?: string | undefined;
45
+ description?: string | undefined;
46
+ } | null;
47
+ variant: {
48
+ id: string;
49
+ } & {
50
+ [k: string]: unknown;
51
+ };
52
+ variantIndex: number;
53
+ element?: any;
54
+ experience?: {
55
+ id: string;
56
+ type: "nt_experiment" | "nt_personalization";
57
+ name?: string | undefined;
58
+ description?: string | undefined;
59
+ } | null | undefined;
60
+ }, {
61
+ variant: {
62
+ id: string;
63
+ } & {
64
+ [k: string]: unknown;
65
+ };
66
+ variantIndex: number;
67
+ element?: any;
68
+ experience?: {
69
+ id: string;
70
+ type: "nt_experiment" | "nt_personalization";
71
+ name?: string | undefined;
72
+ description?: string | undefined;
73
+ } | null | undefined;
74
+ audience?: {
75
+ id: string;
76
+ name?: string | undefined;
77
+ description?: string | undefined;
78
+ } | null | undefined;
79
+ }>;
80
+ export type ElementSeenPayload = Omit<z.input<typeof ElementSeenPayloadSchema>, 'element'> & {
81
+ element: Element;
82
+ };
@@ -1,4 +1,13 @@
1
1
  import { AnalyticsPlugin } from 'analytics';
2
+ import { AnalyticsInstance } from './AnalyticsInstance';
3
+ export type EventHandlerParams<T = unknown> = {
4
+ payload: T;
5
+ instance: AnalyticsInstance;
6
+ };
7
+ export type EventHandler<T = unknown> = (params: EventHandlerParams<T>) => void;
8
+ /**
9
+ * @deprecated Use `NinetailedPlugin` from the sdks/javascript package instead.
10
+ */
2
11
  export declare abstract class NinetailedPlugin implements AnalyticsPlugin {
3
12
  [x: string]: unknown;
4
13
  abstract readonly name: string;
@@ -0,0 +1,4 @@
1
+ import { type Profile } from '@ninetailed/experience.js-shared';
2
+ export type ProfileChangedPayload = {
3
+ profile: Profile;
4
+ };
@@ -1,83 +1,4 @@
1
1
  import { z } from 'zod';
2
- export declare const TrackExperienceProperties: z.ZodObject<{
3
- experience: z.ZodObject<{
4
- id: z.ZodString;
5
- type: z.ZodUnion<[z.ZodLiteral<"nt_experiment">, z.ZodLiteral<"nt_personalization">]>;
6
- name: z.ZodString;
7
- description: z.ZodOptional<z.ZodString>;
8
- }, "strip", z.ZodTypeAny, {
9
- description?: string | undefined;
10
- type: "nt_experiment" | "nt_personalization";
11
- id: string;
12
- name: string;
13
- }, {
14
- description?: string | undefined;
15
- type: "nt_experiment" | "nt_personalization";
16
- id: string;
17
- name: string;
18
- }>;
19
- audience: z.ZodDefault<z.ZodOptional<z.ZodObject<{
20
- id: z.ZodString;
21
- name: z.ZodOptional<z.ZodString>;
22
- description: z.ZodOptional<z.ZodString>;
23
- }, "strip", z.ZodTypeAny, {
24
- name?: string | undefined;
25
- description?: string | undefined;
26
- id: string;
27
- }, {
28
- name?: string | undefined;
29
- description?: string | undefined;
30
- id: string;
31
- }>>>;
32
- selectedVariant: z.ZodObject<{
33
- id: z.ZodString;
34
- }, "strip", z.ZodUnknown, {
35
- [x: string]: unknown;
36
- id: string;
37
- }, {
38
- [x: string]: unknown;
39
- id: string;
40
- }>;
41
- selectedVariantIndex: z.ZodNumber;
42
- }, "strip", z.ZodTypeAny, {
43
- experience: {
44
- description?: string | undefined;
45
- type: "nt_experiment" | "nt_personalization";
46
- id: string;
47
- name: string;
48
- };
49
- audience: {
50
- name?: string | undefined;
51
- description?: string | undefined;
52
- id: string;
53
- };
54
- selectedVariant: {
55
- [x: string]: unknown;
56
- id: string;
57
- };
58
- selectedVariantIndex: number;
59
- }, {
60
- audience?: {
61
- name?: string | undefined;
62
- description?: string | undefined;
63
- id: string;
64
- } | undefined;
65
- experience: {
66
- description?: string | undefined;
67
- type: "nt_experiment" | "nt_personalization";
68
- id: string;
69
- name: string;
70
- };
71
- selectedVariant: {
72
- [x: string]: unknown;
73
- id: string;
74
- };
75
- selectedVariantIndex: number;
76
- }>;
77
- export type TrackExperienceProperties = z.input<typeof TrackExperienceProperties>;
78
- export type SanitizedTrackExperienceProperties = z.infer<typeof TrackExperienceProperties> & {
79
- selectedVariantSelector: string;
80
- };
81
2
  export declare const TrackComponentProperties: z.ZodObject<{
82
3
  variant: z.ZodObject<{
83
4
  id: z.ZodString;
@@ -95,18 +16,18 @@ export declare const TrackComponentProperties: z.ZodObject<{
95
16
  }>;
96
17
  isPersonalized: z.ZodBoolean;
97
18
  }, "strip", z.ZodTypeAny, {
98
- audience: {
19
+ variant: {
99
20
  id: string;
100
21
  };
101
- variant: {
22
+ audience: {
102
23
  id: string;
103
24
  };
104
25
  isPersonalized: boolean;
105
26
  }, {
106
- audience: {
27
+ variant: {
107
28
  id: string;
108
29
  };
109
- variant: {
30
+ audience: {
110
31
  id: string;
111
32
  };
112
33
  isPersonalized: boolean;
@@ -1,23 +1,22 @@
1
- import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo } from '@ninetailed/experience.js-shared';
1
+ import { Logger, PageviewProperties, Profile, Properties, Traits } from '@ninetailed/experience.js-shared';
2
2
  import { DetachListeners } from 'analytics';
3
- import { TrackExperienceProperties, TrackComponentProperties } from './TrackingProperties';
3
+ import { TrackComponentProperties } from './TrackingProperties';
4
4
  import { NinetailedPlugin } from './NinetailedPlugin';
5
+ import { type Ninetailed } from '../Ninetailed';
6
+ import { ElementSeenPayload } from './ElementSeenPayload';
5
7
  type Loading = {
6
8
  status: 'loading';
7
9
  profile: null;
8
- experiences: null;
9
10
  error: null;
10
11
  };
11
12
  type Success = {
12
13
  status: 'success';
13
14
  profile: Profile;
14
- experiences: SelectedVariantInfo[];
15
15
  error: null;
16
16
  };
17
17
  type Fail = {
18
18
  status: 'error';
19
19
  profile: null;
20
- experiences: null;
21
20
  error: Error;
22
21
  };
23
22
  export type ProfileState = {
@@ -38,11 +37,13 @@ export type OnProfileChangeCallback = (profile: ProfileState) => void;
38
37
  export type Page = (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<FlushResult>;
39
38
  export type Track = (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<FlushResult>;
40
39
  export type TrackHasSeenComponent = (properties: TrackComponentProperties) => Promise<void>;
41
- export type TrackHasSeenExperience = (properties: TrackExperienceProperties) => Promise<void>;
40
+ export type TrackHasSeenExperience = (properties: ElementSeenPayload) => Promise<void>;
42
41
  export type Identify = (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<FlushResult>;
43
42
  export type Reset = () => void;
44
43
  export type Debug = (enable: boolean) => void;
45
44
  export type OnProfileChange = (cb: OnProfileChangeCallback) => DetachListeners;
45
+ type ObserveElement = Ninetailed['observeElement'];
46
+ type UnObserveElement = Ninetailed['unobserveElement'];
46
47
  export interface NinetailedInstance {
47
48
  page: Page;
48
49
  track: Track;
@@ -56,8 +57,13 @@ export interface NinetailedInstance {
56
57
  plugins: NinetailedPlugin[];
57
58
  logger: Logger;
58
59
  onIsInitialized: OnIsInitialized;
60
+ observeElement: ObserveElement;
61
+ unobserveElement: UnObserveElement;
59
62
  }
60
- export { NinetailedPlugin, TrackExperienceProperties, TrackComponentProperties, };
63
+ export { NinetailedPlugin, TrackComponentProperties };
61
64
  export type { EventHandler } from './EventHandler';
62
65
  export type { AnalyticsInstance } from './AnalyticsInstance';
63
- export type { SanitizedTrackExperienceProperties } from './TrackingProperties';
66
+ export { ElementSeenPayloadSchema } from './ElementSeenPayload';
67
+ export type { ElementSeenPayload } from './ElementSeenPayload';
68
+ export type { ProfileChangedPayload } from './ProfileChangedPayload';
69
+ export type { Credentials } from './Credentials';
@@ -0,0 +1,4 @@
1
+ import { type Credentials } from '../Credentials';
2
+ export interface AcceptsCredentials {
3
+ setCredentials(credentials: Credentials): void;
4
+ }
@@ -1,7 +1,8 @@
1
1
  import { ExperienceConfiguration, Reference } from '@ninetailed/experience.js-shared';
2
2
  export type ExperienceSelectionMiddlewareReturnArg<Variant extends Reference> = {
3
3
  experience: ExperienceConfiguration<Variant> | null;
4
- variant: Variant | null;
4
+ variant: Variant;
5
+ variantIndex: number;
5
6
  };
6
7
  type ExperienceSelectionMiddlewareReturn<Variant extends Reference> = (arg: ExperienceSelectionMiddlewareReturnArg<Variant>) => ExperienceSelectionMiddlewareReturnArg<Variant>;
7
8
  type ExperienceSelectionMiddlewareArg<Variant extends Reference> = {
@@ -0,0 +1,5 @@
1
+ import { PAGE_HIDDEN } from '../../constants';
2
+ import { EventHandler } from '../EventHandler';
3
+ export interface InterestedInHiddenPage {
4
+ [PAGE_HIDDEN]: EventHandler<void>;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { PROFILE_CHANGE } from '@ninetailed/experience.js-shared';
2
+ import { EventHandler } from '../EventHandler';
3
+ import { ProfileChangedPayload } from '../ProfileChangedPayload';
4
+ export interface InterestedInProfileChange {
5
+ [PROFILE_CHANGE]: EventHandler<ProfileChangedPayload>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import { HAS_SEEN_ELEMENT } from '../../constants';
2
+ import { ElementSeenPayload } from '../ElementSeenPayload';
3
+ import { EventHandler } from '../EventHandler';
4
+ export interface InterestedInSeenElements {
5
+ [HAS_SEEN_ELEMENT]: EventHandler<ElementSeenPayload>;
6
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "5.0.0-beta.3",
3
+ "version": "6.0.1-beta.1",
4
4
  "module": "./index.js",
5
5
  "main": "./index.cjs",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
- "@ninetailed/experience.js-shared": "5.0.0-beta.3",
9
+ "@ninetailed/experience.js-shared": "6.0.1-beta.1",
10
10
  "analytics": "0.8.1",
11
11
  "zod": "3.21.4"
12
12
  },