Go SDK

Install and integrate the ABMeter Go SDK

Installation

Add the github.com/abmeter/abmeter-go module to your project:

go get github.com/abmeter/abmeter-go

Go 1.24 or newer is required. The SDK has zero dependencies outside the Go standard library.

Configuration

Configure the SDK once at application startup, and drain the background queue on shutdown:

import (
    "context"
    "log"
    "os"

    abmeter "github.com/abmeter/abmeter-go"
)

func main() {
    if err := abmeter.Configure(abmeter.Config{
        APIKey: os.Getenv("ABMETER_API_KEY"),
    }); err != nil {
        log.Fatal(err)
    }
    defer abmeter.Reset(context.Background()) // flush queued exposures/events
    // ...
}

The APIKey is required. You can find or create API keys on the API Keys page (available after signing in).

Core Concepts

Parameters represent feature variations - a parameter has a set of possible values assigned to users through experiments or feature flags. Use ResolveParameter to get the value for a specific user.

Events are user actions you want to measure - page views, purchases, clicks. Track them with TrackEvent to analyze how parameter variations affect user behavior.

Users are identified by a UserID - the randomization unit the SDK hashes to assign parameter values randomly across your users but consistently for each one, so the same UserID always sees the same variation (no stored state, no network call). A "user" is your end-user - a customer, visitor, or account - and UserID can be any string you choose (a customer id, visitor id, account id). An optional Email may be provided; ABMeter uses it only for audience rules that target email patterns (e.g. @acme.com), never for identity or bucketing.

Resolve a Parameter

Create a user and resolve a parameter to get the assigned value:

user := abmeter.User{UserID: "user-123"}

value, err := abmeter.ResolveParameter(user, "checkout-button-color")
if err != nil {
    value = "green" // your own fallback; the SDK never panics
}
// value => "blue" (the assigned variant's value for this parameter)

The return value is the parameter value from the variant assigned to this user, or the parameter's default value when no experiment or feature flag controls it for them. Errors are returned as values (Go idiom) - handle them with a fallback of your own rather than aborting the request.

Email is optional and safe to omit - do so for anonymous or server-side users, such as front-end visitors keyed by a cookie id. Leaving it out raises no error: a user with no email simply never matches an audience that targets email patterns, so email-predicate feature flags and experiments don't apply to them. Every other path (random experiments, user-list audiences, event tracking) uses UserID alone. Pass an email only when you use email-pattern audiences: abmeter.User{UserID: "user-123", Email: "[email protected]"}.

Track an Event

Record user actions to measure the impact of your experiments:

abmeter.TrackEvent("purchase", user.UserID, map[string]any{
    "price":    49.99,
    "currency": "USD",
})

Events are queued and submitted asynchronously in batches, so tracking calls are fast and non-blocking. The third argument is a data map with any properties relevant to your metrics.

Full Example

A realistic net/http handler showing parameter resolution and event tracking together:

func (s *Server) handleCheckout(w http.ResponseWriter, r *http.Request) {
    user := abmeter.User{
        UserID: s.currentUserID(r),
        Email:  s.currentUserEmail(r), // optional, only for email-predicate audiences
    }

    buttonColor, err := abmeter.ResolveParameter(user, "checkout-button-color")
    if err != nil {
        buttonColor = "green" // fallback if no experiment is running
    }

    s.render(w, "checkout", map[string]any{"buttonColor": buttonColor})
}

func (s *Server) handlePurchase(w http.ResponseWriter, r *http.Request) {
    order := s.createOrder(r)

    abmeter.TrackEvent("purchase", s.currentUserID(r), map[string]any{
        "price":    order.Total,
        "currency": order.Currency,
    })

    http.Redirect(w, r, "/orders/"+order.ID, http.StatusSeeOther)
}

Next Steps