Documentation
¶
Overview ¶
Package analytics provides a thin, non-blocking wrapper around PostHog for capturing product analytics events. It is intentionally separate from the logging package so that analytics events and log forwarding can evolve independently and a failure in one never affects the other.
Usage:
tracker := analytics.New(cfg.PostHogAPIKey, cfg.PostHogEndpoint)
defer tracker.Close()
tracker.Capture("note.created", userID, map[string]any{"note_id": noteID})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NoopTracker ¶
type NoopTracker struct{}
NoopTracker silently discards all events. Returned by New when no API key is configured so callers never need to guard against a nil Tracker.
func (NoopTracker) Close ¶
func (NoopTracker) Close()
type PostHogTracker ¶
type PostHogTracker struct {
// contains filtered or unexported fields
}
PostHogTracker forwards events to the PostHog API via the official SDK.
func (*PostHogTracker) Capture ¶
func (t *PostHogTracker) Capture(event string, distinctID string, properties map[string]any)
Capture enqueues a PostHog Capture event. The call is non-blocking — the SDK batches events internally and flushes them on its own interval. Any enqueue error is intentionally swallowed so a PostHog outage never surfaces to callers.
func (*PostHogTracker) Close ¶
func (t *PostHogTracker) Close()
Close flushes any buffered events and shuts down the underlying PostHog client.
type Tracker ¶
type Tracker interface {
// Capture enqueues an analytics event. It is non-blocking and always
// succeeds from the caller's perspective.
Capture(event string, distinctID string, properties map[string]any)
// Close flushes any buffered events and releases resources. The caller
// must invoke Close before the process exits — typically via defer.
Close()
}
Tracker captures product analytics events. Implementations must be safe for concurrent use. A Tracker must never return an error from Capture — a PostHog outage or misconfiguration must not affect application availability.