@ninetailed/experience.js 3.0.0-beta.40 → 3.0.0-beta.42

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 CHANGED
@@ -2595,7 +2595,8 @@ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
2595
2595
  const ninetailedPlugin = ({
2596
2596
  apiClient,
2597
2597
  profile,
2598
- locale
2598
+ locale,
2599
+ ninetailed
2599
2600
  }) => {
2600
2601
  let _instance;
2601
2602
  let queue = [];
@@ -2761,8 +2762,7 @@ const ninetailedPlugin = ({
2761
2762
  instance.storage.removeItem(ANONYMOUS_ID);
2762
2763
  instance.storage.removeItem(PROFILE_FALLBACK_CACHE);
2763
2764
  experience_jsShared.logger.debug('Removed old profile data from localstorage.');
2764
- // sending a new page event, when no anonymousId is set will create a new profile.
2765
- yield instance.page();
2765
+ yield ninetailed.track('nt_reset');
2766
2766
  experience_jsShared.logger.info('Profile reset successful.');
2767
2767
  yield delay(10);
2768
2768
  }),
@@ -3346,7 +3346,8 @@ class Ninetailed {
3346
3346
  apiClient: this.apiClient,
3347
3347
  profile,
3348
3348
  locale,
3349
- requestTimeout
3349
+ requestTimeout,
3350
+ ninetailed: this
3350
3351
  });
3351
3352
  this.instance = Analytics__default["default"]({
3352
3353
  app: 'ninetailed',
@@ -4073,6 +4074,7 @@ const isExperienceMatch = ({
4073
4074
  profile
4074
4075
  }) => {
4075
4076
  const trafficRandom = getTrafficRandom(profile, experience);
4077
+ console.log('has no audience', experience.id, !experience.audience);
4076
4078
  experience_jsShared.logger.info(`The traffic random factor for experience ${experience.id} is ${trafficRandom}. It's traffic allocation is set to ${experience.trafficAllocation}.`);
4077
4079
  const isInTrafficRange = experience.trafficAllocation > trafficRandom;
4078
4080
  const matchesAudience = !experience.audience || includes__default["default"](profile.audiences, experience.audience.id);
package/index.js CHANGED
@@ -2582,7 +2582,8 @@ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
2582
2582
  const ninetailedPlugin = ({
2583
2583
  apiClient,
2584
2584
  profile,
2585
- locale
2585
+ locale,
2586
+ ninetailed
2586
2587
  }) => {
2587
2588
  let _instance;
2588
2589
  let queue = [];
@@ -2748,8 +2749,7 @@ const ninetailedPlugin = ({
2748
2749
  instance.storage.removeItem(ANONYMOUS_ID);
2749
2750
  instance.storage.removeItem(PROFILE_FALLBACK_CACHE);
2750
2751
  logger.debug('Removed old profile data from localstorage.');
2751
- // sending a new page event, when no anonymousId is set will create a new profile.
2752
- yield instance.page();
2752
+ yield ninetailed.track('nt_reset');
2753
2753
  logger.info('Profile reset successful.');
2754
2754
  yield delay(10);
2755
2755
  }),
@@ -3333,7 +3333,8 @@ class Ninetailed {
3333
3333
  apiClient: this.apiClient,
3334
3334
  profile,
3335
3335
  locale,
3336
- requestTimeout
3336
+ requestTimeout,
3337
+ ninetailed: this
3337
3338
  });
3338
3339
  this.instance = Analytics({
3339
3340
  app: 'ninetailed',
@@ -4060,6 +4061,7 @@ const isExperienceMatch = ({
4060
4061
  profile
4061
4062
  }) => {
4062
4063
  const trafficRandom = getTrafficRandom(profile, experience);
4064
+ console.log('has no audience', experience.id, !experience.audience);
4063
4065
  logger.info(`The traffic random factor for experience ${experience.id} is ${trafficRandom}. It's traffic allocation is set to ${experience.trafficAllocation}.`);
4064
4066
  const isInTrafficRange = experience.trafficAllocation > trafficRandom;
4065
4067
  const matchesAudience = !experience.audience || includes(profile.audiences, experience.audience.id);
@@ -1,8 +1,6 @@
1
- import { AnalyticsPlugin, DetachListeners } from 'analytics';
1
+ import { AnalyticsPlugin } from 'analytics';
2
2
  import { Locale, Traits, Profile, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions } from '@ninetailed/experience.js-shared';
3
- import { TrackComponentProperties, TrackExperienceProperties } from '@ninetailed/experience.js-plugin-analytics';
4
- import { FlushResult } from './analytics';
5
- import { ProfileState } from './types';
3
+ import { EventFunctionOptions, NinetailedInstance, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackHasSeenExperience } from './types';
6
4
  declare global {
7
5
  interface Window {
8
6
  ninetailed?: {
@@ -12,8 +10,6 @@ declare global {
12
10
  } & unknown;
13
11
  }
14
12
  }
15
- declare type OnIsInitializedCallback = () => void;
16
- export declare type OnIsInitialized = (cb: OnIsInitializedCallback) => void;
17
13
  declare type Options = {
18
14
  url?: string;
19
15
  locale?: Locale;
@@ -23,35 +19,6 @@ declare type Options = {
23
19
  onLog?: OnLogHandler;
24
20
  onError?: OnErrorHandler;
25
21
  };
26
- declare type EventFunctionOptions = {
27
- plugins?: {
28
- all: boolean;
29
- [key: string]: boolean;
30
- };
31
- };
32
- declare type OnProfileChangeCallback = (profile: ProfileState) => void;
33
- export declare type Page = (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<FlushResult>;
34
- export declare type Track = (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<FlushResult>;
35
- export declare type TrackHasSeenComponent = (properties: TrackComponentProperties) => Promise<void>;
36
- export declare type TrackHasSeenExperience = (properties: TrackExperienceProperties) => Promise<void>;
37
- export declare type Identify = (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<FlushResult>;
38
- export declare type Reset = () => void;
39
- export declare type Debug = (enable: boolean) => void;
40
- export declare type OnProfileChange = (cb: OnProfileChangeCallback) => DetachListeners;
41
- export interface NinetailedInstance {
42
- page: Page;
43
- track: Track;
44
- trackHasSeenComponent: TrackHasSeenComponent;
45
- trackHasSeenExperience: TrackHasSeenExperience;
46
- identify: Identify;
47
- reset: Reset;
48
- debug: Debug;
49
- profileState: ProfileState;
50
- onProfileChange: OnProfileChange;
51
- plugins: AnalyticsPlugin[];
52
- logger: Logger;
53
- onIsInitialized: OnIsInitialized;
54
- }
55
22
  declare type NinetailedApiClientInstanceOrOptions = NinetailedApiClient | NinetailedApiClientOptions;
56
23
  export declare class Ninetailed implements NinetailedInstance {
57
24
  private readonly instance;
@@ -62,14 +29,14 @@ export declare class Ninetailed implements NinetailedInstance {
62
29
  readonly plugins: AnalyticsPlugin[];
63
30
  readonly logger: Logger;
64
31
  constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, profile, locale, requestTimeout, onLog, onError, }?: Options);
65
- page: (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<FlushResult>;
66
- track: (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<FlushResult>;
32
+ page: (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
33
+ track: (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
67
34
  trackHasSeenComponent: TrackHasSeenComponent;
68
35
  trackHasSeenExperience: TrackHasSeenExperience;
69
- identify: (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<FlushResult>;
36
+ identify: (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
70
37
  reset: () => void;
71
38
  debug: (enabled: boolean) => void;
72
- onProfileChange: (cb: OnProfileChangeCallback) => DetachListeners;
39
+ onProfileChange: (cb: OnProfileChangeCallback) => import("analytics").DetachListeners;
73
40
  onIsInitialized: (onIsInitialized: OnIsInitializedCallback) => void;
74
41
  private waitUntilInitialized;
75
42
  get profileState(): ProfileState;
@@ -1,17 +1,16 @@
1
1
  import { AnalyticsPlugin } from 'analytics';
2
2
  import { Profile, Locale, NinetailedApiClient } from '@ninetailed/experience.js-shared';
3
+ import { NinetailedInstance, FlushResult } from '../types';
3
4
  declare type AnalyticsPluginNinetailedConfig = {
4
5
  apiClient: NinetailedApiClient;
5
6
  profile?: Profile;
6
7
  locale?: Locale;
7
8
  requestTimeout?: number;
9
+ ninetailed: NinetailedInstance;
8
10
  };
9
11
  export declare const PLUGIN_NAME = "ninetailed";
10
- export declare type FlushResult = {
11
- success: boolean;
12
- };
13
12
  export interface NinetailedEventQueue extends AnalyticsPlugin {
14
13
  flush: () => Promise<FlushResult>;
15
14
  }
16
- export declare const ninetailedPlugin: ({ apiClient, profile, locale, }: AnalyticsPluginNinetailedConfig) => NinetailedEventQueue;
15
+ export declare const ninetailedPlugin: ({ apiClient, profile, locale, ninetailed, }: AnalyticsPluginNinetailedConfig) => NinetailedEventQueue;
17
16
  export {};
@@ -2,7 +2,7 @@ import { BaselineWithVariants } from './BaselineWithVariants';
2
2
  import { Distribution } from './Distribution';
3
3
  import { Reference } from './Reference';
4
4
  export declare type ExperienceType = 'nt_personalization' | 'nt_experiment';
5
- export declare type ExperienceConfiguration<Variant extends Reference> = {
5
+ export declare type ExperienceConfiguration<Variant extends Reference = Reference> = {
6
6
  id: string;
7
7
  type: ExperienceType;
8
8
  audience?: {
package/lib/types.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { Profile } from '@ninetailed/experience.js-shared';
1
+ import { TrackComponentProperties, TrackExperienceProperties } from '@ninetailed/experience.js-plugin-analytics';
2
+ import { Logger, PageviewProperties, Profile, Properties, Traits } from '@ninetailed/experience.js-shared';
3
+ import { AnalyticsPlugin, DetachListeners } from 'analytics';
2
4
  declare type Loading = {
3
5
  status: 'loading';
4
6
  profile: null;
@@ -17,4 +19,38 @@ declare type Fail = {
17
19
  export declare type ProfileState = {
18
20
  from: 'api' | 'hydrated';
19
21
  } & (Loading | Success | Fail);
22
+ export declare type OnIsInitializedCallback = () => void;
23
+ export declare type OnIsInitialized = (cb: OnIsInitializedCallback) => void;
24
+ export declare type EventFunctionOptions = {
25
+ plugins?: {
26
+ all: boolean;
27
+ [key: string]: boolean;
28
+ };
29
+ };
30
+ export declare type FlushResult = {
31
+ success: boolean;
32
+ };
33
+ export declare type OnProfileChangeCallback = (profile: ProfileState) => void;
34
+ export declare type Page = (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<FlushResult>;
35
+ export declare type Track = (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<FlushResult>;
36
+ export declare type TrackHasSeenComponent = (properties: TrackComponentProperties) => Promise<void>;
37
+ export declare type TrackHasSeenExperience = (properties: TrackExperienceProperties) => Promise<void>;
38
+ export declare type Identify = (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<FlushResult>;
39
+ export declare type Reset = () => void;
40
+ export declare type Debug = (enable: boolean) => void;
41
+ export declare type OnProfileChange = (cb: OnProfileChangeCallback) => DetachListeners;
42
+ export interface NinetailedInstance {
43
+ page: Page;
44
+ track: Track;
45
+ trackHasSeenComponent: TrackHasSeenComponent;
46
+ trackHasSeenExperience: TrackHasSeenExperience;
47
+ identify: Identify;
48
+ reset: Reset;
49
+ debug: Debug;
50
+ profileState: ProfileState;
51
+ onProfileChange: OnProfileChange;
52
+ plugins: AnalyticsPlugin[];
53
+ logger: Logger;
54
+ onIsInitialized: OnIsInitialized;
55
+ }
20
56
  export {};
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "3.0.0-beta.40",
3
+ "version": "3.0.0-beta.42",
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": "3.0.0-beta.40",
9
+ "@ninetailed/experience.js-shared": "3.0.0-beta.42",
10
10
  "analytics": "0.8.1",
11
11
  "lodash": "4.17.21",
12
12
  "murmurhash-js": "1.0.0",
13
- "@ninetailed/experience.js-plugin-analytics": "3.0.0-beta.40"
13
+ "@ninetailed/experience.js-plugin-analytics": "3.0.0-beta.42"
14
14
  },
15
15
  "peerDependencies": {}
16
16
  }