AdvaitaADVAITA DOCS
GitHubGet started
Server SDKv1.xApache 2.0

Go SDK

github.com/acai/analytics-go is the Go server SDK with a plugin architecture, an Identify builder, and configurable retry and storage.

Installation

Shell
go get github.com/acai/analytics-go

Initialise

Go
import (
acai "github.com/acai/analytics-go"
"time"
)
config := acai.NewConfig("YOUR_API_KEY")
config.ServerURL = "https://events.yourdomain.com/2/httpapi"
config.FlushQueueSize = 200
config.FlushInterval = 10 * time.Second
client := acai.NewClient(config)
defer client.Shutdown()

Track events

Go
client.Track(acai.Event{
EventType: "Purchase Completed",
UserID: "user_abc123",
EventProperties: acai.NewEventProperties().
Set("product_id", "prod_123").
Set("price", 49.99).
Set("currency", "USD"),
})
client.Flush()

Identify users

Go
identify := acai.NewIdentify().
Set("plan", "enterprise").
SetOnce("first_seen", "2024-01-15").
Add("api_calls", 1).
Append("roles", "admin").
Unset("trial_active")
client.Identify(identify, acai.EventOptions{UserID: "user_abc123"})
// Group assignment
client.SetGroup("company", []string{"Acme Corp"}, acai.EventOptions{
UserID: "user_abc123",
})
// Set properties on the group itself
groupIdentify := acai.NewIdentify().Set("tier", "enterprise")
client.GroupIdentify("company", "Acme Corp", groupIdentify, acai.EventOptions{})

Plugins

Go
type ServerContextPlugin struct{}
func (p *ServerContextPlugin) Name() string { return "server-context" }
func (p *ServerContextPlugin) Type() acai.PluginType { return acai.PluginTypeEnrichment }
func (p *ServerContextPlugin) Setup(config acai.Config) {}
func (p *ServerContextPlugin) Execute(event *acai.Event) *acai.Event {
if event.EventProperties == nil {
event.EventProperties = map[string]interface{}{}
}
event.EventProperties["region"] = os.Getenv("AWS_REGION")
return event
}
client.Add(&ServerContextPlugin{})

Config reference

FieldTypeDefaultDescription
APIKeystringrequiredYour project API key.
ServerURLstringUS endpointCollector endpoint.
UseBatchboolfalseUse the /batch endpoint.
FlushIntervaltime.Duration10sPeriodic flush interval.
FlushQueueSizeint200Max events per batch.
FlushMaxRetriesint12Max retry attempts.
ConnectionTimeouttime.Duration10sHTTP connection timeout.
OptOutboolfalseDisable all event sending.
ExecuteCallbackfunc(ExecuteResult)nilCalled after each event is processed.