> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hightouch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go SDK

> Hightouch's Go SDK for collecting events

The Go SDK makes it easy to track events from Go applications.

## Installation

The Go SDK can be installed from [GitHub](https://github.com/ht-sdks/events-sdk-go):

```
go get github.com/ht-sdks/events-sdk-go
```

To initialize the Go SDK in your application, create a new `Client` instance:

```
package main

import (
  "github.com/ht-sdks/events-sdk-go"
)

func main() {
  client, _ := htevents.NewWithConfig("WRITE_KEY", htevents.Config{
    Endpoint: "https://us-east-1.hightouch-events.com"
  })
  defer client.Close()
}
```

## API

### Identify

The `htevents.Identify` message sends an `identify` event.

Unlike the [Browser SDK](https://docs.hightouch.com/events/sdks/browser.md), it does **not** persist the user ID and
traits locally, so user IDs must be explicitly added to other events. This is
because server side events are usually servicing many different users at once.

**Example usage**:

```
client.Enqueue(htevents.Identify{
  UserId: "123",
  Traits: htevents.Traits{
    "location": "San Francisco",
  },
})
```

**Method parameters**:

| Parameter | Type | Description |
| - | - | - |
| `UserId` | string | The user's persistent ID |
| `AnonymousId` | string | The user's anonymous ID |
| `Traits` | Traits | Additional traits about the user, such as `email` and `name`. |
| `Context` | Context | Overrides to values in the event `Context`. By default, `Context` contains information autocollected by the SDK. |
| `Timestamp` | Time | The date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date. |

### Track

The `htevents.Track` message sends a `track` event.

**Example usage**:

```
client.Enqueue(htevents.Track{
  Event:  "Order completed",
  UserId: "123",
  Properties: htevents.Properties{
    "total": 29.99,
  },
})
```

**Method parameters**:

| Parameter | Type | Description |
| - | - | - |
| `UserId` | string | The user's persistent ID |
| `AnonymousId` | string | The user's anonymous ID |
| `Event` | string | The name of the event. |
| `Properties` | Properties | Additional properties about the event, such as `product_id`. |
| `Context` | Context | Overrides to values in the event `Context`. By default, `Context` contains information autocollected by the SDK. |
| `Timestamp` | Time | The date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date. |

### Page

The `htevents.Page` message sends a `page` event.

**Example usage**:

```
client.Enqueue(htevents.Page{
  Name:   "Getting started",
  UserId: "123",
  Properties: htevents.Properties{
    "total": 29.99,
  },
})
```

**Method parameters**:

| Parameter | Type | Description |
| - | - | - |
| `UserId` | string | The user's persistent ID |
| `AnonymousId` | string | The user's anonymous ID |
| `Name` | string | The page's name. For example "Getting started" |
| `Properties` | Properties | Additional properties about the event, such as `url`. |
| `Context` | Context | Overrides to values in the event `Context`. By default, `Context` contains information autocollected by the SDK. |
| `Timestamp` | Time | The date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date. |

### Screen

The `htevents.Screen` message sends a `screen` event.

**Example usage**:

```
client.Enqueue(htevents.Screen{
  Name:   "Getting started",
  UserId: "123",
  Properties: htevents.Properties{
    "total": 29.99,
  },
})
```

**Method parameters**:

| Parameter | Type | Description |
| - | - | - |
| `UserId` | string | The user's persistent ID |
| `AnonymousId` | string | The user's anonymous ID |
| `Name` | string | The page's name. For example "Getting started" |
| `Properties` | Properties | Additional properties about the event, such as `url`. |
| `Context` | Context | Overrides to values in the event `Context`. By default, `Context` contains information autocollected by the SDK. |
| `Timestamp` | Time | The date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date. |

### Group

The `htevents.Group` message sends a `group` event.

**Example usage**:

```
client.Enqueue(htevents.Group{
  GroupId: "G-1",
  UserId:  "123",
  Traits: htevents.Traits{
    "company_location": "San Francisco",
  },
})
```

**Method parameters**:

| Parameter | Type | Description |
| - | - | - |
| `UserId` | string | The user's persistent ID |
| `AnonymousId` | string | The user's anonymous ID |
| `GroupId` | string | The id for the group. |
| `Traits` | Traits | Additional traits about the group, such as `company_name`. |
| `Context` | Context | Overrides to values in the event `Context`. By default, `Context` contains information autocollected by the SDK. |
| `Timestamp` | Time | The date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date. |

### Close

The Go SDK buffers events locally before sending them to Hightouch's servers.
This minimizes the number of requests made by the SDK and makes the tracking
non-blocking.

To force the local buffer to be sent to Hightouch immediately call the `Close`
method. `Close` should be called when shutting down your app to make sure no events are lost.

**Example usage**:

```
client.Close()
```
