Skip to content

Instantly share code, notes, and snippets.

Variation variation = optimizely.activate("experiment_name", userId);
if (variation != null) {
if (variation.is("control")) {
// execute code for control
} else if (variation.is("variation")) {
// execute code for variation
}
} else {
// execute default code
}
OptimizelyFactory optimizely = new OptimizelyFactory(dataFile);
//...
//...
Sort sortingAlgorithm = optimizelyFactory.getExperimentImpl(“ProductSort”, userId);
sort.sort(sampleProductList());
public ProductSort getExperimentImpl(String experimentName, String userId){
Variation variation = this.optimizelyClient.activate(experimentName, userId);
ProductSort retobj = null;
if(variation.getKey().equals("PriceProductSort")){
retobj = new CategoryProductSort();
} else if(variation.getKey().equals("NameProductSort")){
retobj = new NameProductSort();
} else if(variation.getKey().equals("CategoryProductSort")){
public T getExperimentImpl(String experimentName, String userId){
Variation variation = this.optimizelyClient.activate(experimentName, userId);
T retobj = null;
try {
String className = this.packageName + "." + variation.getKey();
Class cls = Class.forName(className);
Class partypes[] = new Class[0];
Constructor ct = cls.getConstructor(partypes);
OptimizelyReflectionFactory<ProductSort> optimizely = new OptimizelyReflectionFactory<ProductSort>();
//…
//…
ProductSort sort = optimizely.getExperimentImpl(“ProductSort”, input);
sort.sort(sampleProductList());
public T getVariableImpl(String featureFlag, String featureVariable, String userId){
String className = this.optimizelyClient.getFeatureVariableString(featureFlag, featureVariable, userId);
T retobj = null;
try {
Class cls = Class.forName(className);
Class partypes[] = new Class[0];
Constructor ct = cls.getConstructor(partypes);
retobj = (T)ct.newInstance();
public T getVariableImpl(String featureFlag, String featureVariable, String userId){
String className = this.optimizelyClient.getFeatureVariableString(featureFlag, featureVariable, userId);
T retobj = null;
try {
Class cls = Class.forName(className);
Class partypes[] = new Class[0];
Constructor ct = cls.getConstructor(partypes);
retobj = (T)ct.newInstance();
//Business Logic
//...
Variation variation = this.optimizelyClient.activate(experimentName, userId);
if(variation.is("CategoryProductSort")){
CategoryComparator comparator = new CategoryComparator();
Collections.sort(unSortedList, comparator);
} else if(variation.is("NameProductSort")){
NameComparator comparator = new NameComparator();
Collections.sort(unSortedList, comparator);
@asunwoo
asunwoo / seg_opt.js
Created December 13, 2018 18:27
Reference Segment Optimizely Integration in Node JS Express
const express = require('express')
const app = express()
const port = 80
var request = require('request');
var username = <Segment Workspace API username>
var password = ''
var url = 'https://profiles.segment.com/v1/spaces/<workspace_id>/collections/users/profiles/user_id:'