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

    Capture custom events using the PostHog client:

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

    By default, for backwards compatibility reasons, events are sent with person profile processing enabled. This means a person profile will be created for each user who triggers an event.

    If you want to disable person profile processing for certain events, send the event with the following property:

    Go
    "$process_person_profile": false

Community questions

Was this page useful?

Questions about this page? or post a community question.