Skip to content

Commit 4613437

Browse files
author
tjj5036
committed
Starts on core of Activate function
1 parent 8353c88 commit 4613437

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

optimizely/optimizely.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,37 @@ func (client *OptimizelyClient) Track(
7777
// user_id: ID for user
7878
// attributes: optional list representing visitor attributes and values
7979
func (client *OptimizelyClient) Activate(experiment_key string, user_id string, attributes []AttributeEntity) {
80+
var valid_experiment = false
81+
var experiment_id = ""
82+
for i := 0; i < len(client.project_config.Experiments); i++ {
83+
if client.project_config.Experiments[i].Key == experiment_key {
84+
if ExperimentIsRunning(client.project_config.Experiments[i]) {
85+
valid_experiment = true
86+
experiment_id = client.project_config.Experiments[i].Id
87+
}
88+
}
89+
}
90+
91+
if !valid_experiment {
92+
return
93+
}
94+
95+
end_user_id := fmt.Sprintf(END_USER_ID_TEMPLATE, user_id)
96+
//variation_id := client.Bucket(experiment_key, user_id)
97+
98+
parameters := url.Values{}
99+
parameters.Add(ACCOUNT_ID, client.account_id)
100+
parameters.Add(PROJECT_ID, client.project_config.ProjectId)
101+
parameters.Add(GOAL_NAME, "TODO")
102+
parameters.Add(GOAL_ID, experiment_id)
103+
parameters.Add(END_USER_ID, end_user_id)
104+
105+
// Set attribute params if any
106+
if len(attributes) > 0 {
107+
BuildAttributeParams(client.project_config, attributes, parameters)
108+
}
109+
110+
// TODO dispatch event
80111

81112
}
82113

optimizely/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func BuildAttributeParams(
4545
// Checks the status of an Experiment to see if its running or not
4646
// This could be a one liner but the `Status` field will most likely
4747
// grow and require a switch or something.
48-
func experiment_is_running(experiment ExperimentEntity) bool {
48+
func ExperimentIsRunning(experiment ExperimentEntity) bool {
4949
if experiment.Status != "Running" {
5050
return true
5151
}
@@ -72,7 +72,7 @@ func BuildExperimentVariationParams(
7272
parameters url.Values) {
7373

7474
for i := 0; i < len(experiments); i++ {
75-
if !experiment_is_running(experiments[i]) {
75+
if !ExperimentIsRunning(experiments[i]) {
7676
continue
7777
}
7878
experiment_id := experiments[i].Id

0 commit comments

Comments
 (0)