Guest User

Untitled

a guest
Dec 10th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import { OptimizelySDKWrapper } from './index'
  2. import { Experiment } from './Datafile'
  3. var datafile = require('../extensionDatafile.json')
  4.  
  5. const optimizely = new OptimizelySDKWrapper({
  6. datafile,
  7. userId: 'jordan',
  8. })
  9.  
  10. const filterByActionType = (actionType: string) => (experiment: Experiment): boolean => {
  11. const variationData = experiment.variations[0].data
  12. if (!variationData) {
  13. return false
  14. }
  15.  
  16. return variationData.some(action => action.$type === actionType)
  17. }
  18.  
  19. function activate(articleIds: string[]) {
  20. const headlineExps = optimizely.data.getExperiments().filter(filterByActionType('headline'))
  21. console.log('got headlineExps', headlineExps)
  22.  
  23. let headlineChanges: Experiment.Action[] = []
  24.  
  25. headlineExps.forEach(exp => {
  26. const data = optimizely.getExperimentData(exp.key)
  27. if (!data) {
  28. return
  29. }
  30.  
  31. data.forEach(action => {
  32. if (action.$type === 'headline') {
  33. if (articleIds.indexOf(action.articleId as string) > -1) {
  34. headlineChanges.push(action)
  35. }
  36. }
  37. })
  38. })
  39.  
  40. console.log('headline changes ', headlineChanges)
  41. }
  42.  
  43. activate(['article1', 'article2'])
Add Comment
Please, Sign In to add comment