Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add historical_migration flag to config #40

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Config struct {
// will override DefaultFeatureFlagsPollingInterval.
NextFeatureFlagsPollingTick func() time.Duration

// Flag to enable historical migration
// See more in our migration docs: https://posthog.com/docs/migrate
HistoricalMigration bool

// The HTTP transport used by the client, this allows an application to
// redefine how requests are being sent at the HTTP level (for example,
// to change the connection pooling policy).
Expand Down
5 changes: 3 additions & 2 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func makeTimestamp(t time.Time, def time.Time) time.Time {
// export this type because it's only meant to be used internally to send groups
// of messages in one API call.
type batch struct {
ApiKey string `json:"api_key"`
Messages []message `json:"batch"`
ApiKey string `json:"api_key"`
HistoricalMigration bool `json:"historical_migration,omitempty"`
Messages []message `json:"batch"`
}

type APIMessage interface{}
Expand Down
5 changes: 3 additions & 2 deletions posthog.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ func (c *client) send(msgs []message) {
const attempts = 10

b, err := json.Marshal(batch{
ApiKey: c.key,
Messages: msgs,
ApiKey: c.key,
HistoricalMigration: c.HistoricalMigration,
Messages: msgs,
})

if err != nil {
Expand Down
51 changes: 51 additions & 0 deletions posthog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,57 @@ func ExampleCapture() {

}

func ExampleHistoricalMigrationCapture() {
body, server := mockServer()
defer server.Close()

client, _ := NewWithConfig("Csyjlnlun3OzyNJAafdlv", Config{
Endpoint: server.URL,
BatchSize: 1,
now: mockTime,
uid: mockId,
HistoricalMigration: true,
})
defer client.Close()

client.Enqueue(Capture{
Event: "Download",
DistinctId: "123456",
Properties: Properties{
"application": "PostHog Go",
"version": "1.0.0",
"platform": "macos", // :)
},
SendFeatureFlags: false,
})

fmt.Printf("%s\n", <-body)
// Output:
// {
// "api_key": "Csyjlnlun3OzyNJAafdlv",
// "batch": [
// {
// "distinct_id": "123456",
// "event": "Download",
// "library": "posthog-go",
// "library_version": "1.0.0",
// "properties": {
// "$lib": "posthog-go",
// "$lib_version": "1.0.0",
// "application": "PostHog Go",
// "platform": "macos",
// "version": "1.0.0"
// },
// "send_feature_flags": false,
// "timestamp": "2009-11-10T23:00:00Z",
// "type": "capture"
// }
// ],
// "historical_migration": true
// }

}

func TestEnqueue(t *testing.T) {
tests := map[string]struct {
ref string
Expand Down
Loading