@ninetailed/experience.js 7.8.0-beta.1 → 7.8.0-beta.3

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 CHANGED
@@ -595,10 +595,6 @@ class EventBuilder {
595
595
  }
596
596
  }
597
597
 
598
- const requiresEventBuilder = plugin => {
599
- return typeof plugin === 'object' && plugin !== null && 'setEventBuilder' in plugin && typeof plugin.setEventBuilder === 'function';
600
- };
601
-
602
598
  const buildOverrideMiddleware = experienceSelectionMiddleware => _a => {
603
599
  var {
604
600
  experience: originalExperience,
@@ -1018,6 +1014,18 @@ class Ninetailed {
1018
1014
  this.onIsInitialized(resolve);
1019
1015
  });
1020
1016
  };
1017
+ // The following methods are used to register methods of the Ninetailed instance on the window object.
1018
+ // GTM templates do not support executing async functions in `callInWindow`.
1019
+ // Therefore, we provide a versions of those methods without the async keyword.
1020
+ this.trackAsWindowHandler = (event, properties, options) => {
1021
+ return this.track(event, properties, options);
1022
+ };
1023
+ this.identifyAsWindowHandler = (uid, traits, options) => {
1024
+ return this.identify(uid, traits, options);
1025
+ };
1026
+ this.pageAsWindowHandler = (data, options) => {
1027
+ return this.page(data, options);
1028
+ };
1021
1029
  this.onVisibilityChange = () => {
1022
1030
  if (typeof document === 'undefined') {
1023
1031
  return;
@@ -1056,7 +1064,6 @@ class Ninetailed {
1056
1064
  });
1057
1065
  }
1058
1066
  this.plugins = (plugins !== null && plugins !== void 0 ? plugins : []).flat();
1059
- this.eventBuilder = new EventBuilder(buildClientContext);
1060
1067
  this.plugins.forEach(plugin => {
1061
1068
  if (acceptsCredentials(plugin) && this.clientId && this.environment) {
1062
1069
  plugin.setCredentials({
@@ -1067,9 +1074,6 @@ class Ninetailed {
1067
1074
  if (experience_jsPluginAnalytics.hasComponentViewTrackingThreshold(plugin)) {
1068
1075
  plugin.setComponentViewTrackingThreshold(componentViewTrackingThreshold);
1069
1076
  }
1070
- if (requiresEventBuilder(plugin)) {
1071
- plugin.setEventBuilder(this.eventBuilder);
1072
- }
1073
1077
  });
1074
1078
  this._profileState = {
1075
1079
  status: 'loading',
@@ -1078,6 +1082,7 @@ class Ninetailed {
1078
1082
  error: null,
1079
1083
  from: 'api'
1080
1084
  };
1085
+ this.eventBuilder = new EventBuilder(buildClientContext);
1081
1086
  this.ninetailedCorePlugin = new NinetailedCorePlugin({
1082
1087
  apiClient: this.apiClient,
1083
1088
  locale,
@@ -1130,9 +1135,9 @@ class Ninetailed {
1130
1135
  registerWindowHandlers() {
1131
1136
  if (typeof window !== 'undefined') {
1132
1137
  window.ninetailed = Object.assign({}, window.ninetailed, {
1133
- page: this.page.bind(this),
1134
- track: this.track.bind(this),
1135
- identify: this.identify.bind(this),
1138
+ page: this.pageAsWindowHandler.bind(this),
1139
+ track: this.trackAsWindowHandler.bind(this),
1140
+ identify: this.identifyAsWindowHandler.bind(this),
1136
1141
  reset: this.reset.bind(this),
1137
1142
  debug: this.debug.bind(this),
1138
1143
  profile: this.profileState.profile
@@ -1272,7 +1277,6 @@ exports.CONSENT = CONSENT;
1272
1277
  exports.DEBUG_FLAG = DEBUG_FLAG;
1273
1278
  exports.EMPTY_MERGE_ID = EMPTY_MERGE_ID;
1274
1279
  exports.EXPERIENCES_FALLBACK_CACHE = EXPERIENCES_FALLBACK_CACHE;
1275
- exports.EventBuilder = EventBuilder;
1276
1280
  exports.HAS_SEEN_STICKY_COMPONENT = HAS_SEEN_STICKY_COMPONENT;
1277
1281
  exports.LEGACY_ANONYMOUS_ID = LEGACY_ANONYMOUS_ID;
1278
1282
  exports.Ninetailed = Ninetailed;
package/index.esm.js CHANGED
@@ -560,10 +560,6 @@ class EventBuilder {
560
560
  }
561
561
  }
562
562
 
563
- const requiresEventBuilder = plugin => {
564
- return typeof plugin === 'object' && plugin !== null && 'setEventBuilder' in plugin && typeof plugin.setEventBuilder === 'function';
565
- };
566
-
567
563
  const _excluded = ["experience", "variant", "variantIndex"],
568
564
  _excluded2 = ["element"];
569
565
  const buildOverrideMiddleware = experienceSelectionMiddleware => _ref => {
@@ -1000,6 +996,18 @@ class Ninetailed {
1000
996
  this.onIsInitialized(resolve);
1001
997
  });
1002
998
  };
999
+ // The following methods are used to register methods of the Ninetailed instance on the window object.
1000
+ // GTM templates do not support executing async functions in `callInWindow`.
1001
+ // Therefore, we provide a versions of those methods without the async keyword.
1002
+ this.trackAsWindowHandler = (event, properties, options) => {
1003
+ return this.track(event, properties, options);
1004
+ };
1005
+ this.identifyAsWindowHandler = (uid, traits, options) => {
1006
+ return this.identify(uid, traits, options);
1007
+ };
1008
+ this.pageAsWindowHandler = (data, options) => {
1009
+ return this.page(data, options);
1010
+ };
1003
1011
  this.onVisibilityChange = () => {
1004
1012
  if (typeof document === 'undefined') {
1005
1013
  return;
@@ -1038,7 +1046,6 @@ class Ninetailed {
1038
1046
  });
1039
1047
  }
1040
1048
  this.plugins = (plugins != null ? plugins : []).flat();
1041
- this.eventBuilder = new EventBuilder(buildClientContext);
1042
1049
  this.plugins.forEach(plugin => {
1043
1050
  if (acceptsCredentials(plugin) && this.clientId && this.environment) {
1044
1051
  plugin.setCredentials({
@@ -1049,9 +1056,6 @@ class Ninetailed {
1049
1056
  if (hasComponentViewTrackingThreshold(plugin)) {
1050
1057
  plugin.setComponentViewTrackingThreshold(componentViewTrackingThreshold);
1051
1058
  }
1052
- if (requiresEventBuilder(plugin)) {
1053
- plugin.setEventBuilder(this.eventBuilder);
1054
- }
1055
1059
  });
1056
1060
  this._profileState = {
1057
1061
  status: 'loading',
@@ -1060,6 +1064,7 @@ class Ninetailed {
1060
1064
  error: null,
1061
1065
  from: 'api'
1062
1066
  };
1067
+ this.eventBuilder = new EventBuilder(buildClientContext);
1063
1068
  this.ninetailedCorePlugin = new NinetailedCorePlugin({
1064
1069
  apiClient: this.apiClient,
1065
1070
  locale,
@@ -1113,9 +1118,9 @@ class Ninetailed {
1113
1118
  registerWindowHandlers() {
1114
1119
  if (typeof window !== 'undefined') {
1115
1120
  window.ninetailed = Object.assign({}, window.ninetailed, {
1116
- page: this.page.bind(this),
1117
- track: this.track.bind(this),
1118
- identify: this.identify.bind(this),
1121
+ page: this.pageAsWindowHandler.bind(this),
1122
+ track: this.trackAsWindowHandler.bind(this),
1123
+ identify: this.identifyAsWindowHandler.bind(this),
1119
1124
  reset: this.reset.bind(this),
1120
1125
  debug: this.debug.bind(this),
1121
1126
  profile: this.profileState.profile
@@ -1213,4 +1218,4 @@ const selectVariant = (baseline, variants, {
1213
1218
  };
1214
1219
  };
1215
1220
 
1216
- 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 };
1221
+ export { ANONYMOUS_ID, COMPONENT, COMPONENT_START, CONSENT, DEBUG_FLAG, EMPTY_MERGE_ID, EXPERIENCES_FALLBACK_CACHE, 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.8.0-beta.1",
3
+ "version": "7.8.0-beta.3",
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.8.0-beta.1",
13
- "@ninetailed/experience.js-shared": "7.8.0-beta.1",
12
+ "@ninetailed/experience.js-plugin-analytics": "7.8.0-beta.3",
13
+ "@ninetailed/experience.js-shared": "7.8.0-beta.3",
14
14
  "analytics": "0.8.1",
15
15
  "uuid": "9.0.0"
16
16
  },
package/src/index.d.ts CHANGED
@@ -6,12 +6,10 @@ export * from './lib/types';
6
6
  export * from './lib/experience';
7
7
  export * from './lib/plugins/selectPluginsHavingExperienceSelectionMiddleware';
8
8
  export * from './lib/plugins/selectPluginsHavingOnChangeEmitter';
9
- export * from './lib/types/interfaces/RequiresEventBuilder';
10
9
  export * from './lib/types/interfaces/HasExperienceSelectionMiddleware';
11
10
  export * from './lib/types/interfaces/InterestedInSeenElements';
12
11
  export * from './lib/types/interfaces/InterestedInProfileChange';
13
12
  export * from './lib/types/interfaces/InterestedInHiddenPage';
14
13
  export * from './lib/types/interfaces/AcceptsCredentials';
15
14
  export * from './lib/utils/OnChangeEmitter';
16
- export * from './lib/utils/EventBuilder';
17
15
  export type { Profile } from '@ninetailed/experience.js-shared';
@@ -81,6 +81,9 @@ export declare class Ninetailed implements NinetailedInstance {
81
81
  private waitUntilInitialized;
82
82
  get profileState(): ProfileState;
83
83
  private buildOptions;
84
+ private trackAsWindowHandler;
85
+ private identifyAsWindowHandler;
86
+ private pageAsWindowHandler;
84
87
  private registerWindowHandlers;
85
88
  private onVisibilityChange;
86
89
  }
@@ -1,2 +0,0 @@
1
- import { RequiresEventBuilder } from '../types/interfaces/RequiresEventBuilder';
2
- export declare const requiresEventBuilder: (plugin: unknown) => plugin is RequiresEventBuilder;
@@ -1,4 +0,0 @@
1
- import { EventBuilder } from '../../utils/EventBuilder';
2
- export interface RequiresEventBuilder {
3
- setEventBuilder(eventBuilder: EventBuilder): void;
4
- }