-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteraction.go
188 lines (162 loc) · 4.76 KB
/
interaction.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package relay42
import (
"encoding/json"
"golang.org/x/net/context"
)
// Const for all interaction types
const (
TypeBannerView = "bannerView"
TypeTypeConversion = "typeConversion"
TypeEngagement = "engagement"
TypeExperimentMatch = "experimentMatch"
TypePageView = "pageView"
TypeSessionStart = "sessionStart"
TypeUserPreferences = "userPreferences"
TypeSync = "sync"
TypeExternalFact = "externalFact"
)
// InteractionStreamHandlerFunc defines the interaction handler type
type InteractionStreamHandlerFunc func(interaction *Interaction, cancel context.CancelFunc)
// Interaction holds the interaction general data and raw json
type Interaction struct {
General
InteractionJSON json.RawMessage
}
// UnmarshalJSON for custom json marshaling
func (i *Interaction) UnmarshalJSON(b []byte) error {
g := &General{}
err := json.Unmarshal(b, g)
i.InteractionType = g.InteractionType
i.EventID = g.EventID
i.SiteNumber = g.SiteNumber
i.Timestamp = g.Timestamp
i.TrackID = g.TrackID
i.InteractionJSON = b
return err
}
// ToBannerView returns a BannerView from an interaction
func (i *Interaction) ToBannerView() *BannerView {
e := &BannerView{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// ToConversion returns a Conversion from an interaction
func (i *Interaction) ToConversion() *Conversion {
e := &Conversion{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// ToEngagement returns an Engagement from an interaction
func (i *Interaction) ToEngagement() *Engagement {
e := &Engagement{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// ToExperimentMatch returns an ExperimentMatch from an interaction
func (i *Interaction) ToExperimentMatch() *ExperimentMatch {
e := &ExperimentMatch{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// ToPageView returns a PageView from an interaction
func (i *Interaction) ToPageView() *PageView {
e := &PageView{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// ToSessionStart returns a SessionStart from an interaction
func (i *Interaction) ToSessionStart() *SessionStart {
e := &SessionStart{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// ToUserPreferences returns a UserPreferences from an interaction
func (i *Interaction) ToUserPreferences() *UserPreferences {
e := &UserPreferences{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// ToSync returns a Sync from an interaction
func (i *Interaction) ToSync() *Sync {
e := &Sync{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// ToExternalFact returns an ExternalFact from an interaction
func (i *Interaction) ToExternalFact() *ExternalFact {
e := &ExternalFact{}
json.Unmarshal(i.InteractionJSON, e)
return e
}
// General holds interaction general data
type General struct {
InteractionType string `json:"interactionType"`
Timestamp int64 `json:"timestamp"`
TrackID string `json:"trackId"`
SiteNumber int `json:"siteNumber"`
EventID string `json:"eventId"`
}
// BannerView holds banner view data
type BannerView struct {
General
Identifier string `json:"identifier"`
SubIdentifier string `json:"subIdentifier"`
Referral string `json:"referral"`
}
// Conversion holds conversion data
type Conversion struct {
General
TransactionID string `json:"transactionId"`
Value float64 `json:"value"`
Products interface{} `json:"products"`
Variables interface{} `json:"variables"`
}
// Engagement holds engagement data
type Engagement struct {
General
Type string `json:"type"`
Content interface{} `json:"content"`
Variables interface{} `json:"variables"`
}
// ExperimentMatch holds experiment match data
type ExperimentMatch struct {
General
ExperimentGroupNumber int `json:"experimentGroupNumber"`
ExperimentNumber int `json:"experimentNumber"`
}
// PageView page view view data
type PageView struct {
General
URL string `json:"url"`
Source string `json:"source"`
UserAgent string `json:"userAgent"`
}
// SessionStart session start data
type SessionStart struct {
General
URL string `json:"url"`
Source string `json:"source"`
UserAgent string `json:"userAgent"`
}
// UserPreferences holds user preferences data
type UserPreferences struct {
General
OptOutRemarketing bool `json:"optOutRemarketing"`
OptOutAdapting bool `json:"optOutAdapting"`
}
// Sync holds sync data
type Sync struct {
General
PartnerNumber int `json:"partnerNumber"`
PartnerCookie string `json:"partnerCookie"`
MergeType string `json:"mergeType"`
}
// ExternalFact holds external fact data
type ExternalFact struct {
General
Type string `json:"type"`
Variables interface{} `json:"variables"`
TTL int `json:"ttl"`
ForceInsert bool `json:"forceInsert"`
OperationType string `json:"operationType"`
}