Skip to content

Commit 417a5dc

Browse files
committed
Merge pull request #8 from optimizely/get_variation_addition
Adds in bulk of GetVariation
2 parents 5080e1f + f31b675 commit 417a5dc

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

optimizely/optimizely.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ func (client *OptimizelyClient) Activate(experiment_key string, user_id string,
8080

8181
}
8282

83-
// GetVariation gets the variation where the visitor will be bucketed
83+
// GetVariation gets the variation key where the visitor will be bucketed
8484
// Experiment_key: experiment which needs to be activated
8585
// User_id: ID for user
8686
// Returns: variation key representing the variation the user will be
8787
// bucketed into
88-
func (client *OptimizelyClient) GetVariation(experient_key string, user_id string) {
89-
88+
func (client *OptimizelyClient) GetVariation(experiment_key string, user_id string) string {
89+
variation_id := client.Bucket(experiment_key, user_id)
90+
variation_key := GetVariationKeyFromId(experiment_key, variation_id, client.project_config.Experiments)
91+
return variation_key
9092
}

optimizely/utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,19 @@ func BuildExperimentVariationParams(
8585
}
8686
}
8787
}
88+
89+
// Gets variation key given experiment key and variation id
90+
// experiment_key: key representing parent experiment of variation
91+
// variation_id: ID of the variation
92+
// experiments: Array of ExperimentEntities
93+
// Returns: variation key (string)
94+
func GetVariationKeyFromId(experiment_key string, variation_id string, experiments []ExperimentEntity) string {
95+
for i := 0; i < len(experiments); i++ {
96+
for j := 0; j < len(experiments[i].Variations); j++ {
97+
if experiments[i].Variations[j].Id == variation_id {
98+
return experiments[i].Variations[j].Key
99+
}
100+
}
101+
}
102+
return ""
103+
}

0 commit comments

Comments
 (0)