Documentation
¶
Overview ¶
Package posthogkit provides a non-blocking, batched PostHog analytics client. Events are buffered in memory and flushed periodically via tick or when the buffer reaches FlushSize. All capture methods are no-ops when Enabled is false.
Index ¶
- type Client
- func (c *Client) Capture(distinctID, eventName string, props map[string]any)
- func (c *Client) CaptureWithGroups(distinctID, eventName string, props map[string]any, groups map[string]string)
- func (c *Client) Check() health.Check
- func (c *Client) Close()
- func (c *Client) Flusher() func(context.Context) error
- func (c *Client) GroupIdentify(groupType, groupKey string, props map[string]any)
- func (c *Client) HashID(id string) string
- func (c *Client) Identify(distinctID string, props map[string]any)
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a non-blocking, batched PostHog analytics client. Capture methods synchronously snapshot event data before returning, so callers retain ownership of their maps and slices.
func New ¶
New creates a new PostHog client. Defaults are applied for Host ("https://us.i.posthog.com"), FlushInterval (30s), and FlushSize (100).
func (*Client) CaptureWithGroups ¶
func (c *Client) CaptureWithGroups(distinctID, eventName string, props map[string]any, groups map[string]string)
CaptureWithGroups records an event with group context.
func (*Client) Check ¶
Check returns a health.Check that reports healthy when the client is enabled and configured with an API key. Register with health.All().
func (*Client) Close ¶
func (c *Client) Close()
Close stops and joins the flush goroutine before performing a final synchronous flush. Safe to call multiple times and concurrently.
func (*Client) Flusher ¶
Flusher returns a tick-compatible function that periodically flushes the event buffer. Pass the result to lifecycle.Run.
func (*Client) GroupIdentify ¶
GroupIdentify associates properties with a group.
type Config ¶
type Config struct {
APIKey string `env:"POSTHOG_API_KEY" required:"false"`
Host string `env:"POSTHOG_HOST" default:"https://us.i.posthog.com"`
FlushInterval time.Duration `env:"POSTHOG_FLUSH_INTERVAL" default:"30s"`
FlushSize int `env:"POSTHOG_FLUSH_SIZE" default:"100"`
Enabled bool `env:"POSTHOG_ENABLED" default:"true"`
HMACSecret string `env:"POSTHOG_HMAC_SECRET" required:"false"`
}
Config holds PostHog client configuration. Fields are populated by config.MustLoad[Config]() from environment variables using the env tags.