Skip to content

Commit f0cda40

Browse files
author
tjj5036
committed
Starts to follow the pattern as laid out in the other SDK
1 parent 8a59ed6 commit f0cda40

File tree

3 files changed

+72
-13
lines changed

3 files changed

+72
-13
lines changed

optimizely/event.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package optimizely
22

3+
import (
4+
"fmt"
5+
"net/url"
6+
"time"
7+
)
8+
39
var OFFLINE_API_PATH = "https://%v.log.optimizely.com/event" // project_id
410
var END_USER_ID_TEMPLATE = "oeu-%v" // user_id
511

@@ -14,8 +20,72 @@ const (
1420
REVENUE = "v"
1521
SOURCE = "src"
1622
TIME = "time"
23+
SDK_VERSION = "0.0"
1724
)
1825

1926
func DispatchEvent() {
2027

2128
}
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+
}

optimizely/optimizely.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func (client *OptimizelyClient) Track(
3131
attributes []AttributeEntity,
3232
event_value string) {
3333

34+
// Create and distpatch conversion event
35+
3436
var Url *url.URL
3537
Url, err := url.Parse("")
3638
if err != nil {

optimizely/utils.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ func GetGoalIdFromProjectConfig(event_key string, project_config ProjectConfig)
1919
return ""
2020
}
2121

22-
// Get segment Id for the provided attribute key
23-
// project_config: the project_Config
24-
// attributes: the attributes to search through
25-
// attribute_key: the attribute key for which segment ID is to be determined
26-
func GetSementId(project_config ProjectConfig, attributes []AttributeEntity, attribute_key string) string {
27-
for i := 0; i < len(attributes); i++ {
28-
if attributes[i].Key == attribute_key {
29-
return attributes[i].SegmentId
30-
}
31-
}
32-
return ""
33-
}
34-
3522
// BuildAttributeParams adds attribute parameters to the URL Value Map
3623
func BuildAttributeParams(
3724
project_config ProjectConfig,

0 commit comments

Comments
 (0)