@ninetailed/experience.js-react 2.0.1 → 2.1.0

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.esm.js CHANGED
@@ -30,7 +30,9 @@ const NinetailedProvider = ({
30
30
  profile,
31
31
  locale,
32
32
  requestTimeout,
33
- plugins: _plugins = []
33
+ plugins: _plugins = [],
34
+ onLog,
35
+ onError
34
36
  }) => {
35
37
  const ninetailed = useMemo(() => new Ninetailed({
36
38
  clientId,
@@ -41,7 +43,9 @@ const NinetailedProvider = ({
41
43
  plugins: _plugins,
42
44
  profile,
43
45
  locale,
44
- requestTimeout
46
+ requestTimeout,
47
+ onLog,
48
+ onError
45
49
  }), []);
46
50
  return /*#__PURE__*/React.createElement(NinetailedContext.Provider, {
47
51
  value: ninetailed
@@ -2563,11 +2567,58 @@ const useJoinExperiment = ({
2563
2567
  }, [experiences]);
2564
2568
  };
2565
2569
 
2570
+ const DefaultExperienceLoadingComponent = _a => {
2571
+ var {
2572
+ component: Component,
2573
+ experiences,
2574
+ unhideAfterMs = 5000
2575
+ } = _a,
2576
+ baseline = __rest(_a, ["component", "experiences", "unhideAfterMs"]);
2577
+
2578
+ const {
2579
+ logger
2580
+ } = useNinetailed();
2581
+ const [hidden, setHidden] = useState(true);
2582
+ useEffect(() => {
2583
+ const timer = setTimeout(() => {
2584
+ setHidden(false);
2585
+ logger.error(new Error(`The experience was still in loading state after ${unhideAfterMs}ms. That happens when no events are sent to the Ninetailed API. The baseline is now shown instead.`));
2586
+ }, unhideAfterMs);
2587
+ return () => {
2588
+ clearTimeout(timer);
2589
+ };
2590
+ }, []);
2591
+
2592
+ if (hidden) {
2593
+ return /*#__PURE__*/React.createElement("div", {
2594
+ key: "hide",
2595
+ style: {
2596
+ opacity: 0
2597
+ }
2598
+ }, /*#__PURE__*/React.createElement(Component, Object.assign({}, baseline, {
2599
+ ninetailed: {
2600
+ isPersonalized: false,
2601
+ audience: {
2602
+ id: 'baseline'
2603
+ }
2604
+ }
2605
+ })));
2606
+ }
2607
+
2608
+ return /*#__PURE__*/React.createElement(Component, Object.assign({}, baseline, {
2609
+ ninetailed: {
2610
+ isPersonalized: false,
2611
+ audience: {
2612
+ id: 'baseline'
2613
+ }
2614
+ }
2615
+ }));
2616
+ };
2566
2617
  const Experience = _a => {
2567
2618
  var {
2568
2619
  experiences,
2569
2620
  component: Component,
2570
- loadingComponent: LoadingComponent
2621
+ loadingComponent: LoadingComponent = DefaultExperienceLoadingComponent
2571
2622
  } = _a,
2572
2623
  baseline = __rest(_a, ["experiences", "component", "loadingComponent"]);
2573
2624
 
@@ -2600,26 +2651,10 @@ const Experience = _a => {
2600
2651
  }
2601
2652
 
2602
2653
  if (status === 'loading') {
2603
- if (LoadingComponent) {
2604
- return /*#__PURE__*/React.createElement(LoadingComponent, Object.assign({}, baseline, {
2605
- experiences: experiences,
2606
- component: Component
2607
- }));
2608
- }
2609
-
2610
- return /*#__PURE__*/React.createElement("div", {
2611
- key: "hide",
2612
- style: {
2613
- opacity: 0
2614
- }
2615
- }, /*#__PURE__*/React.createElement(Component, Object.assign({}, baseline, {
2616
- ninetailed: {
2617
- isPersonalized: false,
2618
- audience: {
2619
- id: 'baseline'
2620
- }
2621
- }
2622
- })));
2654
+ return /*#__PURE__*/React.createElement(LoadingComponent, Object.assign({}, baseline, {
2655
+ experiences: experiences,
2656
+ component: Component
2657
+ }));
2623
2658
  }
2624
2659
 
2625
2660
  if (!experience) {
@@ -2724,4 +2759,4 @@ const ESRLoadingComponent = _a => {
2724
2759
  return /*#__PURE__*/React.createElement(Component, Object.assign({}, variant));
2725
2760
  };
2726
2761
 
2727
- export { ESRLoadingComponent, ESRProvider, Experience, MergeTag, NinetailedProvider, Personalize, TrackHasSeenComponent, useNinetailed, usePersonalize, useProfile };
2762
+ export { DefaultExperienceLoadingComponent, ESRLoadingComponent, ESRProvider, Experience, MergeTag, NinetailedProvider, Personalize, TrackHasSeenComponent, useNinetailed, usePersonalize, useProfile };
package/index.umd.js CHANGED
@@ -36,7 +36,9 @@
36
36
  locale = _a.locale,
37
37
  requestTimeout = _a.requestTimeout,
38
38
  _c = _a.plugins,
39
- plugins = _c === void 0 ? [] : _c;
39
+ plugins = _c === void 0 ? [] : _c,
40
+ onLog = _a.onLog,
41
+ onError = _a.onError;
40
42
  var ninetailed = React.useMemo(function () {
41
43
  return new experience_js.Ninetailed({
42
44
  clientId: clientId,
@@ -47,7 +49,9 @@
47
49
  plugins: plugins,
48
50
  profile: profile,
49
51
  locale: locale,
50
- requestTimeout: requestTimeout
52
+ requestTimeout: requestTimeout,
53
+ onLog: onLog,
54
+ onError: onError
51
55
  });
52
56
  }, []);
53
57
  return /*#__PURE__*/React__default["default"].createElement(NinetailedContext.Provider, {
@@ -2110,23 +2114,72 @@
2110
2114
  }, [experiences]);
2111
2115
  };
2112
2116
 
2117
+ var DefaultExperienceLoadingComponent = function DefaultExperienceLoadingComponent(_a) {
2118
+ var Component = _a.component;
2119
+ _a.experiences;
2120
+ var _b = _a.unhideAfterMs,
2121
+ unhideAfterMs = _b === void 0 ? 5000 : _b,
2122
+ baseline = __rest(_a, ["component", "experiences", "unhideAfterMs"]);
2123
+
2124
+ var logger = useNinetailed().logger;
2125
+
2126
+ var _c = React.useState(true),
2127
+ hidden = _c[0],
2128
+ setHidden = _c[1];
2129
+
2130
+ React.useEffect(function () {
2131
+ var timer = setTimeout(function () {
2132
+ setHidden(false);
2133
+ logger.error(new Error("The experience was still in loading state after ".concat(unhideAfterMs, "ms. That happens when no events are sent to the Ninetailed API. The baseline is now shown instead.")));
2134
+ }, unhideAfterMs);
2135
+ return function () {
2136
+ clearTimeout(timer);
2137
+ };
2138
+ }, []);
2139
+
2140
+ if (hidden) {
2141
+ return /*#__PURE__*/React__default["default"].createElement("div", {
2142
+ key: "hide",
2143
+ style: {
2144
+ opacity: 0
2145
+ }
2146
+ }, /*#__PURE__*/React__default["default"].createElement(Component, __assign({}, baseline, {
2147
+ ninetailed: {
2148
+ isPersonalized: false,
2149
+ audience: {
2150
+ id: 'baseline'
2151
+ }
2152
+ }
2153
+ })));
2154
+ }
2155
+
2156
+ return /*#__PURE__*/React__default["default"].createElement(Component, __assign({}, baseline, {
2157
+ ninetailed: {
2158
+ isPersonalized: false,
2159
+ audience: {
2160
+ id: 'baseline'
2161
+ }
2162
+ }
2163
+ }));
2164
+ };
2113
2165
  var Experience = function Experience(_a) {
2114
2166
  var experiences = _a.experiences,
2115
2167
  Component = _a.component,
2116
- LoadingComponent = _a.loadingComponent,
2168
+ _b = _a.loadingComponent,
2169
+ LoadingComponent = _b === void 0 ? DefaultExperienceLoadingComponent : _b,
2117
2170
  baseline = __rest(_a, ["experiences", "component", "loadingComponent"]);
2118
2171
 
2119
- var _b = useExperience({
2172
+ var _c = useExperience({
2120
2173
  baseline: baseline,
2121
2174
  experiences: experiences
2122
2175
  }),
2123
- status = _b.status,
2124
- hasVariants = _b.hasVariants,
2125
- experience = _b.experience,
2126
- variant = _b.variant,
2127
- audience = _b.audience,
2128
- isPersonalized = _b.isPersonalized,
2129
- profile = _b.profile;
2176
+ status = _c.status,
2177
+ hasVariants = _c.hasVariants,
2178
+ experience = _c.experience,
2179
+ variant = _c.variant,
2180
+ audience = _c.audience,
2181
+ isPersonalized = _c.isPersonalized,
2182
+ profile = _c.profile;
2130
2183
 
2131
2184
  var joinExperiment = useJoinExperiment({
2132
2185
  experiences: experiences
@@ -2145,26 +2198,10 @@
2145
2198
  }
2146
2199
 
2147
2200
  if (status === 'loading') {
2148
- if (LoadingComponent) {
2149
- return /*#__PURE__*/React__default["default"].createElement(LoadingComponent, __assign({}, baseline, {
2150
- experiences: experiences,
2151
- component: Component
2152
- }));
2153
- }
2154
-
2155
- return /*#__PURE__*/React__default["default"].createElement("div", {
2156
- key: "hide",
2157
- style: {
2158
- opacity: 0
2159
- }
2160
- }, /*#__PURE__*/React__default["default"].createElement(Component, __assign({}, baseline, {
2161
- ninetailed: {
2162
- isPersonalized: false,
2163
- audience: {
2164
- id: 'baseline'
2165
- }
2166
- }
2167
- })));
2201
+ return /*#__PURE__*/React__default["default"].createElement(LoadingComponent, __assign({}, baseline, {
2202
+ experiences: experiences,
2203
+ component: Component
2204
+ }));
2168
2205
  }
2169
2206
 
2170
2207
  if (!experience) {
@@ -2268,6 +2305,7 @@
2268
2305
  return /*#__PURE__*/React__default["default"].createElement(Component, __assign({}, variant));
2269
2306
  };
2270
2307
 
2308
+ exports.DefaultExperienceLoadingComponent = DefaultExperienceLoadingComponent;
2271
2309
  exports.ESRLoadingComponent = ESRLoadingComponent;
2272
2310
  exports.ESRProvider = ESRProvider;
2273
2311
  exports.Experience = Experience;
@@ -18,6 +18,11 @@ export declare type ExperienceProps<P extends Baseline> = ExperienceBaseProps<P>
18
18
  component: ExperienceComponent<P> | React.ComponentType<P>;
19
19
  loadingComponent?: ExperienceLoadingComponent<P>;
20
20
  };
21
+ declare type DefaultExperienceLoadingComponentProps = ExperienceBaseProps & {
22
+ unhideAfterMs?: number;
23
+ };
24
+ export declare const DefaultExperienceLoadingComponent: React.FC<DefaultExperienceLoadingComponentProps>;
21
25
  export declare const Experience: <P extends {
22
26
  id: string;
23
27
  }>({ experiences, component: Component, loadingComponent: LoadingComponent, ...baseline }: ExperienceProps<P>) => JSX.Element;
28
+ export {};
@@ -1,4 +1,4 @@
1
- import { ExperienceConfiguration } from './types';
1
+ import { ExperienceConfiguration } from '@ninetailed/experience.js';
2
2
  declare type ExperimentsContextValue = {
3
3
  experiments: ExperienceConfiguration[];
4
4
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ExperienceConfiguration } from './types';
2
+ import { ExperienceConfiguration } from '@ninetailed/experience.js';
3
3
  declare type ExperimentsProviderProps = {
4
4
  experiments: ExperienceConfiguration[];
5
5
  };
@@ -1,3 +1,3 @@
1
- export { Experience } from './Experience';
2
- export type { ExperienceProps, ExperienceBaseProps, ExperienceComponent, ExperienceLoadingComponent, } from './Experience';
1
+ export { Experience, DefaultExperienceLoadingComponent } from './Experience';
2
+ export type { ExperienceProps, ExperienceBaseProps, ExperienceComponent, ExperienceLoadingComponent } from './Experience';
3
3
  export { ESRProvider, ESRLoadingComponent } from './ESRLoadingComponent';
@@ -1,4 +1,3 @@
1
1
  export type { Baseline } from './Baseline';
2
2
  export type { Variant } from './Variant';
3
3
  export type { BaselineWithVariants } from './BaselineWithVariants';
4
- export type { ExperienceConfiguration } from './ExperienceConfiguration';
@@ -1,5 +1,4 @@
1
- import { Profile } from '@ninetailed/experience.js';
2
- import { ExperienceConfiguration } from './types';
1
+ import { Profile, ExperienceConfiguration } from '@ninetailed/experience.js';
3
2
  declare type UseJoinExperimentArgs = {
4
3
  experiences: ExperienceConfiguration[];
5
4
  };
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { AnalyticsPlugin } from 'analytics';
3
+ import { OnErrorHandler, OnLogHandler, ExperienceConfiguration } from '@ninetailed/experience.js';
3
4
  import { Profile, Locale } from '@ninetailed/experience.js-shared';
4
- import { ExperienceConfiguration } from './Experience/types';
5
5
  export declare type NinetailedProviderProps = {
6
6
  clientId: string;
7
7
  environment?: string;
@@ -12,5 +12,7 @@ export declare type NinetailedProviderProps = {
12
12
  profile?: Profile;
13
13
  locale?: Locale;
14
14
  requestTimeout?: number;
15
+ onLog?: OnLogHandler;
16
+ onError?: OnErrorHandler;
15
17
  };
16
18
  export declare const NinetailedProvider: React.FC<React.PropsWithChildren<NinetailedProviderProps>>;
package/lib/index.d.ts CHANGED
@@ -9,5 +9,5 @@ export { Personalize } from './Personalize';
9
9
  export type { PersonalizedComponent } from './Personalize';
10
10
  export { MergeTag } from './MergeTag';
11
11
  export { TrackHasSeenComponent } from './TrackHasSeenComponent';
12
- export { Experience, ESRProvider, ESRLoadingComponent } from './Experience';
12
+ export { Experience, ESRProvider, ESRLoadingComponent, DefaultExperienceLoadingComponent } from './Experience';
13
13
  export type { ExperienceProps, ExperienceBaseProps, ExperienceComponent, ExperienceLoadingComponent, } from './Experience';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-react",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "peerDependencies": {
5
5
  "react": ">=16.8.0"
6
6
  },
@@ -8,15 +8,15 @@
8
8
  "@analytics/google-analytics": "0.5.3",
9
9
  "react-visibility-sensor": "5.1.1",
10
10
  "lodash": "^4.17.21",
11
- "@ninetailed/experience.js": "2.0.1",
11
+ "@ninetailed/experience.js": "2.1.0",
12
12
  "analytics": "^0.8.0",
13
- "@ninetailed/experience.js-shared": "2.0.1",
13
+ "@ninetailed/experience.js-shared": "2.1.0",
14
14
  "uuid": "^8.3.2",
15
15
  "ts-toolbelt": "^9.6.0",
16
16
  "locale-enum": "^1.1.1",
17
17
  "i18n-iso-countries": "^7.3.0",
18
- "loglevel": "^1.8.0",
19
18
  "murmurhash-js": "^1.0.0",
19
+ "diary": "^0.3.1",
20
20
  "react-intersection-observer": "^8.33.1"
21
21
  },
22
22
  "main": "./index.umd.js",