Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { OptimizelySDKWrapper } from './index'
- import { Experiment } from './Datafile'
- var datafile = require('../extensionDatafile.json')
- const optimizely = new OptimizelySDKWrapper({
- datafile,
- userId: 'jordan',
- })
- const filterByActionType = (actionType: string) => (experiment: Experiment): boolean => {
- const variationData = experiment.variations[0].data
- if (!variationData) {
- return false
- }
- return variationData.some(action => action.$type === actionType)
- }
- function activate(articleIds: string[]) {
- const headlineExps = optimizely.data.getExperiments().filter(filterByActionType('headline'))
- console.log('got headlineExps', headlineExps)
- let headlineChanges: Experiment.Action[] = []
- headlineExps.forEach(exp => {
- const data = optimizely.getExperimentData(exp.key)
- if (!data) {
- return
- }
- data.forEach(action => {
- if (action.$type === 'headline') {
- if (articleIds.indexOf(action.articleId as string) > -1) {
- headlineChanges.push(action)
- }
- }
- })
- })
- console.log('headline changes ', headlineChanges)
- }
- activate(['article1', 'article2'])
Add Comment
Please, Sign In to add comment