1
1
package optimizely
2
2
3
- import (
4
- "fmt"
5
- "net/url"
6
- )
7
-
8
3
// GetOptimizelyClient returns a client that can be used to interface
9
4
// with Optimizely
10
5
func GetOptimizelyClient (account_id string ) (* OptimizelyClient , error ) {
@@ -31,46 +26,6 @@ func (client *OptimizelyClient) Track(
31
26
attributes []AttributeEntity ,
32
27
event_value string ) {
33
28
34
- // Create and distpatch conversion event
35
-
36
- var Url * url.URL
37
- Url , err := url .Parse ("" )
38
- if err != nil {
39
- panic ("boom" )
40
- }
41
-
42
- end_user_id := fmt .Sprintf (END_USER_ID_TEMPLATE , user_id )
43
- goal_id := GetGoalIdFromProjectConfig (event_key , client .project_config )
44
-
45
- // build string to make GET request with
46
- parameters := url.Values {}
47
- parameters .Add (ACCOUNT_ID , client .account_id )
48
- parameters .Add (PROJECT_ID , client .project_config .ProjectId )
49
- parameters .Add (GOAL_NAME , event_key )
50
- parameters .Add (GOAL_ID , goal_id )
51
- parameters .Add (END_USER_ID , end_user_id )
52
-
53
- // Set experiment and corresponding variation
54
- BuildExperimentVariationParams (
55
- client .project_config , event_key , client .project_config .Experiments , user_id , parameters )
56
-
57
- // Set attribute params if any
58
- if len (attributes ) > 0 {
59
- BuildAttributeParams (client .project_config , attributes , parameters )
60
- }
61
-
62
- // Set event_value if set and also append the revenue goal ID
63
- if len (event_value ) != 0 {
64
- parameters .Add (REVENUE , event_value )
65
- //parameters.Add(GOAL_ID, fmt.Sprintf(
66
- //"{%v},{%v}", goal_id, GetRevenueGoalFromProjectConfig())
67
- }
68
-
69
- // Dispatch event
70
- Url .RawQuery = parameters .Encode ()
71
- tracking_url := Url .String ()
72
- fmt .Print (tracking_url )
73
-
74
29
}
75
30
76
31
// Activate buckets visitor and sends impression event to Optimizely
@@ -80,12 +35,10 @@ func (client *OptimizelyClient) Track(
80
35
// attributes: optional list representing visitor attributes and values
81
36
func (client * OptimizelyClient ) Activate (experiment_key string , user_id string , attributes []AttributeEntity ) {
82
37
var valid_experiment = false
83
- var experiment_id = ""
84
38
for i := 0 ; i < len (client .project_config .Experiments ); i ++ {
85
39
if client .project_config .Experiments [i ].Key == experiment_key {
86
40
if ExperimentIsRunning (client .project_config .Experiments [i ]) {
87
41
valid_experiment = true
88
- experiment_id = client .project_config .Experiments [i ].Id
89
42
}
90
43
}
91
44
}
@@ -94,23 +47,9 @@ func (client *OptimizelyClient) Activate(experiment_key string, user_id string,
94
47
return
95
48
}
96
49
97
- end_user_id := fmt .Sprintf (END_USER_ID_TEMPLATE , user_id )
98
- variation_id := client .Bucket (experiment_key , user_id )
99
-
100
- parameters := url.Values {}
101
- parameters .Add (ACCOUNT_ID , client .account_id )
102
- parameters .Add (PROJECT_ID , client .project_config .ProjectId )
103
- parameters .Add (GOAL_NAME , GenerateGoalName (client .project_config .Events ))
104
- parameters .Add (fmt .Sprintf ("{%v}{%v}" , EXPERIMENT , experiment_id ), variation_id )
105
- parameters .Add (GOAL_ID , experiment_id )
106
- parameters .Add (END_USER_ID , end_user_id )
107
-
108
- // Set attribute params if any
109
- if len (attributes ) > 0 {
110
- BuildAttributeParams (client .project_config , attributes , parameters )
111
- }
112
-
113
- // TODO dispatch event
50
+ variation_id := ""
51
+ impression_event := CreateImpressionEvent (
52
+ client , experiment_key , variation_id , user_id , attributes )
114
53
115
54
}
116
55
0 commit comments