Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

bufbuild/analytics-go

 
 

Repository files navigation

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

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.

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%