-
Notifications
You must be signed in to change notification settings - Fork 26
/
identities.go
113 lines (93 loc) · 3.2 KB
/
identities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Package sensorsanalytics /*
package sensorsanalytics
import (
"errors"
"github.com/sensorsdata/sa-sdk-go/utils"
)
const (
BIND = "track_id_bind"
UNBIND = "track_id_unbind"
BIND_EVENT = "$BindID"
UNBIND_EVENT = "$UnbindID"
LOGIN_ID = "$identity_login_id"
MOBILE = "$identity_mobile"
EMAIL = "$identity_email"
)
type Identity struct {
Identities map[string]string
}
func (sa *SensorsAnalytics) Bind(identity Identity) error {
if identity.Identities == nil || len(identity.Identities) < 2 {
return errors.New("identity is invalid")
}
return TrackEventID3(sa, identity, BIND, BIND_EVENT, nil)
}
func (sa *SensorsAnalytics) UnBind(identity Identity) error {
if identity.Identities == nil {
return errors.New("identity is nil")
}
return TrackEventID3(sa, identity, UNBIND, UNBIND_EVENT, nil)
}
func (sa *SensorsAnalytics) TrackById(identity Identity, event string, properties map[string]interface{}) error {
var nproperties map[string]interface{}
// merge properties
if properties == nil {
nproperties = make(map[string]interface{})
} else {
nproperties = utils.DeepCopy(properties)
}
// merge super properties
if superProperties != nil {
utils.MergeSuperProperty(superProperties, nproperties)
}
return TrackEventID3(sa, identity, TRACK, event, nproperties)
}
func (sa *SensorsAnalytics) ProfileSetById(identity Identity, properties map[string]interface{}) error {
var nproperties map[string]interface{}
if properties == nil {
return errors.New("property should not be nil")
} else {
nproperties = utils.DeepCopy(properties)
}
return TrackEventID3(sa, identity, PROFILE_SET, "", nproperties)
}
func (sa *SensorsAnalytics) ProfileSetOnceById(identity Identity, properties map[string]interface{}) error {
var nproperties map[string]interface{}
if properties == nil {
return errors.New("property should not be nil")
} else {
nproperties = utils.DeepCopy(properties)
}
return TrackEventID3(sa, identity, PROFILE_SET_ONCE, "", nproperties)
}
func (sa *SensorsAnalytics) ProfileIncrementById(identity Identity, properties map[string]interface{}) error {
var nproperties map[string]interface{}
if properties == nil {
return errors.New("property should not be nil")
} else {
nproperties = utils.DeepCopy(properties)
}
return TrackEventID3(sa, identity, PROFILE_INCREMENT, "", nproperties)
}
func (sa *SensorsAnalytics) ProfileAppendById(identity Identity, properties map[string]interface{}) error {
var nproperties map[string]interface{}
if properties == nil {
return errors.New("property should not be nil")
} else {
nproperties = utils.DeepCopy(properties)
}
return TrackEventID3(sa, identity, PROFILE_APPEND, "", nproperties)
}
func (sa *SensorsAnalytics) ProfileUnsetById(identity Identity, properties map[string]interface{}) error {
var nproperties map[string]interface{}
if properties == nil {
return errors.New("property should not be nil")
} else {
nproperties = utils.DeepCopy(properties)
}
return TrackEventID3(sa, identity, PROFILE_UNSET, "", nproperties)
}
func (sa *SensorsAnalytics) ProfileDeleteById(identity Identity) error {
nproperties := make(map[string]interface{})
return TrackEventID3(sa, identity, PROFILE_DELETE, "", nproperties)
}