-
Notifications
You must be signed in to change notification settings - Fork 20
/
group_identify.go
69 lines (55 loc) · 1.38 KB
/
group_identify.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
package posthog
import (
"fmt"
"time"
)
type GroupIdentify struct {
Type string
Key string
DistinctId string
Timestamp time.Time
Properties Properties
}
func (msg GroupIdentify) internal() {
panic(unimplementedError)
}
func (msg GroupIdentify) Validate() error {
if len(msg.Type) == 0 {
return FieldError{
Type: "posthog.GroupIdentify",
Name: "Type",
Value: msg.Type,
}
}
if len(msg.Key) == 0 {
return FieldError{
Type: "posthog.GroupIdentify",
Name: "Key",
Value: msg.Key,
}
}
return nil
}
type GroupIdentifyInApi struct {
Library string `json:"library"`
LibraryVersion string `json:"library_version"`
Timestamp time.Time `json:"timestamp"`
Event string `json:"event"`
DistinctId string `json:"distinct_id"`
Properties Properties `json:"properties"`
}
func (msg GroupIdentify) APIfy() APIMessage {
library := "posthog-go"
myProperties := Properties{}.Set("$lib", library).Set("$lib_version", getVersion())
myProperties.Set("$group_type", msg.Type).Set("$group_key", msg.Key).Set("$group_set", msg.Properties)
distinctId := fmt.Sprintf("$%s_%s", msg.Type, msg.Key)
apified := GroupIdentifyInApi{
Event: "$groupidentify",
Properties: myProperties,
DistinctId: distinctId,
Timestamp: msg.Timestamp,
Library: library,
LibraryVersion: getVersion(),
}
return apified
}