modulepackage
4.2.1
Repository: https://github.com/rudderlabs/analytics-go.git
Documentation: pkg.go.dev
# README
The Customer Data Platform for Developers
Website · Documentation · Community Slack
RudderStack Go SDK
The RudderStack Go SDK lets you send customer event data from your Go applications to your specified destinations.
SDK setup requirements
- 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.
Installation
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
Using the 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: "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()
}
Gzip support
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. |
---|
Sending events
Refer to the RudderStack Go SDK documentation for more information on the supported event types.
License
The RudderStack Go SDK is released under the MIT license.
# Functions
Instantiate a new client that uses the write key passed as first argument to send messages to the backend.
No description provided by the author
No description provided by the author
No description provided by the author
Instantiate a new client that uses the write key and configuration passed as arguments to send messages to the backend.
This function instantiate an object that statisfies the analytics.Logger interface and send logs to standard logger passed as argument.
No description provided by the author
# Constants
This constant sets the default batch size used by client instances if none was explicitly set.
No description provided by the author
This constant sets the default flush interval used by client instances if none was explicitly set.
Version of the client.
# Variables
This error is returned by methods of the `Client` interface when they are called after the client was already closed.
This error is used to notify the client callbacks that a message send failed because the JSON representation of a message exceeded the upper limit.
This error is used to notify the application that too many requests are already being sent and no more messages can be accepted.
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
Instances of this type carry the different configuration options that may be set when instantiating a client.
Returned by the `NewWithConfig` function when the one of the configuration fields was set to an impossible value (like a negative duration).
No description provided by the author
No description provided by the author
Instances of this type are used to represent errors returned when a field was no initialize properly in a structure passed as argument to one of the functions of this package.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
This type represents products in the E-commerce API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
Values implementing this interface are used by analytics clients to notify the application when a message send succeeded or failed.
This interface is the main API exposed by the analytics package.
No description provided by the author
Instances of types implementing this interface can be used to define where the analytics client logs are written.
This interface is used to represent analytics objects that can be sent via a client.
# Type aliases
No description provided by the author
This type is used to represent properties in messages that support it.
No description provided by the author