---
title: "Go | SDKs | Documentation - Vemetric"
description: "Track your data via the Go SDK for Vemetric."
url: https://vemetric.com/docs/sdks/go
---

# Go SDK

Track your data via the Go SDK for Vemetric.

* * *

Below you can see how to initialize and configure the SDK, as well as all the available functions.

> The Go SDK doesn’t track your page visitors and is meant as a complement to the [Frontend SDKs](https://vemetric.com/docs/sdks/overview#frontend).

## Installation

### Install the SDK

In your project directory, run:

```bash
go get github.com/vemetric/vemetric-go
```

### Initialize the Vemetric Client

We recommend creating a single instance of the Vemetric client and reusing it throughout your application.

```go
import (
  "github.com/vemetric/vemetric-go"
)

client, err := vemetric.New("YOUR_PROJECT_TOKEN")
```

> Replace `YOUR_PROJECT_TOKEN` with the unique token for your project (found in the project settings).

> If you’re [using a proxy](https://vemetric.com/docs/advanced-guides/using-a-proxy) to track data via your own domain, you can pass the `vemetric.WithHost("https://hub.yourdomain.com")` option to the client.

## Methods

Below you can find all the available methods and their functionality.

### trackEvent

The main method to track any kind of event.

```go
err = client.TrackEvent(&vemetric.TrackEventOpts{
  EventName: "SignupCompleted",
  UserIdentifier: "user-id",
  UserDisplayName: "John Doe",
  UserAvatarUrl: "https://example.com/avatar.jpg",
  EventData: map[string]any{
    "key": "value",
  },
})
```

You need to pass an `vemetric.TrackEventOpts` object with the following properties:

-   `EventName`: **Required:** The name of the event to track.
-   `UserIdentifier`: **Required:** The identifier of the user to associate the event with.
-   `UserDisplayName`: Optional: The display name of the user. (will be shown in the Vemetric UI)
-   `UserAvatarUrl`: Optional: The avatar URL of the user. (will be shown in the Vemetric UI)
-   `EventData`: Optional: An object containing the meta data of the event so you can later filter by
-   `UserData`: Optional: An object to [update the user data](https://vemetric.com/docs/product-analytics/user-identification#updating-user-data).
    -   `Set`: An object containing the user data to set, overriding existing values.
    -   `SetOnce`: An object containing the user data to set once, only if the keys do not exist yet.
    -   `Unset`: An array of keys to remove from the user data.

Checkout the [tracking custom events](https://vemetric.com/docs/product-analytics/tracking-custom-events) section to learn more.

### updateUser

Updates the data of the user with the given identifier.

```go
err = client.UpdateUser(&vemetric.UpdateUserOpts{
  UserIdentifier: "user-id",
  UserData: vemetric.UserData{
    Set: map[string]any{"key1": "value1"},
    SetOnce: map[string]any{"key2": "value2"},
    Unset: []string{"key3"},
  },
})
```

You need to pass an `vemetric.UpdateUserOpts` object with the following properties:

-   `UserIdentifier`: **Required:** The identifier of the user to associate the event with.
-   `UserData`: An object to [update the user data](https://vemetric.com/docs/product-analytics/user-identification#updating-user-data).
    -   `Set`: An object containing the user data to set, overriding existing values.
    -   `SetOnce`: An object containing the user data to set once, only if the keys do not exist yet.
    -   `Unset`: An array of keys to remove from the user data.

## Resources

[Go Package](https://pkg.go.dev/github.com/vemetric/vemetric-go)

View the Package of the Go SDK.

[Source code](https://github.com/vemetric/vemetric-go)

View the source code of the Go SDK on GitHub.
