1
1
package optimizely
2
2
3
+ import (
4
+ "fmt"
5
+ "net/url"
6
+ "time"
7
+ )
8
+
3
9
var OFFLINE_API_PATH = "https://%v.log.optimizely.com/event" // project_id
4
10
var END_USER_ID_TEMPLATE = "oeu-%v" // user_id
5
11
@@ -14,8 +20,72 @@ const (
14
20
REVENUE = "v"
15
21
SOURCE = "src"
16
22
TIME = "time"
23
+ SDK_VERSION = "0.0"
17
24
)
18
25
19
26
func DispatchEvent () {
20
27
21
28
}
29
+
30
+ type Event struct {
31
+ params url.Values
32
+ }
33
+
34
+ // Add experiment to variation mapping to the impression event
35
+ // experiment_key: Experiment which is being activated
36
+ // variation_id: id for variation which would be presented to the user
37
+ func (event * Event ) add_experiment (experiment_key string , variation_id string ) {
38
+
39
+ }
40
+
41
+ // Add imp[ression goal information to the event
42
+ // experiment_key: Experiment which is being activated
43
+ func (event * Event ) add_impression_goal (experiment_key string ) {
44
+
45
+ }
46
+
47
+ // Get segment Id for the provided attribute key
48
+ // project_config: the project_Config
49
+ // attributes: the attributes to search through
50
+ // attribute_key: the attribute key for which segment ID is to be determined
51
+ func GetSementId (project_config ProjectConfig , attributes []AttributeEntity , attribute_key string ) string {
52
+ for i := 0 ; i < len (attributes ); i ++ {
53
+ if attributes [i ].Key == attribute_key {
54
+ return attributes [i ].SegmentId
55
+ }
56
+ }
57
+ return ""
58
+ }
59
+
60
+ // BuildAttributeParams adds attribute parameters to the URL Value Map
61
+ func build_attribute_params (event * Event , project_config ProjectConfig , attributes []AttributeEntity ) {
62
+ for i := 0 ; i < len (attributes ); i ++ {
63
+ segment_id := GetSementId (project_config , attributes , attributes [i ].Key )
64
+ if len (segment_id ) > 0 {
65
+ event .params .Add (fmt .Sprintf ("{%v}{%v}" , SEGMENT , segment_id ), attributes [i ].Value )
66
+ }
67
+ }
68
+ }
69
+
70
+ // Add params which are used in both conversion and impression events
71
+ // user_id: Id for user
72
+ // attributes: array representing user attributes and values which need to be recorded
73
+ func (event * Event ) add_common_params (client * OptimizelyClient , user_id string , attributes []AttributeEntity ) {
74
+ event .params .Add (PROJECT_ID , client .project_config .ProjectId )
75
+ event .params .Add (ACCOUNT_ID , client .account_id )
76
+ event .params .Add (END_USER_ID , user_id )
77
+ build_attribute_params (event , client .project_config , attributes )
78
+ event .params .Add (SOURCE , fmt .Sprintf ("go-sdk-%v" , SDK_VERSION ))
79
+ event .params .Add (TIME , fmt .Sprint ("%v" , time .Now ().Unix ()))
80
+ }
81
+
82
+ // Create impression Event to be sent to the logging endpoint.
83
+ // experiment_key: Experiment for which impression needs to be recorded.
84
+ // variation_id: ID for variation which would be presented to user.
85
+ // user_id: ID for user.
86
+ // attributes: Dict representing user attributes and values which need to be recorded.
87
+ // Returns: Event object encapsulating the impression event.
88
+ func CreateImpressionEvent (client * OptimizelyClient , experiment_key string , variation_id string , user_id string , attributes []AttributeEntity ) {
89
+ event := & Event {}
90
+ event .add_common_params (client , user_id , attributes )
91
+ }
0 commit comments