Search documentation...

K
ChangelogBook a demoSign up

Go SDK

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

Installation

The Go SDK can be installed from GitHub:

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, 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:

ParameterTypeDescription
UserIdstringThe user's persistent ID
AnonymousIdstringThe user's anonymous ID
TraitsTraitsAdditional traits about the user, such as email and name.
ContextContextOverrides to values in the event Context. By default, Context contains information autocollected by the SDK.
TimestampTimeThe 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:

ParameterTypeDescription
UserIdstringThe user's persistent ID
AnonymousIdstringThe user's anonymous ID
EventstringThe name of the event.
PropertiesPropertiesAdditional properties about the event, such as product_id.
ContextContextOverrides to values in the event Context. By default, Context contains information autocollected by the SDK.
TimestampTimeThe 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:

ParameterTypeDescription
UserIdstringThe user's persistent ID
AnonymousIdstringThe user's anonymous ID
NamestringThe page's name. For example "Getting started"
PropertiesPropertiesAdditional properties about the event, such as url.
ContextContextOverrides to values in the event Context. By default, Context contains information autocollected by the SDK.
TimestampTimeThe 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:

ParameterTypeDescription
UserIdstringThe user's persistent ID
AnonymousIdstringThe user's anonymous ID
NamestringThe page's name. For example "Getting started"
PropertiesPropertiesAdditional properties about the event, such as url.
ContextContextOverrides to values in the event Context. By default, Context contains information autocollected by the SDK.
TimestampTimeThe 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:

ParameterTypeDescription
UserIdstringThe user's persistent ID
AnonymousIdstringThe user's anonymous ID
GroupIdstringThe id for the group.
TraitsTraitsAdditional traits about the group, such as company_name.
ContextContextOverrides to values in the event Context. By default, Context contains information autocollected by the SDK.
TimestampTimeThe 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()

Ready to get started?

Jump right in or a book a demo. Your first destination is always free.

Book a demoSign upBook a demo

Need help?

Our team is relentlessly focused on your success. Don't hesitate to reach out!

Feature requests?

We'd love to hear your suggestions for integrations and other features.

Last updated: Mar 12, 2024

On this page

InstallationAPIIdentifyTrackPageScreenGroupClose

Was this page helpful?