-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathtracking.go
42 lines (38 loc) · 1.11 KB
/
tracking.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
package ffclient
import (
"time"
"github.com/thomaspoignant/go-feature-flag/exporter"
"github.com/thomaspoignant/go-feature-flag/ffcontext"
)
// Track is used to track an event.
// Note: Use this function only if you are using multiple go-feature-flag instances.
func (g *GoFeatureFlag) Track(
trackingEventName string,
ctx ffcontext.EvaluationContext,
trackingEventDetails exporter.TrackingEventDetails,
) {
if g != nil && g.trackingEventDataExporter != nil {
contextKind := "user"
if ctx.IsAnonymous() {
contextKind = "anonymousUser"
}
event := exporter.TrackingEvent{
Kind: "tracking",
ContextKind: contextKind,
UserKey: ctx.GetKey(),
CreationDate: time.Now().Unix(),
Key: trackingEventName,
EvaluationContext: ctx.ToMap(),
TrackingDetails: trackingEventDetails,
}
g.trackingEventDataExporter.AddEvent(event)
}
}
// Track is used to track an event.
func Track(
trackingEventName string,
ctx ffcontext.EvaluationContext,
trackingEventDetails exporter.TrackingEventDetails,
) {
ff.Track(trackingEventName, ctx, trackingEventDetails)
}