-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
47 lines (38 loc) · 888 Bytes
/
client.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
package analytics
import (
"strconv"
"strings"
"github.com/posthog/posthog-go"
"github.com/desmos-labs/caerus/utils"
)
var client posthog.Client
func init() {
enabledStr := utils.GetEnvOr(EnvAnalyticsEnabled, "false")
enabled, err := strconv.ParseBool(enabledStr)
if err != nil || !enabled {
return
}
apiKey := utils.GetEnvOr(EnvAnalyticsPostHogApiKey, "")
if len(strings.TrimSpace(apiKey)) == 0 {
return
}
postHogClient, err := posthog.NewWithConfig(apiKey, posthog.Config{
Endpoint: utils.GetEnvOr(EnvAnalyticsPostHogHost, "https://eu.posthog.com"),
})
if err != nil {
panic(err)
}
client = postHogClient
}
// Enqueue allows to enqueue the given event to the PostHog instance
func Enqueue(event posthog.Capture) {
if client != nil {
client.Enqueue(event)
}
}
// Stop closes the PostHog client
func Stop() {
if client != nil {
client.Close()
}
}