RudderStack Go SDK
Use RudderStack’s Go SDK to send server-side events to various destinations.
RudderStack’s Go SDK lets you track and send the events from your Go applications to the specified destinations.
See the Go SDK GitHub codebase for implementation-specific details.

SDK setup requirements

The Setup tab in the RudderStack dashboard has the SDK installation snippet containing both the write key and the data plane URL. Use it to integrate the Go SDK into your application.
Install Go SDK
To install the Go SDK in the GOPATH, run the following command:
go get github.com/rudderlabs/analytics-go
Initialize the SDK
Run the following code snippet to initialize the Go SDK:
package main
import (
"github.com/rudderlabs/analytics-go/v4"
)
func main() {
// Instantiates a client to use send messages to the RudderStack API.
// Use your write key in the below placeholder:
client := analytics.New(<WRITE_KEY>, <DATA_PLANE_URL>)
// Enqueues a track event that will be sent asynchronously.
client.Enqueue(analytics.Track{
UserId: "1hKOmRA4GRlm",
Event: "Test Event",
})
// Flushes any queued messages and closes the client.
client.Close()
}
Alternatively, you can run the following snippet:
package main
import (
"github.com/rudderlabs/analytics-go/v4"
)
func main() {
// Instantiates a client to use send messages to the RudderStack API.
// Enter your write key in the below placeholder:
client, _ := analytics.NewWithConfig(WRITE_KEY,
analytics.Config{
DataPlaneUrl: DATA_PLANE_URL,
Interval: 30 * time.Second,
BatchSize: 100,
Verbose: true,
DisableGzip: false, // Set to true to disable Gzip compression.
})
// Enqueues a track event that will be sent asynchronously.
client.Enqueue(analytics.Track{
UserId: "1hKOmRA4GRlm",
Event: "Test Event",
})
// Flushes any queued messages and closes the client.
client.Close()
}
Migrate to SDK v4
To migrate to the Go SDK v4.1.0, set the data plane URL in Config (as seen in the above section) instead of passing it as an argument.
SDK initialization options
The RudderStack Go SDK provides the following parameters which you can pass during the SDK’s initialization:
| Parameter | Data type | Description |
|---|
DataPlaneUrl | String | Your RudderStack data plane URL. |
Interval | Time (in sec) | The SDK sends the messages when this flushing interval time has elapsed.
Default value: 30 |
BatchSize | Integer | Total number of messages to be sent in a single batch.
Default value: 250 |
Verbose | Boolean | When set to true, the client sends more frequent and detailed messages to the logger.
Default value: false |
RetryAfter | Function | A function that takes an integer (retry count) and returns time.Duration, allowing for dynamic backoff strategies. |
DisableGzip | Boolean | Disables gzip compression of the requests.
Default value: false |
NoProxySupport | Boolean | Set this variable to true if you do not use a proxy to send the events.
Default value: false
 Setting NoProxySupport to true will avoid RudderStack making calls to the proxy for fetching the total number of nodes in case of a multi-node setup.
|
Gzip event requests

The Go SDK supports the Gzip compression feature from v4.1.0 and above.
The Go SDK automatically gzips requests. However, you can disable this by setting the DisableGzip parameter to true while initializing the SDK:
client, _ := analytics.NewWithConfig(WRITE_KEY,
analytics.Config{
DataPlaneUrl: DATA_PLANE_URL,
Interval: 30 * time.Second,
BatchSize: 100,
Verbose: true,
DisableGzip: true
})

The
DisableGzip parameter requires
rudder-server version 1.4 or higher. Otherwise, your events might fail.
Supported events

RudderStack does not store or persist the user state in any of the server-side SDKs.
Unlike the client-side SDKs that deal with only a single user at a given time, the server-side SDKs deal with multiple users simultaneously. Therefore, you must specify either the userId or anonymousId every time while making any API calls supported by the Go SDK.
Identify
The identify call lets you identify a visiting user and associate them to their actions. It also lets you record the traits about them like their name, email address, etc.
A sample identify call is shown:
client.Enqueue(analytics.Identify{
UserId: "1hKOmRA4GRlm",
Traits: analytics.NewTraits().
SetName("Alex Keener").
SetEmail("alex@example.com").
Set("plan", "Free").
Set("manager", 12),
})
The identify method parameters are as described below:
| Field | Data type | Description |
|---|
UserId Required, if AnonymousId is absent. | String | Unique identifier for a user in your database. |
AnonymousId Required, if UserId is absent. | String | The SDK automatically sets this identifier in cases where there is no unique identifier for the user. |
Traits | Object | An optional dictionary of the user’s traits, like Name or Email. |
Context | Object | An optional dictionary of information that provides context about the event. It is not directly related to the API call. |
Integrations | Object | An optional dictionary containing the destinations to be enabled or disabled. |
Timestamp | Timestamp in ISO 8601 format | The timestamp of the event’s arrival. |
Track
The track call lets you record the user actions along with their associated properties. Each user action is called an event.
A sample track call is shown below:
client.Enqueue(analytics.Track{
UserId: "1hKOmRA4GRlm",
Event: "Signed Up",
Properties: analytics.NewProperties().
Set("plan", "Free"),
})
The track method parameters are as described below:
| Field | Data type | Description |
|---|
UserId Required, if AnonymousId is absent. | String | Unique identifier for a user in your database. |
AnonymousId Required, if UserId is absent. | String | The SDK automatically sets this identifier in cases where there is no unique identifier for the user. |
Event Required | String | Name of the event. |
Properties | Object | An optional dictionary of the properties associated with the event. |
Context | Object | An optional dictionary of information that provides context about the event. It is not directly related to the API call. |
Integrations | Object | An optional dictionary containing the destinations to be enabled or disabled. |
Timestamp | Timestamp in ISO 8601 format | The timestamp of the event’s arrival. |
Page
The page call lets you record the page views on your application along with the other relevant information about the page.
A sample page call is as shown:
client.Enqueue(analytics.Page{
UserId: "12345",
Name: "Pizza",
Properties: analytics.NewProperties().
SetURL("https://dominos.com"),
})
The page method parameters are as described below:
| Field | Data type | Description |
|---|
UserId Required, if AnonymousId is absent. | String | Unique identifier for a user in your database. |
AnonymousId Required, if UserId is absent. | String | The SDK automatically sets this identifier in cases where there is no unique identifier for the user. |
Name Required | String | Name of the viewed page. |
Properties | Object | An optional dictionary of the properties associated with the viewed page, like URL or Referrer. |
Context | Object | An optional dictionary of information that provides context about the event. It is not directly related to the API call. |
Integrations | Object | An optional dictionary containing the destinations to be enabled or disabled. |
Timestamp | Timestamp in ISO 8601 format | The timestamp of the event’s arrival. |
Screen
The screen call is the mobile equivalent of the page call. It lets you record the screen views on your mobile app along with other relevant information about the screen.
A sample screen call is as shown:
client.Enqueue(analytics.Screen{
UserId: "1hKOmRA4GRlm",
Name: "Pizza",
Properties: analytics.NewProperties().
SetURL("https://dominos.com"),
})
The screen method parameters are as described below:
| Field | Data type | Description |
|---|
UserId Required, if AnonymousId is absent. | String | Unique identifier for a user in your database. |
AnonymousId Required, if UserId is absent. | String | The SDK automatically sets this identifier in cases where there is no unique identifier for the user. |
Name Required | String | Name of the viewed screen. |
Properties | Object | An optional dictionary of the properties associated with the viewed screen, like URL or Referrer. |
Context | Object | An optional dictionary of information that provides context about the event. It is not directly related to the API call. |
Integrations | Object | An optional dictionary containing the destinations to be enabled or disabled. |
Timestamp | Timestamp in ISO 8601 format | The timestamp of the event’s arrival. |
Group
The group call lets you link an identified user with a group, such as a company, organization, or an account. It also lets you record any custom traits or properties associated with that group.
A sample group call made using the Go SDK is shown below:
client.Enqueue(analytics.Group{
UserId: "1hKOmRA4GRlm",
GroupId: "1",
Traits: map[string]interface{}{
"name": "Company",
"description": "Facebook",
},
})
The group method parameters are as follows:
| Field | Data type | Description |
|---|
UserId Required, if AnonymousId is absent. | String | Unique identifier for a user in your database. |
AnonymousId Required, if UserId is absent. | String | The SDK automatically sets this identifier in cases where there is no unique identifier for the user. |
GroupId Required | String | Unique identifier of the group in your database. |
Traits | Object | An optional dictionary of the group’s traits like Name or Email. |
Context | Object | An optional dictionary of information that provides context about the event. It is not directly related to the API call. |
Integrations | Object | An optional dictionary containing the destinations to be enabled or disabled. |
Timestamp | Timestamp in ISO 8601 format | The timestamp of the event’s arrival. |
Alias
The alias call lets you merge different identities of a known user. It is an advanced method that lets you change the tracked user’s ID explicitly. You can use alias for managing the user’s identity in some of the downstream destinations.
A sample alias call is as shown:
client.Enqueue(analytics.Alias{
PreviousId: "12345",
UserId: "1hKOmRA4GRlm",
})
The alias method parameters are as mentioned below:
| Field | Data type | Description |
|---|
UserId Required, if AnonymousId is absent. | String | Unique identifier for a user in your database. |
AnonymousId Required, if UserId is absent. | String | The SDK automatically sets this identifier in cases where there is no unique identifier for the user. |
PreviousId Required | String | The previous unique identifier of the user. |
Context | Object | An optional dictionary of information that provides context about the event. It is not directly related to the API call. |
Integrations | Object | An optional dictionary containing the destinations to be enabled or disabled. |
Timestamp | Timestamp in ISO 8601 format | The timestamp of the event’s arrival. |
Context and traits
The Context object supports sending standard contextual properties along with the Extra object to add any custom properties.

Note that:
- All event APIs support sending contextual data through the
Context field. - The custom properties sent through the
Extra field appear directly in root level of the context object of the event payload.
The Traits object lets you include user attributes that provide additional context about the user.
A sample track event containing the above fields is shown below:
client.Enqueue(analytics.Track{
UserId: "1hKOmRA4GRlm",
Event: "Button Clicked",
Properties: analytics.NewProperties().
Set("button_name", "signup_cta").
Set("button_location", "header").
Set("page_section", "hero").
Set("value", 29.99),
Context: &analytics.Context{
Traits: analytics.Traits{
"subscription_level": "premium",
"age": 30,
},
Extra: map[string]interface{}{
"customField": "customValue",
"experimentId": 12345,
},
},
})
The corresponding event payload looks when you include these contextual properties is shown below:
{
"anonymousId": "anon_67890",
"channel": "server",
"context": {
"app": {
"build": "100",
"name": "MyApp",
"namespace": "com.mycompany.myapp",
"version": "1.0.0"
},
"library": {
"name": "analytics-go",
"version": "4.2.2"
},
"traits": {
// User attributes from Context.Traits
"age": 30,
"subscription_level": "premium"
},
// Custom properties from Context.Extra
"customField": "customValue",
"experimentId": 12345
},
"event": "Button Clicked",
"integrations": {
"All": true,
"Google Analytics": false
},
"messageId": "68c19e6e-3a9d-4546-97c0-75180bfbdadf",
"originalTimestamp": "2025-10-13T21:02:23.06924+05:30",
"properties": {
// Event-specific properties
"button_location": "header",
"button_name": "signup_cta",
"page_section": "hero",
"value": 29.99
},
"receivedAt": "2025-10-13T15:32:25.953026288Z",
"request_ip": "106.51.149.173",
"rudderId": "ac59e9bd-5503-42e7-9054-8bfb3fd08d67",
"sentAt": "2025-10-13T21:02:25.070593+05:30",
"type": "track",
"userId": "1hKOmRA4GRlm"
}
FAQ
How does the Go SDK handle events larger than 32KB?
The Go SDK drops any events greater than 32KB. To avoid data loss, ensure your events are within this size limit.
Does the Go SDK support event ordering?
The Go SDK does not support event ordering by default. Events are processed asynchronously in batches for better performance.
What happens if the data plane URL is unreachable?
If the data plane URL is unreachable, the SDK will:
- Retry sending the events based on the
RetryAfter configuration. - Buffer events up to the configured
BatchSize. - Drop events if the buffer is full.
Questions? Contact us by Email or on
Slack