Amplitude unofficial client for Go, inspired in their official SDK for Node

Amplitude Golang SDK

Go Reference GitHub release (latest by date) GitHub go.mod Go version

Amplitude unofficial client for Go, inspired in their official SDK for Node.

For reference, visit HTTP API v2 documentation.

Installation

$ go get github.com/renatoaf/amplitude-go

Usage

// startup
client := amplitude.NewDefaultClient("<your-api-key")
client.Start()

// logging events
client.LogEvent(&data.Event{
    UserID: "[email protected]",
    EventType: "test-event",
    EventProperties: map[string]interface{}{
        "source": "notification",
    },
    UserProperties: map[string]interface{}{
        "age": 25,
        "gender": "female",
    },
})

// gracefully shutdown, waiting pending events to be sent
client.Shutdown()

The Event (doc) structure is based on API V2 request properties.

Events will not be sent synchronously, the client keeps a goroutine responsible for batching and issuing uploads of events. This routine will upload events:

  • after the upload interval (every 10ms by default).
  • as soon as we accumulate enough events to batch (256 events by default).
  • when Flush is explicitly invoked.
  • during shutdown process.

LogEvent calls, therefore, should never block. It will return an error in case the event was not queued (which means the event will be dropped without even being sent). This should not happen unless the uploads are not getting through for some reason (e.g. a misconfiguration).

Check advanced parameters to learn how to tweak the default behaviour.

Advanced parameters

The default client behaviour can be configured through a set of custom Options (doc).

client := amplitude.NewClient("<your-api-key", amplitude.Options{ ... })

Examples

  1. If you want to configure your client to issue uploads every second:
client := amplitude.NewClient("<your-api-key", amplitude.Options{
    UploadInterval: time.Second,
})
  1. If you want to disable retries:
client := amplitude.NewClient("<your-api-key", amplitude.Options{
    MaxUploadAttempts: 1,
})
  1. If you want to hook your own Datadog metrics for amplitude events:
client := amplitude.NewClient("<your-api-key", amplitude.Options{
    UploadDelegate: func(_ *amplitude.Uploader, events []*data.Event, err error) {
        count := len(events)
        if err != nil {
            statsd.Incr("amplitude.events", []string{"status:failure"}, count)
        } else {
            statsd.Incr("amplitude.events", []string{"status:success"}, count)
        }
    },
})
  1. If you want to allow more upload batches in parallel and a larger queue, in case you anticipate a higher throughput of events:
client := amplitude.NewClient("<your-api-key", amplitude.Options{
    MaxParallelUploads: 16, 
    MaxCachedEvents: 32000,
})
Similar Resources

Go client for the YNAB API. Unofficial. It covers 100% of the resources made available by the YNAB API.

YNAB API Go Library This is an UNOFFICIAL Go client for the YNAB API. It covers 100% of the resources made available by the YNAB API. Installation go

Oct 6, 2022

Avanza Unofficial GO API Client

Avanza Unofficial GO API Client Please note that I am not affiliated with Avanza Bank AB in any way. The underlying API can be taken down or changed w

Jan 7, 2023

(unofficial) TexTra API client library

go-textra This is a library that translates with みんなの自動翻訳(minnano-jidou-honyaku)@textra's API. You need a textra account. package main import ( "fmt

Dec 13, 2021

A go sdk for baidu netdisk open platform 百度网盘开放平台 Go SDK

Pan Go Sdk 该代码库为百度网盘开放平台Go语言的SDK

Nov 22, 2022

Nextengine-sdk-go: the NextEngine SDK for the Go programming language

NextEngine SDK for Go nextengine-sdk-go is the NextEngine SDK for the Go programming language. Getting Started Install go get github.com/takaaki-s/nex

Dec 7, 2021

Commercetools-go-sdk is fork of original commercetools-go-sdk

commercetools-go-sdk The Commercetools Go SDK is automatically generated based on the official API specifications of Commercetools. It should therefor

Dec 13, 2021

Sdk-go - Go version of the Synapse SDK

synapsesdk-go Synapse Protocol's Go SDK. Currently in super duper alpha, do not

Jan 7, 2022

Redash-go-sdk - An SDK for the programmatic management of Redash, in Go

Redash-go-sdk - An SDK for the programmatic management of Redash, in Go

Redash Go SDK An SDK for the programmatic management of Redash. The main compone

Dec 13, 2022

Go client for official Notion API.

notion notion is a Go client for the Notion API. Features The client supports all (non-deprecated) endpoints available in the Notion API, as of May 15

Dec 5, 2021
Nov 28, 2022
Twilight is an unofficial Golang SDK for Twilio APIs
Twilight is an unofficial Golang SDK for Twilio APIs

Twilight is an unofficial Golang SDK for Twilio APIs. Twilight was born as a result of my inability to spell Twilio correctly. I searched for a Twillio Golang client library and couldn’t find any, I decided to build one. Halfway through building this, I realized I had spelled Twilio as Twillio when searching for a client library on Github.

Jul 2, 2021
An easy-to-use unofficial SDK for Feishu and Lark Open Platform

go-lark go-lark is an easy-to-use unofficial SDK for Feishu and Lark Open Platform. go-lark implements messaging APIs, with full-fledged supports on b

Jan 2, 2023
Unofficial Fiber Handler for Sentry SDK

Fiber Handler for Sentry SDK Welcome to another "I can't find one, so I made one" episode of mine. Installation $ go get github.com/aldy505/sentry-fib

Oct 11, 2022
Unofficial Go SDK for GoPay Payments REST API

Unofficial Go SDK for GoPay Payments REST API Installation go get https://github.com/apparently-studio/gopay-go-api Basic usage client := gopay.NewCl

Nov 18, 2022
unofficial NBA Stats API SDK in Go

nba api go (nag) is an unofficial NBA Stats API in Go. it is very much a Go port of nba_api. endpoints alltimeleadersgrids assistleaders assisttracker

Sep 23, 2022
Unofficial getpocket.com API Golang SDK

GetPocket API Golang SDK https://getpocket.com/developer/ Example usage: package main import ( "context" "fmt" pocket "github.com/ernur-eskermes/p

Nov 28, 2021
Unofficial SDK to access for Open Threat Exchange (OTX) in Go

gotx Unofficial SDK to access for Open Threat Exchange (OTX) API in Go. Usage package main import ( "context" "fmt" "os" "github.com/m-mizutani/

Feb 12, 2022
Golang SDK for Dusupay payment gateway API (Unofficial)

Dusupay API SDK GO (Unofficial) Description Unofficial Dusupay payment gateway API Client for Go API documentation https://docs.dusupay.com/ Installat

Sep 27, 2022
Unofficial Golang SDK for TON (The Open Network)

TonWeb Unofficial Golang SDK for TON (The Open Network) Installation go get github.com/neotoolkit/tonweb Usage package main import ( "fmt" "os" "

Jun 13, 2022