Mixpanel Go Client
go get github.com/stryd/mixpanel-go
import (
"github.com/stryd/mixpanel-go"
)
mixpanelAPI := mixpanel.New(mixpanel.WithToken("api-token"))
There are multiple options that can be provided in any order. If multiple are provided the last one will take effect.
// must be https
mixpanel.WithApiUrl("https://new-api.mixpanel.com")
// required for track calls
mixpanel.WithToken("api_token")
// required for import calls
mixpanel.WithServiceAccount("service_account_username", "service_account_secret")
mixpanel.WithProjectID("1234")
This is usually used client-side but can be used from servers as well. The event must have occurred with in the last 5 days if a time is provided.
Token is required.
event := mixpanel.Event{
DistinctID: "1234", // required
Name: "your-event", // required
Properties: map[string]interface{}{
"run_id": "123456789",
}
}
if err := mixpanelClient.Track(event); err != nil {
log.Fatal(err)
}
Should only be used server side. Can track up to 2000 events as long as those 2000 events don't exceed the size limit of a single import request (2MB uncompressed). Insert IDs will be calculated if not provided for each event.
Service account credentials are required.
now := time.Now()
events := []mixpanel.Event{{
DistinctID: "1234", // required
Name: "run-completed", // required
Time: &now, // required
Properties: map[string]interface{}{
"run_id": "123456789",
}
},{
DistinctID: "1234", // required
Name: "run-deleted", // required
Time: &now, // required
Properties: map[string]interface{}{
"run_id": "123456789",
}
}}
if err := mixpanelClient.Import(events); err != nil {
log.Fatal(err)
}