@ninetailed/experience.js-react 4.2.3 → 4.3.0-beta.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.cjs +134 -62
- package/index.js +135 -63
- package/lib/Experience/ComponentMarker.d.ts +2 -0
- package/lib/NinetailedProvider.d.ts +6 -12
- package/lib/index.d.ts +1 -1
- package/lib/useProfile.d.ts +2 -0
- package/package.json +4 -3
package/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var experience_js = require('@ninetailed/experience.js');
|
|
8
|
+
var reactIs = require('react-is');
|
|
8
9
|
var reactIntersectionObserver = require('react-intersection-observer');
|
|
9
10
|
var experience_jsShared = require('@ninetailed/experience.js-shared');
|
|
10
11
|
var radash = require('radash');
|
|
@@ -2087,6 +2088,36 @@ const useJoinExperiment = () => {
|
|
|
2087
2088
|
return context.joinExperiment;
|
|
2088
2089
|
};
|
|
2089
2090
|
|
|
2091
|
+
const ComponentMarker = /*#__PURE__*/React.forwardRef((_, ref) => {
|
|
2092
|
+
const {
|
|
2093
|
+
logger
|
|
2094
|
+
} = useNinetailed();
|
|
2095
|
+
const markerRef = React.useRef(null);
|
|
2096
|
+
React.useEffect(() => {
|
|
2097
|
+
// TODO: Create a better message
|
|
2098
|
+
logger.debug('Using fallback mechanism to select component.');
|
|
2099
|
+
}, [logger]);
|
|
2100
|
+
React.useEffect(() => {
|
|
2101
|
+
if (markerRef.current) {
|
|
2102
|
+
const nextSibling = markerRef.current.nextSibling;
|
|
2103
|
+
if (ref) {
|
|
2104
|
+
if (typeof ref === 'function') {
|
|
2105
|
+
ref(nextSibling);
|
|
2106
|
+
} else {
|
|
2107
|
+
ref.current = nextSibling;
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
}, []);
|
|
2112
|
+
return jsxRuntime.jsx("div", {
|
|
2113
|
+
className: "nt-cmp-marker",
|
|
2114
|
+
style: {
|
|
2115
|
+
display: 'none !important'
|
|
2116
|
+
},
|
|
2117
|
+
ref: markerRef
|
|
2118
|
+
});
|
|
2119
|
+
});
|
|
2120
|
+
|
|
2090
2121
|
const DefaultExperienceLoadingComponent = _a => {
|
|
2091
2122
|
var {
|
|
2092
2123
|
component: Component,
|
|
@@ -2140,6 +2171,10 @@ const Experience = _a => {
|
|
|
2140
2171
|
passthroughProps
|
|
2141
2172
|
} = _a,
|
|
2142
2173
|
baseline = __rest(_a, ["experiences", "component", "loadingComponent", "passthroughProps"]);
|
|
2174
|
+
const {
|
|
2175
|
+
observeElement,
|
|
2176
|
+
unobserveElement
|
|
2177
|
+
} = useNinetailed();
|
|
2143
2178
|
// TODO we actually could hook into the experience hook here with the plugins
|
|
2144
2179
|
const {
|
|
2145
2180
|
status,
|
|
@@ -2154,6 +2189,10 @@ const Experience = _a => {
|
|
|
2154
2189
|
experiences
|
|
2155
2190
|
});
|
|
2156
2191
|
const joinExperiment = useJoinExperiment();
|
|
2192
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2193
|
+
// @ts-ignore
|
|
2194
|
+
const isComponentForwardRef = reactIs.isForwardRef(jsxRuntime.jsx(Component, {}));
|
|
2195
|
+
const componentRef = React.useRef(null);
|
|
2157
2196
|
React.useEffect(() => {
|
|
2158
2197
|
if (status === 'success' && experience && profile) {
|
|
2159
2198
|
joinExperiment({
|
|
@@ -2163,10 +2202,33 @@ const Experience = _a => {
|
|
|
2163
2202
|
});
|
|
2164
2203
|
}
|
|
2165
2204
|
}, [status, experience, profile]);
|
|
2205
|
+
React.useEffect(() => {
|
|
2206
|
+
const componentElement = componentRef.current;
|
|
2207
|
+
if (componentElement) {
|
|
2208
|
+
observeElement({
|
|
2209
|
+
element: componentElement,
|
|
2210
|
+
experienceId: experience === null || experience === void 0 ? void 0 : experience.id,
|
|
2211
|
+
variantId: variant === null || variant === void 0 ? void 0 : variant.id,
|
|
2212
|
+
baselineId: baseline.id,
|
|
2213
|
+
audienceId: audience === null || audience === void 0 ? void 0 : audience.id
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
return () => {
|
|
2217
|
+
if (componentElement) {
|
|
2218
|
+
unobserveElement(componentElement);
|
|
2219
|
+
}
|
|
2220
|
+
};
|
|
2221
|
+
}, [observeElement, unobserveElement, experience, baseline, variant, audience]);
|
|
2166
2222
|
if (!hasVariants) {
|
|
2167
|
-
return
|
|
2168
|
-
|
|
2169
|
-
|
|
2223
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2224
|
+
children: [!isComponentForwardRef && jsxRuntime.jsx(ComponentMarker, {
|
|
2225
|
+
ref: componentRef
|
|
2226
|
+
}), /*#__PURE__*/React.createElement(Component, Object.assign({}, passthroughProps, baseline, {
|
|
2227
|
+
key: baseline.id
|
|
2228
|
+
}, isComponentForwardRef ? {
|
|
2229
|
+
ref: componentRef
|
|
2230
|
+
} : {}))]
|
|
2231
|
+
});
|
|
2170
2232
|
}
|
|
2171
2233
|
if (status === 'loading') {
|
|
2172
2234
|
return /*#__PURE__*/React.createElement(LoadingComponent, Object.assign({}, baseline, {
|
|
@@ -2177,14 +2239,20 @@ const Experience = _a => {
|
|
|
2177
2239
|
}));
|
|
2178
2240
|
}
|
|
2179
2241
|
if (!experience) {
|
|
2180
|
-
return jsxRuntime.
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2242
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2243
|
+
children: [!isComponentForwardRef && jsxRuntime.jsx(ComponentMarker, {
|
|
2244
|
+
ref: componentRef
|
|
2245
|
+
}), jsxRuntime.jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
2246
|
+
ninetailed: {
|
|
2247
|
+
isPersonalized: false,
|
|
2248
|
+
audience: {
|
|
2249
|
+
id: 'baseline'
|
|
2250
|
+
}
|
|
2185
2251
|
}
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2252
|
+
}, isComponentForwardRef ? {
|
|
2253
|
+
ref: componentRef
|
|
2254
|
+
} : {}))]
|
|
2255
|
+
});
|
|
2188
2256
|
}
|
|
2189
2257
|
if (!variant) {
|
|
2190
2258
|
return jsxRuntime.jsx(TrackExperience, Object.assign({
|
|
@@ -2193,14 +2261,20 @@ const Experience = _a => {
|
|
|
2193
2261
|
// the profile is definitely defined, otherwise there wouldn't be an experience selected
|
|
2194
2262
|
profile: profile
|
|
2195
2263
|
}, {
|
|
2196
|
-
children: jsxRuntime.
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2264
|
+
children: jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2265
|
+
children: [!isComponentForwardRef && jsxRuntime.jsx(ComponentMarker, {
|
|
2266
|
+
ref: componentRef
|
|
2267
|
+
}), jsxRuntime.jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
2268
|
+
ninetailed: {
|
|
2269
|
+
isPersonalized: false,
|
|
2270
|
+
audience: {
|
|
2271
|
+
id: (audience === null || audience === void 0 ? void 0 : audience.id) || 'all visitors'
|
|
2272
|
+
}
|
|
2201
2273
|
}
|
|
2202
|
-
}
|
|
2203
|
-
|
|
2274
|
+
}, isComponentForwardRef ? {
|
|
2275
|
+
ref: componentRef
|
|
2276
|
+
} : {}))]
|
|
2277
|
+
})
|
|
2204
2278
|
}), baseline.id);
|
|
2205
2279
|
}
|
|
2206
2280
|
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
@@ -2210,15 +2284,21 @@ const Experience = _a => {
|
|
|
2210
2284
|
// the profile is definitely defined, otherwise there wouldn't be an experience selected
|
|
2211
2285
|
profile: profile
|
|
2212
2286
|
}, {
|
|
2213
|
-
children: !isVariantHidden ?
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2287
|
+
children: !isVariantHidden ? jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2288
|
+
children: [!isComponentForwardRef && jsxRuntime.jsx(ComponentMarker, {
|
|
2289
|
+
ref: componentRef
|
|
2290
|
+
}), /*#__PURE__*/React.createElement(Component, Object.assign({}, Object.assign(Object.assign({}, passthroughProps), variant), {
|
|
2291
|
+
key: `${experience.id}-${variant.id}`,
|
|
2292
|
+
ninetailed: {
|
|
2293
|
+
isPersonalized,
|
|
2294
|
+
audience: {
|
|
2295
|
+
id: (audience === null || audience === void 0 ? void 0 : audience.id) || 'all visitors'
|
|
2296
|
+
}
|
|
2219
2297
|
}
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2298
|
+
}, isComponentForwardRef ? {
|
|
2299
|
+
ref: componentRef
|
|
2300
|
+
} : {}))]
|
|
2301
|
+
}) : null
|
|
2222
2302
|
}));
|
|
2223
2303
|
};
|
|
2224
2304
|
|
|
@@ -2380,47 +2460,39 @@ const ExperimentsProvider = ({
|
|
|
2380
2460
|
}));
|
|
2381
2461
|
};
|
|
2382
2462
|
|
|
2383
|
-
const NinetailedProvider =
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
onError
|
|
2412
|
-
});
|
|
2413
|
-
}, []);
|
|
2414
|
-
const {
|
|
2415
|
-
experiments = [],
|
|
2416
|
-
maximumActiveExperiments,
|
|
2417
|
-
children
|
|
2418
|
-
} = props;
|
|
2463
|
+
const NinetailedProvider = ({
|
|
2464
|
+
children,
|
|
2465
|
+
clientId,
|
|
2466
|
+
experiments: _experiments = [],
|
|
2467
|
+
maximumActiveExperiments,
|
|
2468
|
+
environment,
|
|
2469
|
+
preview,
|
|
2470
|
+
url,
|
|
2471
|
+
profile,
|
|
2472
|
+
locale,
|
|
2473
|
+
requestTimeout,
|
|
2474
|
+
plugins: _plugins = [],
|
|
2475
|
+
onLog,
|
|
2476
|
+
onError
|
|
2477
|
+
}) => {
|
|
2478
|
+
const ninetailed = React.useMemo(() => new experience_js.Ninetailed({
|
|
2479
|
+
clientId,
|
|
2480
|
+
environment,
|
|
2481
|
+
preview
|
|
2482
|
+
}, {
|
|
2483
|
+
url,
|
|
2484
|
+
plugins: _plugins,
|
|
2485
|
+
profile,
|
|
2486
|
+
locale,
|
|
2487
|
+
requestTimeout,
|
|
2488
|
+
onLog,
|
|
2489
|
+
onError
|
|
2490
|
+
}), []);
|
|
2419
2491
|
return jsxRuntime.jsx(NinetailedContext.Provider, Object.assign({
|
|
2420
2492
|
value: ninetailed
|
|
2421
2493
|
}, {
|
|
2422
2494
|
children: jsxRuntime.jsx(ExperimentsProvider, Object.assign({
|
|
2423
|
-
experiments:
|
|
2495
|
+
experiments: _experiments,
|
|
2424
2496
|
maximumActiveExperiments: maximumActiveExperiments
|
|
2425
2497
|
}, {
|
|
2426
2498
|
children: children
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import React, { createContext, useContext, useEffect, useState, useRef, useMemo, createElement as createElement$1, useCallback } from 'react';
|
|
2
|
+
import React, { createContext, useContext, useEffect, useState, useRef, useMemo, forwardRef, createElement as createElement$1, useCallback } from 'react';
|
|
3
3
|
import { selectDistribution, makeExperienceSelectMiddleware, selectHasExperienceVariants, selectActiveExperiments, selectExperience, selectExperienceVariant, Ninetailed, selectVariant } from '@ninetailed/experience.js';
|
|
4
|
+
import { isForwardRef } from 'react-is';
|
|
4
5
|
import { useInView } from 'react-intersection-observer';
|
|
5
6
|
import { isBrowser, logger } from '@ninetailed/experience.js-shared';
|
|
6
7
|
import { isEqual, debounce as debounce$1, get as get$1 } from 'radash';
|
|
@@ -2079,6 +2080,36 @@ const useJoinExperiment = () => {
|
|
|
2079
2080
|
return context.joinExperiment;
|
|
2080
2081
|
};
|
|
2081
2082
|
|
|
2083
|
+
const ComponentMarker = /*#__PURE__*/forwardRef((_, ref) => {
|
|
2084
|
+
const {
|
|
2085
|
+
logger
|
|
2086
|
+
} = useNinetailed();
|
|
2087
|
+
const markerRef = useRef(null);
|
|
2088
|
+
useEffect(() => {
|
|
2089
|
+
// TODO: Create a better message
|
|
2090
|
+
logger.debug('Using fallback mechanism to select component.');
|
|
2091
|
+
}, [logger]);
|
|
2092
|
+
useEffect(() => {
|
|
2093
|
+
if (markerRef.current) {
|
|
2094
|
+
const nextSibling = markerRef.current.nextSibling;
|
|
2095
|
+
if (ref) {
|
|
2096
|
+
if (typeof ref === 'function') {
|
|
2097
|
+
ref(nextSibling);
|
|
2098
|
+
} else {
|
|
2099
|
+
ref.current = nextSibling;
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
}, []);
|
|
2104
|
+
return jsx("div", {
|
|
2105
|
+
className: "nt-cmp-marker",
|
|
2106
|
+
style: {
|
|
2107
|
+
display: 'none !important'
|
|
2108
|
+
},
|
|
2109
|
+
ref: markerRef
|
|
2110
|
+
});
|
|
2111
|
+
});
|
|
2112
|
+
|
|
2082
2113
|
const DefaultExperienceLoadingComponent = _a => {
|
|
2083
2114
|
var {
|
|
2084
2115
|
component: Component,
|
|
@@ -2132,6 +2163,10 @@ const Experience = _a => {
|
|
|
2132
2163
|
passthroughProps
|
|
2133
2164
|
} = _a,
|
|
2134
2165
|
baseline = __rest(_a, ["experiences", "component", "loadingComponent", "passthroughProps"]);
|
|
2166
|
+
const {
|
|
2167
|
+
observeElement,
|
|
2168
|
+
unobserveElement
|
|
2169
|
+
} = useNinetailed();
|
|
2135
2170
|
// TODO we actually could hook into the experience hook here with the plugins
|
|
2136
2171
|
const {
|
|
2137
2172
|
status,
|
|
@@ -2146,6 +2181,10 @@ const Experience = _a => {
|
|
|
2146
2181
|
experiences
|
|
2147
2182
|
});
|
|
2148
2183
|
const joinExperiment = useJoinExperiment();
|
|
2184
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2185
|
+
// @ts-ignore
|
|
2186
|
+
const isComponentForwardRef = isForwardRef(jsx(Component, {}));
|
|
2187
|
+
const componentRef = useRef(null);
|
|
2149
2188
|
useEffect(() => {
|
|
2150
2189
|
if (status === 'success' && experience && profile) {
|
|
2151
2190
|
joinExperiment({
|
|
@@ -2155,10 +2194,33 @@ const Experience = _a => {
|
|
|
2155
2194
|
});
|
|
2156
2195
|
}
|
|
2157
2196
|
}, [status, experience, profile]);
|
|
2197
|
+
useEffect(() => {
|
|
2198
|
+
const componentElement = componentRef.current;
|
|
2199
|
+
if (componentElement) {
|
|
2200
|
+
observeElement({
|
|
2201
|
+
element: componentElement,
|
|
2202
|
+
experienceId: experience === null || experience === void 0 ? void 0 : experience.id,
|
|
2203
|
+
variantId: variant === null || variant === void 0 ? void 0 : variant.id,
|
|
2204
|
+
baselineId: baseline.id,
|
|
2205
|
+
audienceId: audience === null || audience === void 0 ? void 0 : audience.id
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
return () => {
|
|
2209
|
+
if (componentElement) {
|
|
2210
|
+
unobserveElement(componentElement);
|
|
2211
|
+
}
|
|
2212
|
+
};
|
|
2213
|
+
}, [observeElement, unobserveElement, experience, baseline, variant, audience]);
|
|
2158
2214
|
if (!hasVariants) {
|
|
2159
|
-
return
|
|
2160
|
-
|
|
2161
|
-
|
|
2215
|
+
return jsxs(Fragment, {
|
|
2216
|
+
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
2217
|
+
ref: componentRef
|
|
2218
|
+
}), /*#__PURE__*/createElement$1(Component, Object.assign({}, passthroughProps, baseline, {
|
|
2219
|
+
key: baseline.id
|
|
2220
|
+
}, isComponentForwardRef ? {
|
|
2221
|
+
ref: componentRef
|
|
2222
|
+
} : {}))]
|
|
2223
|
+
});
|
|
2162
2224
|
}
|
|
2163
2225
|
if (status === 'loading') {
|
|
2164
2226
|
return /*#__PURE__*/createElement$1(LoadingComponent, Object.assign({}, baseline, {
|
|
@@ -2169,14 +2231,20 @@ const Experience = _a => {
|
|
|
2169
2231
|
}));
|
|
2170
2232
|
}
|
|
2171
2233
|
if (!experience) {
|
|
2172
|
-
return
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2234
|
+
return jsxs(Fragment, {
|
|
2235
|
+
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
2236
|
+
ref: componentRef
|
|
2237
|
+
}), jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
2238
|
+
ninetailed: {
|
|
2239
|
+
isPersonalized: false,
|
|
2240
|
+
audience: {
|
|
2241
|
+
id: 'baseline'
|
|
2242
|
+
}
|
|
2177
2243
|
}
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2244
|
+
}, isComponentForwardRef ? {
|
|
2245
|
+
ref: componentRef
|
|
2246
|
+
} : {}))]
|
|
2247
|
+
});
|
|
2180
2248
|
}
|
|
2181
2249
|
if (!variant) {
|
|
2182
2250
|
return jsx(TrackExperience, Object.assign({
|
|
@@ -2185,14 +2253,20 @@ const Experience = _a => {
|
|
|
2185
2253
|
// the profile is definitely defined, otherwise there wouldn't be an experience selected
|
|
2186
2254
|
profile: profile
|
|
2187
2255
|
}, {
|
|
2188
|
-
children:
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2256
|
+
children: jsxs(Fragment, {
|
|
2257
|
+
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
2258
|
+
ref: componentRef
|
|
2259
|
+
}), jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
2260
|
+
ninetailed: {
|
|
2261
|
+
isPersonalized: false,
|
|
2262
|
+
audience: {
|
|
2263
|
+
id: (audience === null || audience === void 0 ? void 0 : audience.id) || 'all visitors'
|
|
2264
|
+
}
|
|
2193
2265
|
}
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2266
|
+
}, isComponentForwardRef ? {
|
|
2267
|
+
ref: componentRef
|
|
2268
|
+
} : {}))]
|
|
2269
|
+
})
|
|
2196
2270
|
}), baseline.id);
|
|
2197
2271
|
}
|
|
2198
2272
|
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
@@ -2202,15 +2276,21 @@ const Experience = _a => {
|
|
|
2202
2276
|
// the profile is definitely defined, otherwise there wouldn't be an experience selected
|
|
2203
2277
|
profile: profile
|
|
2204
2278
|
}, {
|
|
2205
|
-
children: !isVariantHidden ?
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2279
|
+
children: !isVariantHidden ? jsxs(Fragment, {
|
|
2280
|
+
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
2281
|
+
ref: componentRef
|
|
2282
|
+
}), /*#__PURE__*/createElement$1(Component, Object.assign({}, Object.assign(Object.assign({}, passthroughProps), variant), {
|
|
2283
|
+
key: `${experience.id}-${variant.id}`,
|
|
2284
|
+
ninetailed: {
|
|
2285
|
+
isPersonalized,
|
|
2286
|
+
audience: {
|
|
2287
|
+
id: (audience === null || audience === void 0 ? void 0 : audience.id) || 'all visitors'
|
|
2288
|
+
}
|
|
2211
2289
|
}
|
|
2212
|
-
}
|
|
2213
|
-
|
|
2290
|
+
}, isComponentForwardRef ? {
|
|
2291
|
+
ref: componentRef
|
|
2292
|
+
} : {}))]
|
|
2293
|
+
}) : null
|
|
2214
2294
|
}));
|
|
2215
2295
|
};
|
|
2216
2296
|
|
|
@@ -2372,47 +2452,39 @@ const ExperimentsProvider = ({
|
|
|
2372
2452
|
}));
|
|
2373
2453
|
};
|
|
2374
2454
|
|
|
2375
|
-
const NinetailedProvider =
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
onError
|
|
2404
|
-
});
|
|
2405
|
-
}, []);
|
|
2406
|
-
const {
|
|
2407
|
-
experiments = [],
|
|
2408
|
-
maximumActiveExperiments,
|
|
2409
|
-
children
|
|
2410
|
-
} = props;
|
|
2455
|
+
const NinetailedProvider = ({
|
|
2456
|
+
children,
|
|
2457
|
+
clientId,
|
|
2458
|
+
experiments: _experiments = [],
|
|
2459
|
+
maximumActiveExperiments,
|
|
2460
|
+
environment,
|
|
2461
|
+
preview,
|
|
2462
|
+
url,
|
|
2463
|
+
profile,
|
|
2464
|
+
locale,
|
|
2465
|
+
requestTimeout,
|
|
2466
|
+
plugins: _plugins = [],
|
|
2467
|
+
onLog,
|
|
2468
|
+
onError
|
|
2469
|
+
}) => {
|
|
2470
|
+
const ninetailed = useMemo(() => new Ninetailed({
|
|
2471
|
+
clientId,
|
|
2472
|
+
environment,
|
|
2473
|
+
preview
|
|
2474
|
+
}, {
|
|
2475
|
+
url,
|
|
2476
|
+
plugins: _plugins,
|
|
2477
|
+
profile,
|
|
2478
|
+
locale,
|
|
2479
|
+
requestTimeout,
|
|
2480
|
+
onLog,
|
|
2481
|
+
onError
|
|
2482
|
+
}), []);
|
|
2411
2483
|
return jsx(NinetailedContext.Provider, Object.assign({
|
|
2412
2484
|
value: ninetailed
|
|
2413
2485
|
}, {
|
|
2414
2486
|
children: jsx(ExperimentsProvider, Object.assign({
|
|
2415
|
-
experiments:
|
|
2487
|
+
experiments: _experiments,
|
|
2416
2488
|
maximumActiveExperiments: maximumActiveExperiments
|
|
2417
2489
|
}, {
|
|
2418
2490
|
children: children
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { NinetailedPlugin, ExperienceConfiguration } from '@ninetailed/experience.js';
|
|
3
3
|
import { Profile, Locale, OnErrorHandler, OnLogHandler } from '@ninetailed/experience.js-shared';
|
|
4
|
-
type
|
|
5
|
-
experiments?: ExperienceConfiguration<any>[];
|
|
6
|
-
maximumActiveExperiments?: number;
|
|
7
|
-
};
|
|
8
|
-
export type NinetailedProviderInstantiationProps = {
|
|
4
|
+
export type NinetailedProviderProps = {
|
|
9
5
|
clientId: string;
|
|
10
6
|
environment?: string;
|
|
7
|
+
experiments?: ExperienceConfiguration<any>[];
|
|
8
|
+
maximumActiveExperiments?: number;
|
|
11
9
|
preview?: boolean;
|
|
12
10
|
url?: string;
|
|
13
11
|
plugins?: (NinetailedPlugin | NinetailedPlugin[])[];
|
|
@@ -16,9 +14,5 @@ export type NinetailedProviderInstantiationProps = {
|
|
|
16
14
|
requestTimeout?: number;
|
|
17
15
|
onLog?: OnLogHandler;
|
|
18
16
|
onError?: OnErrorHandler;
|
|
19
|
-
}
|
|
20
|
-
export
|
|
21
|
-
ninetailed: Ninetailed;
|
|
22
|
-
} & ExperimentProviderProps);
|
|
23
|
-
export declare const NinetailedProvider: (props: React.PropsWithChildren<NinetailedProviderProps>) => JSX.Element;
|
|
24
|
-
export {};
|
|
17
|
+
};
|
|
18
|
+
export declare const NinetailedProvider: ({ children, clientId, experiments, maximumActiveExperiments, environment, preview, url, profile, locale, requestTimeout, plugins, onLog, onError, }: React.PropsWithChildren<NinetailedProviderProps>) => JSX.Element;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { Profile, Variant } from '@ninetailed/experience.js-shared';
|
|
2
2
|
export type { ExperienceConfiguration, ExperienceType, EXPERIENCE_TRAIT_PREFIX, } from '@ninetailed/experience.js';
|
|
3
3
|
export { NinetailedProvider } from './NinetailedProvider';
|
|
4
|
-
export type { NinetailedProviderProps
|
|
4
|
+
export type { NinetailedProviderProps } from './NinetailedProvider';
|
|
5
5
|
export { useNinetailed } from './useNinetailed';
|
|
6
6
|
export { useProfile } from './useProfile';
|
|
7
7
|
export { usePersonalize } from './usePersonalize';
|
package/lib/useProfile.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare const useProfile: () => {
|
|
|
10
10
|
status: "success";
|
|
11
11
|
profile: {
|
|
12
12
|
id: string;
|
|
13
|
+
stableId: string;
|
|
13
14
|
random: number;
|
|
14
15
|
audiences: string[];
|
|
15
16
|
traits: import("@ninetailed/experience.js-shared").Properties;
|
|
@@ -28,6 +29,7 @@ export declare const useProfile: () => {
|
|
|
28
29
|
timezone?: string | undefined;
|
|
29
30
|
};
|
|
30
31
|
session: {
|
|
32
|
+
id: string;
|
|
31
33
|
isReturningVisitor: boolean;
|
|
32
34
|
landingPage: {
|
|
33
35
|
path: string;
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0-beta.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"react": ">=16.8.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@analytics/google-analytics": "0.5.3",
|
|
9
9
|
"react-visibility-sensor": "5.1.1",
|
|
10
|
-
"@ninetailed/experience.js": "4.
|
|
10
|
+
"@ninetailed/experience.js": "4.3.0-beta.0",
|
|
11
|
+
"react-is": "18.2.0",
|
|
11
12
|
"react-intersection-observer": "8.34.0",
|
|
12
|
-
"@ninetailed/experience.js-shared": "4.
|
|
13
|
+
"@ninetailed/experience.js-shared": "4.3.0-beta.0",
|
|
13
14
|
"radash": "10.9.0",
|
|
14
15
|
"analytics": "0.8.1"
|
|
15
16
|
},
|