Go product analytics installation

  1. Install the package

    Required

    Install the PostHog Go library:

    Terminal
    go get "github.com/posthog/posthog-go"
  2. Configure PostHog

    Required

    Initialize the PostHog client with your API key and host:

    main.go
    package main
    import (
    "github.com/posthog/posthog-go"
    )
    func main() {
    client, _ := posthog.NewWithConfig("<ph_project_api_key>", posthog.Config{Endpoint: "https://us.i.posthog.com"})
    defer client.Close()
    }
  3. Send events

    Recommended

    Once installed, you can manually send events to test your integration:

    Go
    client.Enqueue(posthog.Capture{
    DistinctId: "user_123",
    Event: "button_clicked",
    Properties: posthog.NewProperties().
    Set("button_name", "signup"),
    })
  4. Next steps

    Recommended

    Now that you're capturing events, continue with the resources below to learn what else Product Analytics enables within the PostHog platform.

    ResourceDescription
    Capturing eventsLearn how to capture custom events beyond autocapture
    Identifying usersAssociate events with specific users
    Creating insightsBuild trends, funnels, and retention charts
    Group analyticsTrack events at the company or account level

Community questions

Was this page useful?

Questions about this page? or post a community question.