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

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,
@@ -962,7 +958,10 @@ class Ninetailed {
962
958
  })));
963
959
  return;
964
960
  }
965
- const baselineVariants = experience_jsShared.selectBaselineWithVariants(experience, baseline);
961
+ const experienceWithStickyFromExperienceApi = Object.assign(Object.assign({}, experience), {
962
+ sticky: selectedExperience.sticky
963
+ });
964
+ const baselineVariants = experience_jsShared.selectBaselineWithVariants(experienceWithStickyFromExperienceApi, baseline);
966
965
  if (!baselineVariants) {
967
966
  setSelectedVariant(overrideResult(Object.assign(Object.assign({}, emptyReturn), {
968
967
  loading: false,
@@ -987,7 +986,7 @@ class Ninetailed {
987
986
  status: 'success',
988
987
  loading: false,
989
988
  error: null,
990
- experience,
989
+ experience: experienceWithStickyFromExperienceApi,
991
990
  variant,
992
991
  variantIndex: selectedExperience.variantIndex,
993
992
  audience: experience.audience ? experience.audience : null,
@@ -1018,6 +1017,18 @@ class Ninetailed {
1018
1017
  this.onIsInitialized(resolve);
1019
1018
  });
1020
1019
  };
1020
+ // The following methods are used to register methods of the Ninetailed instance on the window object.
1021
+ // GTM templates do not support executing async functions in `callInWindow`.
1022
+ // Therefore, we provide a versions of those methods without the async keyword.
1023
+ this.trackAsWindowHandler = (event, properties, options) => {
1024
+ return this.track(event, properties, options);
1025
+ };
1026
+ this.identifyAsWindowHandler = (uid, traits, options) => {
1027
+ return this.identify(uid, traits, options);
1028
+ };
1029
+ this.pageAsWindowHandler = (data, options) => {
1030
+ return this.page(data, options);
1031
+ };
1021
1032
  this.onVisibilityChange = () => {
1022
1033
  if (typeof document === 'undefined') {
1023
1034
  return;
@@ -1056,7 +1067,6 @@ class Ninetailed {
1056
1067
  });
1057
1068
  }
1058
1069
  this.plugins = (plugins !== null && plugins !== void 0 ? plugins : []).flat();
1059
- this.eventBuilder = new EventBuilder(buildClientContext);
1060
1070
  this.plugins.forEach(plugin => {
1061
1071
  if (acceptsCredentials(plugin) && this.clientId && this.environment) {
1062
1072
  plugin.setCredentials({
@@ -1067,9 +1077,6 @@ class Ninetailed {
1067
1077
  if (experience_jsPluginAnalytics.hasComponentViewTrackingThreshold(plugin)) {
1068
1078
  plugin.setComponentViewTrackingThreshold(componentViewTrackingThreshold);
1069
1079
  }
1070
- if (requiresEventBuilder(plugin)) {
1071
- plugin.setEventBuilder(this.eventBuilder);
1072
- }
1073
1080
  });
1074
1081
  this._profileState = {
1075
1082
  status: 'loading',
@@ -1078,6 +1085,7 @@ class Ninetailed {
1078
1085
  error: null,
1079
1086
  from: 'api'
1080
1087
  };
1088
+ this.eventBuilder = new EventBuilder(buildClientContext);
1081
1089
  this.ninetailedCorePlugin = new NinetailedCorePlugin({
1082
1090
  apiClient: this.apiClient,
1083
1091
  locale,
@@ -1130,9 +1138,9 @@ class Ninetailed {
1130
1138
  registerWindowHandlers() {
1131
1139
  if (typeof window !== 'undefined') {
1132
1140
  window.ninetailed = Object.assign({}, window.ninetailed, {
1133
- page: this.page.bind(this),
1134
- track: this.track.bind(this),
1135
- identify: this.identify.bind(this),
1141
+ page: this.pageAsWindowHandler.bind(this),
1142
+ track: this.trackAsWindowHandler.bind(this),
1143
+ identify: this.identifyAsWindowHandler.bind(this),
1136
1144
  reset: this.reset.bind(this),
1137
1145
  debug: this.debug.bind(this),
1138
1146
  profile: this.profileState.profile
@@ -1272,7 +1280,6 @@ exports.CONSENT = CONSENT;
1272
1280
  exports.DEBUG_FLAG = DEBUG_FLAG;
1273
1281
  exports.EMPTY_MERGE_ID = EMPTY_MERGE_ID;
1274
1282
  exports.EXPERIENCES_FALLBACK_CACHE = EXPERIENCES_FALLBACK_CACHE;
1275
- exports.EventBuilder = EventBuilder;
1276
1283
  exports.HAS_SEEN_STICKY_COMPONENT = HAS_SEEN_STICKY_COMPONENT;
1277
1284
  exports.LEGACY_ANONYMOUS_ID = LEGACY_ANONYMOUS_ID;
1278
1285
  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 => {
@@ -944,7 +940,10 @@ class Ninetailed {
944
940
  })));
945
941
  return;
946
942
  }
947
- const baselineVariants = selectBaselineWithVariants(experience, baseline);
943
+ const experienceWithStickyFromExperienceApi = Object.assign({}, experience, {
944
+ sticky: selectedExperience.sticky
945
+ });
946
+ const baselineVariants = selectBaselineWithVariants(experienceWithStickyFromExperienceApi, baseline);
948
947
  if (!baselineVariants) {
949
948
  setSelectedVariant(overrideResult(Object.assign({}, emptyReturn, {
950
949
  loading: false,
@@ -969,7 +968,7 @@ class Ninetailed {
969
968
  status: 'success',
970
969
  loading: false,
971
970
  error: null,
972
- experience,
971
+ experience: experienceWithStickyFromExperienceApi,
973
972
  variant,
974
973
  variantIndex: selectedExperience.variantIndex,
975
974
  audience: experience.audience ? experience.audience : null,
@@ -1000,6 +999,18 @@ class Ninetailed {
1000
999
  this.onIsInitialized(resolve);
1001
1000
  });
1002
1001
  };
1002
+ // The following methods are used to register methods of the Ninetailed instance on the window object.
1003
+ // GTM templates do not support executing async functions in `callInWindow`.
1004
+ // Therefore, we provide a versions of those methods without the async keyword.
1005
+ this.trackAsWindowHandler = (event, properties, options) => {
1006
+ return this.track(event, properties, options);
1007
+ };
1008
+ this.identifyAsWindowHandler = (uid, traits, options) => {
1009
+ return this.identify(uid, traits, options);
1010
+ };
1011
+ this.pageAsWindowHandler = (data, options) => {
1012
+ return this.page(data, options);
1013
+ };
1003
1014
  this.onVisibilityChange = () => {
1004
1015
  if (typeof document === 'undefined') {
1005
1016
  return;
@@ -1038,7 +1049,6 @@ class Ninetailed {
1038
1049
  });
1039
1050
  }
1040
1051
  this.plugins = (plugins != null ? plugins : []).flat();
1041
- this.eventBuilder = new EventBuilder(buildClientContext);
1042
1052
  this.plugins.forEach(plugin => {
1043
1053
  if (acceptsCredentials(plugin) && this.clientId && this.environment) {
1044
1054
  plugin.setCredentials({
@@ -1049,9 +1059,6 @@ class Ninetailed {
1049
1059
  if (hasComponentViewTrackingThreshold(plugin)) {
1050
1060
  plugin.setComponentViewTrackingThreshold(componentViewTrackingThreshold);
1051
1061
  }
1052
- if (requiresEventBuilder(plugin)) {
1053
- plugin.setEventBuilder(this.eventBuilder);
1054
- }
1055
1062
  });
1056
1063
  this._profileState = {
1057
1064
  status: 'loading',
@@ -1060,6 +1067,7 @@ class Ninetailed {
1060
1067
  error: null,
1061
1068
  from: 'api'
1062
1069
  };
1070
+ this.eventBuilder = new EventBuilder(buildClientContext);
1063
1071
  this.ninetailedCorePlugin = new NinetailedCorePlugin({
1064
1072
  apiClient: this.apiClient,
1065
1073
  locale,
@@ -1113,9 +1121,9 @@ class Ninetailed {
1113
1121
  registerWindowHandlers() {
1114
1122
  if (typeof window !== 'undefined') {
1115
1123
  window.ninetailed = Object.assign({}, window.ninetailed, {
1116
- page: this.page.bind(this),
1117
- track: this.track.bind(this),
1118
- identify: this.identify.bind(this),
1124
+ page: this.pageAsWindowHandler.bind(this),
1125
+ track: this.trackAsWindowHandler.bind(this),
1126
+ identify: this.identifyAsWindowHandler.bind(this),
1119
1127
  reset: this.reset.bind(this),
1120
1128
  debug: this.debug.bind(this),
1121
1129
  profile: this.profileState.profile
@@ -1213,4 +1221,4 @@ const selectVariant = (baseline, variants, {
1213
1221
  };
1214
1222
  };
1215
1223
 
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 };
1224
+ 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.2",
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.2",
13
+ "@ninetailed/experience.js-shared": "7.8.0-beta.2",
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
- }