---
title: Get started with the Go SDK
description: "Install the Amplitude Go SDK, create a client, send a first event from a Go server, and fix the problems that stop server-side events from arriving."
product: analytics
lang: en
last_updated: 2026-12-01
token_estimate: 2266
---
# Get started with the Go SDK

- **Package:** `github.com/amplitude/analytics-go` ([gomod](https://pkg.go.dev/github.com/amplitude/analytics-go))
- **Latest version:** v1.3.1

Install the Go SDK, create a client, and send one event from your Go program to Amplitude. The SDK is the Go module `github.com/amplitude/analytics-go`, and its package name is `amplitude`. Each step lists the conditions that commonly break that step, so you can fix a problem where it happens. For the full option list, go to [Configuration options](https://amplitude.com/docs/sdks/analytics/go/go-sdk/reference#configuration-options). For changes between versions, go to the [Go SDK releases on GitHub](https://github.com/amplitude/analytics-go/releases).

> For AI agents: a documentation index is available at [/docs/llms.txt](/docs/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

The Go SDK is for server-side code that sends events on behalf of many users. It doesn't store a user ID, device ID, or session between calls, so you pass the user's identity with each event.

## Prerequisites

- An Amplitude project and its API key. Find the key in _Settings > Projects > your project > General_.
- The data center your organization uses: US (default) or EU.
- The latest Go SDK release. If you pin an older version, check the [Go SDK releases](https://github.com/amplitude/analytics-go/releases) to confirm that it includes the features you use.
- Go 1.17 or later, with Go modules. The examples on these pages run on Go 1.27.

## Install the SDK

From the directory that holds your `go.mod`, add the module:

```bash
go get github.com/amplitude/analytics-go
```

Then import the `amplitude` package, which holds the client, the event types, and the configuration:

```go
package main

import "github.com/amplitude/analytics-go/amplitude"

func main() {
	_ = amplitude.NewConfig("AMPLITUDE_API_KEY")
}
```

### Fix installation problems

| Symptom | Cause | Fix |
| --- | --- | --- |
| `no required module provides package github.com/amplitude/analytics-go/amplitude; to add it:` | The module isn't in your `go.mod`. | Run `go get github.com/amplitude/analytics-go` in the directory that holds `go.mod`, and commit `go.mod` and `go.sum`. |
| `undefined: amplitude.IdentityOpSet`, or another `amplitude.IdentityOp...` constant | The identity operation constants live in the `types` subpackage. The `amplitude` package re-exports the `IdentityOp` type but not its constants. | Use the [`Identify` methods](https://amplitude.com/docs/sdks/analytics/go/go-sdk/reference#identify-struct) such as `Set()`, or import `github.com/amplitude/analytics-go/amplitude/types` and use `types.IdentityOpSet`. |

## Initialize the SDK

Create a `Config` with your API key, change any options on it, then pass it to `NewClient()`. Create one client when your process starts and share it across requests and goroutines. Defer `Shutdown()` so the client sends queued events before the program exits.

```go
package main

import "github.com/amplitude/analytics-go/amplitude"

func main() {
	config := amplitude.NewConfig("AMPLITUDE_API_KEY")
	client := amplitude.NewClient(config)
	defer client.Shutdown()
}
```

`NewClient()` copies the `Config`. Changes you make to `config` after the call don't affect the client.

If your project uses the EU data center, set `config.ServerZone = amplitude.ServerZoneEU` before you call `NewClient()`. For other options, go to [Configuration options](https://amplitude.com/docs/sdks/analytics/go/go-sdk/reference#configuration-options).

### Fix initialization problems

| Symptom | Cause | Fix |
| --- | --- | --- |
| Uploads fail with `Invalid API key` | The key is empty or wrong, or belongs to a project in the other data center. `NewClient()` doesn't check the key, so the error appears only when the SDK uploads events. | Check the environment variable that holds your key, and set `ServerZone` to match the project's data center. |
| The SDK uploads far more often than expected, or the log fills with requests | `FlushInterval` is a `time.Duration`. A bare number such as `5000` means 5000 nanoseconds. | Write durations with units: `config.FlushInterval = 5 * time.Second`. |
| Options you set have no effect | You changed `config` after `NewClient()`. | Set every option before `NewClient()`. To check what the client uses, call [`client.Config()`](https://amplitude.com/docs/sdks/analytics/go/go-sdk/reference#config). |

## Send a first event

Track one event for a user. Set `UserID` (or `DeviceID`) on every event, because the SDK doesn't remember identity between calls. `Track()` queues the event and returns immediately. The deferred `Shutdown()` sends the event before `main` returns.

```go
package main

import "github.com/amplitude/analytics-go/amplitude"

func main() {
	config := amplitude.NewConfig("AMPLITUDE_API_KEY")
	client := amplitude.NewClient(config)
	defer client.Shutdown()

	client.Track(amplitude.Event{
		EventType:       "Sign Up Completed",
		UserID:          "user-12345",
		EventProperties: map[string]interface{}{"plan": "starter"},
	})
}
```

The SDK sends this event to Amplitude:

```json
{
  "event_type": "Sign Up Completed",
  "user_id": "user-12345",
  "event_properties": { "plan": "starter" },
  "time": 1794431065800,
  "insert_id": "d99fc12f-77d3-40c5-9bb6-6a082fdd0a80",
  "library": "amplitude-go/1.3.1"
}
```

In a long-running server, the SDK uploads queued events every 10 seconds, or as soon as 200 events are waiting. Go to [How the SDK uploads events](https://amplitude.com/docs/sdks/analytics/go/go-sdk/instrument-and-configure#how-the-sdk-uploads-events).

### Fix upload problems

The default logger writes every upload result to standard error, with the prefix `amplitude-analytics - `. To get the result in code, set an [`ExecuteCallback`](https://amplitude.com/docs/sdks/analytics/go/go-sdk/verify-events#read-the-upload-result).

| Log line on standard error | Cause | Fix |
| --- | --- | --- |
| No upload lines at all, and the program exits | The program exited before the next upload, without calling `Shutdown()` or `Flush()`. The SDK holds events only in memory. | Call `defer client.Shutdown()` immediately after `NewClient()`. Go to [Flush before the process exits](https://amplitude.com/docs/sdks/analytics/go/go-sdk/instrument-and-configure#flush-before-the-process-exits). |
| `Error: Invalid event, EventType and either UserID or DeviceID cannot be empty` | The event has no `EventType`, or neither `UserID` nor `DeviceID`. The SDK sends the event anyway, and Amplitude rejects it. | Set `EventType` and `UserID` or `DeviceID` on every event. |
| `Error: Invalid API key: code=400, ...` | The key is wrong, or belongs to a project in the other data center. The SDK drops every event in the request. | Copy the key again and check `ServerZone`. |
| `Error: Invalid id length for user_id or device_id: code=400, ...` | An ID is shorter than five characters, Amplitude's default minimum. | Use longer IDs, or set [`MinIDLength`](https://amplitude.com/docs/sdks/analytics/go/go-sdk/instrument-and-configure#allow-shorter-ids). |
| `Error: HTTP request failed: Post "https://api2.amplitude.com/2/httpapi": ... code=0, ...` | The request never reached a server: DNS failure, a firewall, or no outbound network. The SDK drops these events without retrying. | Confirm that the host can reach `api2.amplitude.com` (or `api.eu.amplitude.com`) on port 443. If outbound traffic must go through a proxy, set [`ServerURL`](https://amplitude.com/docs/sdks/analytics/go/go-sdk/instrument-and-configure#send-events-through-a-proxy). |
| `Error: Event reached max retry times 12: code=500, ...` | Amplitude returned server errors or timed out on every attempt. | Check the `Info: HTTP response code` lines before it for the status of each attempt. |

## Confirm the event in Amplitude

1. In Amplitude, open **User Lookup** and search for the user ID you passed, `user-12345` in the example.
2. Open the **Activity** tab and turn on **Live event updates**.
3. Confirm that `Sign Up Completed` appears with the `plan` property.

If the event doesn't appear within a minute, follow [Verify events](https://amplitude.com/docs/sdks/analytics/go/go-sdk/verify-events). That page checks each stage between `Track()` and Amplitude's servers.

## Next steps

- Add the events and properties your tracking plan needs. Go to [Track events](https://amplitude.com/docs/sdks/analytics/go/go-sdk/instrument-and-configure#track-events).
- Keep the SDK from logging your API key in production. Go to [Control logging](https://amplitude.com/docs/sdks/analytics/go/go-sdk/instrument-and-configure#control-logging).
- Flush events before a job, CLI, or serverless function exits. Go to [Flush before the process exits](https://amplitude.com/docs/sdks/analytics/go/go-sdk/instrument-and-configure#flush-before-the-process-exits).
- Tune batching, retries, and timeouts. Go to [Data delivery](https://amplitude.com/docs/sdks/analytics/go/go-sdk/instrument-and-configure#data-delivery).

