- Create an Optimizely Account
- Navigate to the codepen and follow the instructions below!
- Turn off any ad-blockers! Ad-blockers can prevent this demo from working.
- Initialize Optimizely with the following code (replacing SDK Key from your development environment):
// Step 1: Initialize Optimizely
const optimizely = optimizelySdk.createInstance({
sdkKey: 'Your_SDK_Key',
datafileOptions: {
autoUpdate: true,
updateInterval: 1*1000
},
logLevel: 'info',
});
- Implement the feature flag:
// Step 2: Install a feature flag
var enabled = optimizely.isFeatureEnabled('astronaut_feature', 'user123')
- Create a feature in the UI called
astronaut_feature. - Turn the feature on!
- Create an audience to target specific attributes (ex:
tableis a number equal to4) - Pass those attributes in the code:
// Step 2: Install a feature flag
var enabled = optimizely.isFeatureEnabled('astronaut_feature', 'user123', { table: 4 })
- Add the audience to the feature and target specific user groups!
How is the Optimizely SDK imported into this Astronaut Demo?
- The Optimizely SDK is installed in the Astronaut Demo via an HTML script tag which makes the SDK available as a global variable called
optimizelySdk. In most applications the SDK would be installed via a package manager alongside other 3rd party SDKs, but since we are restricted in the demo environment, we use an HTML script tag.