Created
December 6, 2018 21:11
-
-
Save jordangarcia/ce3fd1a658115ab22a2efead4f48c79e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Step 1 | |
* Explain what a datafile is, ie you have one for your project | |
* | |
* To use optimizely you need to first download your datafile and | |
* create an OptimizelySDK instance | |
*/ | |
// Requesting the datafile and instantiating the SD | |
const datafileUrl = 'https://cdn.optimizely.com/onboarding/7afe4c97c06f11e38cadf35d39e1180f.json' | |
const optimizelySDK = require('@optimizely/optimizely-sdk') | |
const fetch = require('node-fetch') | |
async function main() { | |
/** | |
* Step 1 download the datafile and create an instance | |
*/ | |
const userId = process.argv[2] || 'yeesheen' | |
const resp = await fetch(datafileUrl) | |
const datafile = await resp.json() | |
const optimizely = optimizelySDK.createInstance({ | |
datafile, | |
}); | |
/** | |
* Step 2 | |
* Explain what a feature is an make customer use isFeatureEnabled API | |
*/ | |
const isEnabled = optimizely.isFeatureEnabled('checkout_flow', userId) | |
console.log('isEnabled', isEnabled) | |
/** | |
* Step 3 | |
* Use a feature variable | |
*/ | |
const message = optimizely.getFeatureVariableString('checkout_flow', 'message', userId) | |
console.log('message', message) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment