Skip to content

Commit 5a01392

Browse files
[FSSDK-11403] readme change
1 parent b10dbb5 commit 5a01392

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

README.md

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Optimizely Rollouts is [free feature flags](https://www.optimizely.com/free-feat
2121
> For **Node.js** applications, refer to the [JavaScript (Node) variant of the developer documentation](https://docs.developers.optimizely.com/feature-experimentation/docs/javascript-node-sdk).
2222
2323
> For **Edge Functions**, we provide starter kits that utilize the Optimizely JavaScript SDK for the following platforms:
24+
>
2425
> - [Akamai (Edgeworkers)](https://github.com/optimizely/akamai-edgeworker-starter-kit)
2526
> - [AWS Lambda@Edge](https://github.com/optimizely/aws-lambda-at-edge-starter-kit)
2627
> - [Cloudflare Worker](https://github.com/optimizely/cloudflare-worker-template)
@@ -32,38 +33,44 @@ Optimizely Rollouts is [free feature flags](https://www.optimizely.com/free-feat
3233
### Prerequisites
3334

3435
Ensure the SDK supports all of the platforms you're targeting. In particular, the SDK targets modern ES6-compliant JavaScript environments. We officially support:
36+
3537
- Node.js >= 18.0.0. By extension, environments like AWS Lambda, Google Cloud Functions, and Auth0 Webtasks are supported as well. Older Node.js releases likely work too (try `npm test` to validate for yourself), but are not formally supported.
3638
- Modern Web Browsers, such as Microsoft Edge 84+, Firefox 91+, Safari 13+, and Chrome 102+, Opera 76+
3739

3840
In addition, other environments are likely compatible but are not formally supported including:
41+
3942
- Progressive Web Apps, WebViews, and hybrid mobile apps like those built with React Native and Apache Cordova.
4043
- [Cloudflare Workers](https://developers.cloudflare.com/workers/) and [Fly](https://fly.io/), both of which are powered by recent releases of V8.
4144
- Anywhere else you can think of that might embed a JavaScript engine. The sky is the limit; experiment everywhere! 🚀
4245

43-
4446
### Install the SDK
4547

4648
Once you've validated that the SDK supports the platforms you're targeting, fetch the package from [NPM](https://www.npmjs.com/package/@optimizely/optimizely-sdk):
4749

4850
Using `npm`:
51+
4952
```sh
5053
npm install --save @optimizely/optimizely-sdk
5154
```
5255

5356
Using `yarn`:
57+
5458
```sh
5559
yarn add @optimizely/optimizely-sdk
5660
```
5761

5862
Using `pnpm`:
63+
5964
```sh
6065
pnpm add @optimizely/optimizely-sdk
6166
```
6267

6368
Using `deno` (no installation required):
69+
6470
```javascript
65-
import optimizely from "npm:@optimizely/optimizely-sdk"
71+
import optimizely from 'npm:@optimizely/optimizely-sdk';
6672
```
73+
6774
## Use the JavaScript SDK
6875

6976
See the [Optimizely Feature Experimentation developer documentation for JavaScript](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/javascript-sdk) to learn how to set up your first JavaScript project and use the SDK for client-side applications.
@@ -78,19 +85,19 @@ import {
7885
createPollingProjectConfigManager,
7986
createBatchEventProcessor,
8087
createOdpManager,
81-
} from "@optimizely/optimizely-sdk";
88+
} from '@optimizely/optimizely-sdk';
8289

8390
// 1. Configure your project config manager
8491
const pollingConfigManager = createPollingProjectConfigManager({
85-
sdkKey: "<YOUR_SDK_KEY>",
86-
autoUpdate: true, // Optional: enable automatic updates
87-
updateInterval: 300000, // Optional: update every 5 minutes (in ms)
92+
sdkKey: '<YOUR_SDK_KEY>',
93+
autoUpdate: true, // Optional: enable automatic updates
94+
updateInterval: 300000, // Optional: update every 5 minutes (in ms)
8895
});
8996

9097
// 2. Create an event processor for analytics
9198
const batchEventProcessor = createBatchEventProcessor({
92-
batchSize: 10, // Optional: default batch size
93-
flushInterval: 1000, // Optional: flush interval in ms
99+
batchSize: 10, // Optional: default batch size
100+
flushInterval: 1000, // Optional: flush interval in ms
94101
});
95102

96103
// 3. Set up ODP manager for segments and audience targeting
@@ -103,20 +110,18 @@ const optimizelyClient = createInstance({
103110
odpManager: odpManager,
104111
});
105112

106-
// 5. Wait for the client to be ready before using
107-
if (optimizelyClient) {
108-
optimizelyClient.onReady()
109-
.then(() => {
110-
console.log("Optimizely client is ready");
111-
// Your application code using Optimizely goes here
112-
})
113-
.catch((error) => {
114-
console.error("Error initializing Optimizely client:", error);
115-
});
116-
}
113+
optimizelyClient
114+
.onReady()
115+
.then(() => {
116+
console.log('Optimizely client is ready');
117+
// Your application code using Optimizely goes here
118+
})
119+
.catch(error => {
120+
console.error('Error initializing Optimizely client:', error);
121+
});
117122
```
118123

119-
### Initialization (Using HTML)
124+
### Initialization (Using HTML)
120125

121126
The package has different entry points for different environments. The browser entry point is an ES module, which can be used with an appropriate bundler like **Webpack** or **Rollup**. Additionally, for ease of use during initial evaluations you can include a standalone umd bundle of the SDK in your web page by fetching it from [unpkg](https://unpkg.com/):
122127

@@ -138,42 +143,38 @@ As `window.optimizelySdk` should be a global variable at this point, you can con
138143
createInstance,
139144
createPollingProjectConfigManager,
140145
createBatchEventProcessor,
141-
createOdpManager
146+
createOdpManager,
142147
} = window.optimizelySdk;
143148
144149
// Initialize components
145150
const pollingConfigManager = createPollingProjectConfigManager({
146-
sdkKey: "<YOUR_SDK_KEY>",
147-
autoUpdate: true
151+
sdkKey: '<YOUR_SDK_KEY>',
152+
autoUpdate: true,
148153
});
149-
154+
150155
const batchEventProcessor = createBatchEventProcessor();
151-
156+
152157
const odpManager = createOdpManager();
153158
154159
// Create the Optimizely client
155160
const optimizelyClient = createInstance({
156161
projectConfigManager: pollingConfigManager,
157162
eventProcessor: batchEventProcessor,
158-
odpManager: odpManager
163+
odpManager: odpManager,
159164
});
160165
161-
// Wait for initialization to complete
162-
if (optimizelyClient) {
163-
optimizelyClient.onReady()
164-
.then(() => {
165-
console.log("Optimizely client is ready");
166-
// Start using the client here
167-
})
168-
.catch((error) => {
169-
console.error("Error initializing Optimizely client:", error);
170-
});
171-
}
166+
optimizelyClient
167+
.onReady()
168+
.then(() => {
169+
console.log('Optimizely client is ready');
170+
// Start using the client here
171+
})
172+
.catch(error => {
173+
console.error('Error initializing Optimizely client:', error);
174+
});
172175
</script>
173176
```
174177

175-
176-
177178
Regarding `EventDispatcher`s: In Node.js environment, the default `EventDispatcher` is powered by the [`http/s`](https://nodejs.org/api/http.html) module.
178179

179180
## SDK Development

0 commit comments

Comments
 (0)