@ninetailed/experience.js 4.4.0-beta.1 → 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.cjs CHANGED
@@ -2591,11 +2591,13 @@ const ninetailedPlugin = ({
2591
2591
  apiClient,
2592
2592
  profile,
2593
2593
  locale,
2594
- ninetailed
2594
+ ninetailed,
2595
+ buildClientContext
2595
2596
  }) => {
2596
2597
  let _instance;
2597
2598
  let queue = [];
2598
2599
  let enabledFeatures = Object.values(experience_jsShared.FEATURES);
2600
+ const buildContext = buildClientContext || buildClientNinetailedRequestContext;
2599
2601
  const flush = () => __awaiter(void 0, void 0, void 0, function* () {
2600
2602
  const events = Object.assign([], queue);
2601
2603
  experience_jsShared.logger.info('Start flushing events.');
@@ -2699,7 +2701,7 @@ const ninetailedPlugin = ({
2699
2701
  payload
2700
2702
  }) => __awaiter(void 0, void 0, void 0, function* () {
2701
2703
  experience_jsShared.logger.info('Sending Page event.');
2702
- const ctx = buildClientNinetailedRequestContext();
2704
+ const ctx = buildContext();
2703
2705
  return enqueueEvent(experience_jsShared.buildPageEvent({
2704
2706
  messageId: payload.meta.rid,
2705
2707
  timestamp: payload.meta.ts,
@@ -2714,7 +2716,7 @@ const ninetailedPlugin = ({
2714
2716
  payload
2715
2717
  }) => __awaiter(void 0, void 0, void 0, function* () {
2716
2718
  experience_jsShared.logger.info('Sending Track event.');
2717
- const ctx = buildClientNinetailedRequestContext();
2719
+ const ctx = buildContext();
2718
2720
  return enqueueEvent(experience_jsShared.buildTrackEvent({
2719
2721
  messageId: payload.meta.rid,
2720
2722
  timestamp: payload.meta.ts,
@@ -2730,7 +2732,7 @@ const ninetailedPlugin = ({
2730
2732
  payload
2731
2733
  }) => __awaiter(void 0, void 0, void 0, function* () {
2732
2734
  experience_jsShared.logger.info('Sending Identify event.');
2733
- const ctx = buildClientNinetailedRequestContext();
2735
+ const ctx = buildContext();
2734
2736
  if (payload.userId === EMPTY_MERGE_ID && (!payload.traits || typeof payload.traits === 'object' && Object.keys(payload.traits).length === 0)) {
2735
2737
  experience_jsShared.logger.info('Skipping Identify event as no userId and no traits are set.');
2736
2738
  return;
@@ -3299,7 +3301,8 @@ class Ninetailed {
3299
3301
  locale,
3300
3302
  requestTimeout,
3301
3303
  onLog,
3302
- onError
3304
+ onError,
3305
+ buildClientContext
3303
3306
  } = {}) {
3304
3307
  this.isInitialized = false;
3305
3308
  this.page = (data, options) => __awaiter(this, void 0, void 0, function* () {
@@ -3466,6 +3469,7 @@ class Ninetailed {
3466
3469
  profile,
3467
3470
  locale,
3468
3471
  requestTimeout,
3472
+ buildClientContext,
3469
3473
  ninetailed: this
3470
3474
  });
3471
3475
  this.instance = Analytics__default["default"]({
package/index.js CHANGED
@@ -2584,11 +2584,13 @@ const ninetailedPlugin = ({
2584
2584
  apiClient,
2585
2585
  profile,
2586
2586
  locale,
2587
- ninetailed
2587
+ ninetailed,
2588
+ buildClientContext
2588
2589
  }) => {
2589
2590
  let _instance;
2590
2591
  let queue = [];
2591
2592
  let enabledFeatures = Object.values(FEATURES);
2593
+ const buildContext = buildClientContext || buildClientNinetailedRequestContext;
2592
2594
  const flush = () => __awaiter(void 0, void 0, void 0, function* () {
2593
2595
  const events = Object.assign([], queue);
2594
2596
  logger.info('Start flushing events.');
@@ -2692,7 +2694,7 @@ const ninetailedPlugin = ({
2692
2694
  payload
2693
2695
  }) => __awaiter(void 0, void 0, void 0, function* () {
2694
2696
  logger.info('Sending Page event.');
2695
- const ctx = buildClientNinetailedRequestContext();
2697
+ const ctx = buildContext();
2696
2698
  return enqueueEvent(buildPageEvent({
2697
2699
  messageId: payload.meta.rid,
2698
2700
  timestamp: payload.meta.ts,
@@ -2707,7 +2709,7 @@ const ninetailedPlugin = ({
2707
2709
  payload
2708
2710
  }) => __awaiter(void 0, void 0, void 0, function* () {
2709
2711
  logger.info('Sending Track event.');
2710
- const ctx = buildClientNinetailedRequestContext();
2712
+ const ctx = buildContext();
2711
2713
  return enqueueEvent(buildTrackEvent({
2712
2714
  messageId: payload.meta.rid,
2713
2715
  timestamp: payload.meta.ts,
@@ -2723,7 +2725,7 @@ const ninetailedPlugin = ({
2723
2725
  payload
2724
2726
  }) => __awaiter(void 0, void 0, void 0, function* () {
2725
2727
  logger.info('Sending Identify event.');
2726
- const ctx = buildClientNinetailedRequestContext();
2728
+ const ctx = buildContext();
2727
2729
  if (payload.userId === EMPTY_MERGE_ID && (!payload.traits || typeof payload.traits === 'object' && Object.keys(payload.traits).length === 0)) {
2728
2730
  logger.info('Skipping Identify event as no userId and no traits are set.');
2729
2731
  return;
@@ -3292,7 +3294,8 @@ class Ninetailed {
3292
3294
  locale,
3293
3295
  requestTimeout,
3294
3296
  onLog,
3295
- onError
3297
+ onError,
3298
+ buildClientContext
3296
3299
  } = {}) {
3297
3300
  this.isInitialized = false;
3298
3301
  this.page = (data, options) => __awaiter(this, void 0, void 0, function* () {
@@ -3459,6 +3462,7 @@ class Ninetailed {
3459
3462
  profile,
3460
3463
  locale,
3461
3464
  requestTimeout,
3465
+ buildClientContext,
3462
3466
  ninetailed: this
3463
3467
  });
3464
3468
  this.instance = Analytics({
@@ -1,5 +1,5 @@
1
1
  /// <reference types="analytics" />
2
- import { Locale, Traits, Profile, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions } from '@ninetailed/experience.js-shared';
2
+ import { Locale, Traits, Profile, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
3
3
  import { EventFunctionOptions, NinetailedInstance, NinetailedPlugin, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackHasSeenExperience } from './types';
4
4
  declare global {
5
5
  interface Window {
@@ -19,6 +19,7 @@ type Options = {
19
19
  requestTimeout?: number;
20
20
  onLog?: OnLogHandler;
21
21
  onError?: OnErrorHandler;
22
+ buildClientContext?: () => NinetailedRequestContext;
22
23
  };
23
24
  type NinetailedApiClientInstanceOrOptions = NinetailedApiClient | NinetailedApiClientOptions;
24
25
  export declare class Ninetailed implements NinetailedInstance {
@@ -31,7 +32,7 @@ export declare class Ninetailed implements NinetailedInstance {
31
32
  private readonly environment;
32
33
  readonly plugins: NinetailedPlugin[];
33
34
  readonly logger: Logger;
34
- constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, profile, locale, requestTimeout, onLog, onError, }?: Options);
35
+ constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, profile, locale, requestTimeout, onLog, onError, buildClientContext, }?: Options);
35
36
  page: (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
36
37
  track: (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
37
38
  trackHasSeenComponent: TrackHasSeenComponent;
@@ -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 {};
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "4.4.0-beta.1",
3
+ "version": "4.5.0-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": "4.4.0-beta.1",
9
+ "@ninetailed/experience.js-shared": "4.5.0-beta.1",
10
10
  "analytics": "0.8.1",
11
11
  "zod": "3.21.4"
12
12
  },