Documentation ¶
Overview ¶
Amplitude unofficial client for Go, inspired in their official SDK for Node.
Usage:
func main() { const ApiKey = "<your-api-key>" client := amplitude.NewDefaultClient(ApiKey) client.Start() err := client.LogEvent(&data.Event{ UserID: "datamonster@gmail.com", EventType: "test-event", EventProperties: map[string]interface{}{ "source": "notification", }, UserProperties: map[string]interface{}{ "age": 25, "gender": "female", }, }) if err != nil { log.Printf("failed to queue event: %v", err) } client.Shutdown() }
Index ¶
Constants ¶
View Source
const ( DefaultServerUrl = "https://api2.amplitude.com/2/httpapi" // 256 events batch size for individual uploads DefaultBatchSize = 256 // Based on nodejs client (but not estimated for this SDK): 2kb is a safe estimate for a medium size event object. This keeps the SDK's memory footprint roughly under 32 MB. DefaultMaxCachedEvents = 16000 // 12 goroutines to execute parallel uploads. DefaultMaxParallelUploads = 12 // 5 retries with backoff. DefaultMaxUploadAttempts = 6 // 10 ms pace of upload DefaultUploadInterval = 10 * time.Millisecond // Default of 10s was took from NodeJS sdk DefaultRequestTimeout = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps Amplitude V2 api client.
func NewDefaultClient ¶
NewDefaultClient creates a client with default options.
func (*Client) Identify ¶ added in v0.0.2
Identify enqueues an identify event to be uploaded in background.
type ClientState ¶
type ClientState uint32
ClientState defines the client FSM.
const ( Idle ClientState = iota Running Closing Closed )
type Options ¶
type Options struct { // Base context Context context.Context // BatchSize is the amount of events sent in a single upload batch; defaults to DefaultBatchSize. BatchSize int // MaxCachedEvents is the limit of events we can queue before start dropping logged events; defaults to DefaultMaxCachedEvents. MaxCachedEvents int // MaxParallelUploads is the number of goroutines we spawn to handle uploads in batch; defaults to DefaultMaxParallelUploads. MaxParallelUploads int // MaxUploadAttempts is the number of upload attempts we execute before dropping a batch (MaxUploadAttempts - 1 retries); defaults to DefaultMaxUploadAttempts. MaxUploadAttempts int // OptOut should be set to true if you want a dry-run experience; defaults to false. OptOut bool // Transport allows you to configure your own transport layer; defaults to transport.HttpTransport. Transport transport.Transport // ServerUrl allows you to configure your own API server url; defaults to DefaultServerUrl. ServerUrl string // RequestTimeout is the timeout for each individual upload attempt; defaults to DefaultRequestTimeout. RequestTimeout time.Duration // UploadInterval is the interval between individual uploads; defaults to DefaultUploadInterval. UploadInterval time.Duration // UploadDelegate allows you to hook your own code when an upload happens (for example to send metrics); defaults to nil. UploadDelegate UploadBatchDelegate // defaults to nil }
Options defines API Client optional parameters.
func (*Options) BaseContext ¶ added in v0.0.3
type UploadBatchDelegate ¶
UploadBatchDelegate function executes when an upload batch happens (succeeded or not).
type UploadCallback ¶
type UploadCallback func(*Uploader)
UploadCallback function executes deferred code during the upload.
Click to show internal directories.
Click to hide internal directories.