The Customer Data Platform for Developers
Website · Documentation · Community Slack
The RudderStack Go SDK lets you send customer event data from your Go applications to your specified destinations.
- Set up a RudderStack open source account.
- Set up a Go source in the dashboard.
- Copy the write key and the data plane URL. For more information, refer to the Go SDK documentation.
You can install the Go SDK via the go get
command.
It is highly recommended to use a tool like Godep to avoid any issues related to the breaking API changes introduced between the major versions of the library. |
---|
To install the SDK in the GOPATH
, run the following:
go get github.com/rudderlabs/analytics-go
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: "test-user",
Event: "test-snippet",
})
// 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.
// User 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 // Enables Gzip compression - set true to disable Gzip.
})
// Enqueues a track event that will be sent asynchronously.
client.Enqueue(analytics.Track{
UserId: "test-user",
Event: "test-snippet",
})
// Flushes any queued messages and closes the client.
client.Close()
}
The Go SDK supports Gzip compression from version 4.1.0 and it is enabled by default. However, you can disable this feature by setting the DisableGzip
parameter to true
while initializing the SDK, as shown:
client, _ := analytics.NewWithConfig(WRITE_KEY,
analytics.Config{
DataPlaneUrl: DATA_PLANE_URL,
Interval: 30 * time.Second,
BatchSize: 100,
Verbose: true,
DisableGzip: false // Enables Gzip compression - set true to disable Gzip.
})
Note: Gzip requires rudder-server version 1.4 or later. |
---|
Refer to the RudderStack Go SDK documentation for more information on the supported event types.
The RudderStack Go SDK is released under the MIT license.