Skip to content

Instantly share code, notes, and snippets.

@asunwoo
asunwoo / personas_industry.json
Last active December 13, 2018 18:54
personas_industry.json
{
"traits": {
"email": "albertsemail@segment.com",
"industry": "b2b",
"name": "Albert Segment"
},
"cursor": {
"url": "",
"has_more": false,
"next": "",
@asunwoo
asunwoo / full_stack_attributes.js
Last active December 14, 2018 21:18
full_stack_attributes.js
var variation = optimizelyClient.activate("my_experiment", userId, {
industry: "b2b"
});
And:
optimizelyClient.track("my_event", userId, {
industry: "b2b"
});
@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:'
//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);
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();
OptimizelyReflectionFactory<ProductSort> optimizely = new OptimizelyReflectionFactory<ProductSort>();
//…
//…
ProductSort sort = optimizely.getExperimentImpl(“ProductSort”, input);
sort.sort(sampleProductList());
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);
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")){
OptimizelyFactory optimizely = new OptimizelyFactory(dataFile);
//...
//...
Sort sortingAlgorithm = optimizelyFactory.getExperimentImpl(“ProductSort”, userId);
sort.sort(sampleProductList());