analytics

package
v0.0.0-...-acbe8ed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package analytics is SolidPing's product-analytics (PostHog) client.

Off unless configured

The package is designed so that a deployment which has NOT configured PostHog does literally nothing: New returns a genuine no-op implementation that constructs no HTTP client, opens no connection and allocates no buffer, and the package-level default is that no-op. Nothing in this package reaches the network unless config.PostHogConfig.Active() is true, i.e. `posthog.enabled == true && posthog.project_api_key != ""`.

Call sites never branch

Following the Sentry wiring already used by the server, the client is a process-wide default installed once at startup (SetDefault) and used through the package-level Capture helper. Call sites therefore never ask "is analytics on" — they just Capture, and the no-op swallows it.

Privacy

Events are keyed by a pseudonymous distinct id built from the organization UID and user UID only (see DistinctID). This package must never be handed an email address, a check target host/URL, an incident payload, or any customer-supplied free text; the exported Event type deliberately carries no field for them and the fixed event-name set below is small on purpose.

Index

Constants

View Source
const (
	// EventOrgCreated fires when a new organization is created.
	EventOrgCreated = "org_created"
	// EventUserSignedUp fires when a user account is registered.
	EventUserSignedUp = "user_signed_up"
	// EventCheckCreated fires when a monitoring check is created. The check's
	// target is NEVER included — only its type.
	EventCheckCreated = "check_created"
	// EventIntegrationConnected fires when a notification integration
	// connection is created.
	EventIntegrationConnected = "integration_connected"
	// EventStatusPagePublished fires when a status page is published.
	EventStatusPagePublished = "status_page_published"
)

Event names. Deliberately a small, closed set: it is far easier to add an event later than to purge one from a warehouse.

Variables

This section is empty.

Functions

func Capture

func Capture(ctx context.Context, event Event)

Capture records an event on the process-wide client. This is what call sites use; when analytics is not configured it is a no-op function call.

func Close

func Close(ctx context.Context) error

Close flushes the process-wide client. Called on graceful shutdown.

func DistinctID

func DistinctID(orgUID, userUID string) string

DistinctID builds the pseudonymous distinct id used for every event. The dashboard's src/lib/analytics.ts MUST build the same string, so a browser session and its server-side events stitch together in PostHog.

Deliberately UUID-only: no email, no slug, no name.

func SetDefault

func SetDefault(c Client)

SetDefault installs the process-wide analytics client. Passing nil resets to the no-op.

Types

type Client

type Client interface {
	// Capture records an event. It must never block the caller and never
	// return an error to a request path — delivery is best-effort.
	Capture(ctx context.Context, event Event)
	// Enabled reports whether this client actually sends anything.
	Enabled() bool
	// Close flushes buffered events. Safe to call on a no-op client.
	Close(ctx context.Context) error
}

Client captures product events.

func Default

func Default() Client

Default returns the process-wide analytics client, never nil.

func New

func New(cfg config.PostHogConfig) Client

New builds the analytics client for the given configuration.

It returns the no-op client — and constructs NOTHING else — whenever PostHog is not active. This is the single point where the "off unless configured" guarantee is enforced server-side; it applies exactly the same rule as GET /api/v1/config and the dashboard.

func NewNoop

func NewNoop() Client

NewNoop returns the no-op client. Exported for tests and for call sites that want to be explicit about disabling analytics.

type Event

type Event struct {
	// Name is one of the Event* constants above.
	Name string
	// OrgUID is the organization UUID (pseudonymous).
	OrgUID string
	// UserUID is the acting user's UUID (pseudonymous). May be empty for
	// system-initiated actions.
	UserUID string
	// Properties are additional non-identifying event properties.
	Properties map[string]any
}

Event is a product event. It intentionally offers no free-text field: the only caller-supplied payload is Properties, which must contain low-cardinality non-identifying values (a check type, a provider name), never a hostname, a URL, an email or user-entered text.

Directories

Path Synopsis
Package signupguard provides the source-level scan that keeps the user_signed_up product event honest (spec 2026-08-02-08).
Package signupguard provides the source-level scan that keeps the user_signed_up product event honest (spec 2026-08-02-08).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL