Skip to content

Commit 3804acf

Browse files
authored
Merge branch 'PostHog:master' into master
2 parents 51a7f5c + e4ff93a commit 3804acf

14 files changed

+51
-61
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.20
2+
3+
* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.19...v1.2.20)
4+
15
## 1.2.19
26

37
* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.18...v1.2.19)

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ func main() {
6262
Properties: posthog.NewProperties().
6363
Set("$current_url", "https://example.com"),
6464
})
65-
66-
// Capture event with calculated uuid to deduplicate repeated events.
67-
// The library github.com/google/uuid is used
68-
key := myEvent.Id + myEvent.Project
69-
uid := uuid.NewSHA1(uuid.NameSpaceX500, []byte(key)).String()
70-
client.Enqueue(posthog.Capture{
71-
Uuid: uid,
72-
DistinctId: "test-user",
73-
Event: "$pageview",
74-
Properties: posthog.NewProperties().
75-
Set("$current_url", "https://example.com"),
76-
})
7765

7866
// Check if a feature flag is enabled
7967
isMyFlagEnabled, err := client.IsFeatureEnabled(

capture.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ type Capture struct {
99
// This field is exported for serialization purposes and shouldn't be set by
1010
// the application, its value is always overwritten by the library.
1111
Type string
12-
// You don't usually need to specify this field - Posthog will generate it automatically.
13-
// Use it only when necessary - for example, to prevent duplicate events.
14-
Uuid string
12+
1513
DistinctId string
1614
Event string
1715
Timestamp time.Time
@@ -46,7 +44,6 @@ func (msg Capture) Validate() error {
4644

4745
type CaptureInApi struct {
4846
Type string `json:"type"`
49-
Uuid string `json:"uuid"`
5047
Library string `json:"library"`
5148
LibraryVersion string `json:"library_version"`
5249
Timestamp time.Time `json:"timestamp"`
@@ -75,7 +72,6 @@ func (msg Capture) APIfy() APIMessage {
7572

7673
apified := CaptureInApi{
7774
Type: msg.Type,
78-
Uuid: msg.Uuid,
7975
Library: library,
8076
LibraryVersion: libraryVersion,
8177
Timestamp: msg.Timestamp,

config.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package posthog
33
import (
44
"net/http"
55
"time"
6+
7+
"github.com/google/uuid"
68
)
79

810
// Instances of this type carry the different configuration options that may
@@ -77,6 +79,12 @@ type Config struct {
7779
// If not set the client will fallback to use a default retry policy.
7880
RetryAfter func(int) time.Duration
7981

82+
// A function called by the client to generate unique message identifiers.
83+
// The client uses a UUID generator if none is provided.
84+
// This field is not exported and only exposed internally to let unit tests
85+
// mock the id generation.
86+
uid func() string
87+
8088
// A function called by the client to get the current time, `time.Now` is
8189
// used by default.
8290
// This field is not exported and only exposed internally to let unit tests
@@ -165,6 +173,10 @@ func makeConfig(c Config) Config {
165173
c.RetryAfter = DefaultBacko().Duration
166174
}
167175

176+
if c.uid == nil {
177+
c.uid = uid
178+
}
179+
168180
if c.now == nil {
169181
c.now = time.Now
170182
}
@@ -175,3 +187,10 @@ func makeConfig(c Config) Config {
175187

176188
return c
177189
}
190+
191+
// This function returns a string representation of a UUID, it's the default
192+
// function used for generating unique IDs.
193+
func uid() string {
194+
new_uuid, _ := uuid.NewRandom()
195+
return new_uuid.String()
196+
}

fixtures/test-enqueue-capture-with-uuid.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

fixtures/test-enqueue-capture.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
},
1616
"send_feature_flags": false,
1717
"timestamp": "2009-11-10T23:00:00Z",
18-
"type": "capture",
19-
"uuid": ""
18+
"type": "capture"
2019
}
2120
]
2221
}

fixtures/test-interval-capture.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
},
1616
"send_feature_flags": false,
1717
"timestamp": "2009-11-10T23:00:00Z",
18-
"type": "capture",
19-
"uuid": ""
18+
"type": "capture"
2019
}
2120
]
2221
}

fixtures/test-many-capture.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
},
1515
"send_feature_flags": false,
1616
"timestamp": "2009-11-10T23:00:00Z",
17-
"type": "capture",
18-
"uuid": ""
17+
"type": "capture"
1918
},
2019
{
2120
"distinct_id": "123456",
@@ -30,8 +29,7 @@
3029
},
3130
"send_feature_flags": false,
3231
"timestamp": "2009-11-10T23:00:00Z",
33-
"type": "capture",
34-
"uuid": ""
32+
"type": "capture"
3533
},
3634
{
3735
"distinct_id": "123456",
@@ -46,8 +44,7 @@
4644
},
4745
"send_feature_flags": false,
4846
"timestamp": "2009-11-10T23:00:00Z",
49-
"type": "capture",
50-
"uuid": ""
47+
"type": "capture"
5148
}
5249
]
5350
}

fixtures/test-merge-capture.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
},
1717
"send_feature_flags": false,
1818
"timestamp": "2015-07-10T23:00:00Z",
19-
"type": "capture",
20-
"uuid": ""
19+
"type": "capture"
2120
}
2221
]
2322
}

fixtures/test-timestamp-capture.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
},
1616
"send_feature_flags": false,
1717
"timestamp": "2015-07-10T23:00:00Z",
18-
"type": "capture",
19-
"uuid": ""
18+
"type": "capture"
2019
}
2120
]
2221
}

0 commit comments

Comments
 (0)