2
2
3
3
Use Optimizely Feature Flags and AB Tests easily in React with a library of pre-built components.
4
4
5
+ ### Features
6
+
7
+ - Automatic datafile downloading and caching (through LocalStorage)
8
+ - User ID + Attributes memoization
9
+ - Render blocking until datafile is ready via an easy to use React API
10
+ - Optimizely Timeout - only block rendering up to X ms
11
+ - Event queuing for ` track ` , allows ` track ` calls to happen before datafile is downloaded
12
+ - Library of React components to use with Feature Flags and AB Tests
13
+
5
14
### Compatibility
6
15
7
16
` React 15.x + `
@@ -19,12 +28,16 @@ import optimizelySDK from '@optimizely/js-web-sdk'
19
28
20
29
const optimizely = optimizelySDK .createInstance ({
21
30
sdkKey: ' your-optimizely-sdk-key' ,
22
- userId: window .userId ,
23
31
})
24
32
25
33
class App extends React .Component {
26
34
render () {
27
- < OptimizelyProvider optimizely= {optimizely} timeout= {500 }>
35
+ < OptimizelyProvider
36
+ optimizely= {optimizely}
37
+ timeout= {500 }
38
+ userId= {window .userId }
39
+ userAttributes= {{ plan_type: ' bronze' }}
40
+ >
28
41
< OptimizelyExperiment experiment= " ab-test" >
29
42
{(variation ) => (
30
43
< p> got variation {variation}< / p>
@@ -62,7 +75,9 @@ This is required at the root level and leverages React’s `Context` API to allo
62
75
63
76
* props*
64
77
* ` optimizely : OptimizelySDK ` instance of the OptimizelySDK from ` @optimizely/js-web-sdk `
65
- * ` timeout : Number ` the amount for OptimizelyExperiment and OptimizelyFeature components to render ` null ` before resolving
78
+ * ` userId : String ` userId to be passed to the SDK for every Feature Flag / AB Test / ` track ` call
79
+ * ` userAttributes : Object ` (optional) userAttributes passed for every Feature Flag / AB Test / ` track ` call
80
+ * ` timeout : Number ` (optional) the amount for OptimizelyExperiment and OptimizelyFeature components to render ` null ` before resolving
66
81
67
82
### Loading the datafile synchronously
68
83
@@ -74,14 +89,13 @@ import { OptimizelyProvider } from '@optimizely/react-sdk'
74
89
import optimizelySDK from ' @optimizely/js-web-sdk'
75
90
76
91
const optimizely = optimizelySDK .createInstance ({
77
- userId: window .userId ,
78
92
datafile: window .datafile ,
79
93
})
80
94
81
95
class App extends React .Component {
82
96
render () {
83
97
return (
84
- < OptimizelyProvider optimizely= {optimizely}>
98
+ < OptimizelyProvider optimizely= {optimizely} userId = { window . userId } >
85
99
< App / >
86
100
< / OptimizelyProvider>
87
101
)
@@ -100,14 +114,18 @@ import { OptimizelyProvider } from '@optimizely/react-sdk'
100
114
import optimizelySDK from ' @optimizely/js-web-sdk'
101
115
102
116
const optimizely = optimizelySDK .createInstance ({
103
- userId: window .userId ,
104
117
SDKKey: ' your-optimizely-sdk-key' , // Optimizely environment key
105
118
})
106
119
107
120
class App extends React .Component {
108
121
render () {
109
122
return (
110
- < OptimizelyProvider optimizely= {optimizely} timeout= {200 }>
123
+ < OptimizelyProvider
124
+ optimizely= {optimizely}
125
+ timeout= {500 }
126
+ userId= {window .userId }
127
+ userAttributes= {{ plan_type: ' bronze' }}
128
+ >
111
129
< App / >
112
130
< / OptimizelyProvider>
113
131
)
0 commit comments