-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathidentify.go
More file actions
76 lines (62 loc) · 1.69 KB
/
identify.go
File metadata and controls
76 lines (62 loc) · 1.69 KB
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
package posthog
import (
"time"
)
var _ Message = (*Identify)(nil)
// This type represents object sent in an identify call
type Identify struct {
// This field is exported for serialization purposes and shouldn't be set by
// the application, its value is always overwritten by the library.
Type string
// Uuid is optional. If not provided, a random UUID will be generated.
Uuid string
DistinctId string
Timestamp time.Time
Properties Properties
DisableGeoIP bool
}
func (msg Identify) internal() {
panic(unimplementedError)
}
func (msg Identify) Validate() error {
if len(msg.DistinctId) == 0 {
return FieldError{
Type: "posthog.Identify",
Name: "DistinctId",
Value: msg.DistinctId,
}
}
return nil
}
type IdentifyInApi struct {
Type string `json:"type"`
Uuid string `json:"uuid"`
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"`
Set Properties `json:"$set"`
}
func (msg Identify) APIfy() APIMessage {
myProperties := Properties{}.
Set("$lib", SDKName).
Set("$lib_version", getVersion()).
Merge(getSystemContext().ToProperties())
if msg.DisableGeoIP {
myProperties.Set(propertyGeoipDisable, true)
}
apified := IdentifyInApi{
Type: msg.Type,
Uuid: msg.Uuid,
Event: "$identify",
Library: SDKName,
LibraryVersion: getVersion(),
Timestamp: msg.Timestamp,
DistinctId: msg.DistinctId,
Properties: myProperties,
Set: msg.Properties,
}
return apified
}