11package optimizely
22
3- import (
4- "fmt"
5- "net/url"
6- )
7-
83// GetOptimizelyClient returns a client that can be used to interface
94// with Optimizely
105func GetOptimizelyClient (account_id string ) (* OptimizelyClient , error ) {
@@ -31,46 +26,6 @@ func (client *OptimizelyClient) Track(
3126 attributes []AttributeEntity ,
3227 event_value string ) {
3328
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-
7429}
7530
7631// Activate buckets visitor and sends impression event to Optimizely
@@ -80,12 +35,10 @@ func (client *OptimizelyClient) Track(
8035// attributes: optional list representing visitor attributes and values
8136func (client * OptimizelyClient ) Activate (experiment_key string , user_id string , attributes []AttributeEntity ) {
8237 var valid_experiment = false
83- var experiment_id = ""
8438 for i := 0 ; i < len (client .project_config .Experiments ); i ++ {
8539 if client .project_config .Experiments [i ].Key == experiment_key {
8640 if ExperimentIsRunning (client .project_config .Experiments [i ]) {
8741 valid_experiment = true
88- experiment_id = client .project_config .Experiments [i ].Id
8942 }
9043 }
9144 }
@@ -94,23 +47,9 @@ func (client *OptimizelyClient) Activate(experiment_key string, user_id string,
9447 return
9548 }
9649
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 )
11453
11554}
11655
0 commit comments