-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathintegration.go
121 lines (93 loc) · 3.42 KB
/
integration.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
114
115
116
117
118
119
120
121
package integrations
// Integration defines what an integration is made of.
// Each integrations is responsible to register it self to the registry (see
// RegisterIntegration for details).
type Integration interface {
// Identify is responsible of forwarding the identify call to the integration
Identify(identification Identification) error
// Track forwards the event to the integration
Track(event Event) error
// Page forwards the page-view to the integration
Page(page Page) error
// Enabled returns wether or not the integration is enabled/configured
Enabled() bool
}
// Identification defines the structure of the data we receive from the API
type Identification struct {
// Unique user ID. Should not change, ever.
UserID string `json:"userID"`
// Set of custom traits sent to the integrations. Some might be required, on
// a per integration basis.
UserTraits map[string]interface{} `json:"userTraits"`
// Timestamp of when the identifiaction originally triggered
Timestamp int64 `json:"timestamp"`
// Timestamp of when Forwardlytics received the identifiaction.
ReceivedAt int64 `json:"receivedAt"`
}
// Validate the content of the identifiaction to be sure it has everything that's needed
func (i Identification) Validate() (missingParameters []string) {
if i.UserID == "" {
missingParameters = append(missingParameters, "userID")
}
if i.Timestamp == 0 {
missingParameters = append(missingParameters, "timestamp")
}
return
}
// Event defines the structure for the incoming event data from the API
type Event struct {
// Name is the name of the event
Name string `json:"name"`
// Unique user ID. Should not change, ever.
UserID string `json:"userID"`
// Properties are custom variables you can send with the event
Properties map[string]interface{} `json:"properties"`
// Timestamp of when the identifiaction originally triggered
Timestamp int64 `json:"timestamp"`
// ReceivedAt of when Forwardlytics received the identifiaction.
ReceivedAt int64 `json:"receivedAt"`
}
// Validate the content of the event to be sure it has everything that's needed
func (e Event) Validate() (missingParameters []string) {
if e.Name == "" {
missingParameters = append(missingParameters, "name")
}
if e.UserID == "" {
missingParameters = append(missingParameters, "userID")
}
if e.Timestamp == 0 {
missingParameters = append(missingParameters, "timestamp")
}
return
}
// Page defines the structure for the incoming page-view data
type Page struct {
// Name is the name of the page
Name string `json:"name"`
// Unique user ID. Should not change, ever.
UserID string `json:"userID"`
// Unique user ID. Should not change, ever.
Url string `json:"url"`
// Properties are custom variables you can send with the page
Properties map[string]interface{} `json:"properties"`
// Timestamp of when the page-call originally triggered
Timestamp int64 `json:"timestamp"`
// ReceivedAt of when Forwardlytics received the page-call.
ReceivedAt int64 `json:"receivedAt"`
}
// Validate the content of the page to be sure it has everything that's needed
func (p Page) Validate() (missingParameters []string) {
if p.Name == "" {
missingParameters = append(missingParameters, "name")
}
if p.Url == "" {
missingParameters = append(missingParameters, "url")
}
if p.UserID == "" {
missingParameters = append(missingParameters, "userID")
}
if p.Timestamp == 0 {
missingParameters = append(missingParameters, "timestamp")
}
return
}