multisource

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SourcePropertyKey is the event property used to identify the analytics source (e.g. ios, web).
	// For PostHog, where a single API key is shared across sources, this property distinguishes events.
	SourcePropertyKey = "source"
)

Variables

This section is empty.

Functions

func RegisterMultiSourceEventReporter

func RegisterMultiSourceEventReporter(i do.Injector)

RegisterMultiSourceEventReporter registers a *MultiSourceEventReporter with the injector. Prerequisite: map[string]*analyticscfg.SourceConfig must be registered in the injector.

Types

type MultiSourceEventReporter

type MultiSourceEventReporter struct {
	// contains filtered or unexported fields
}

MultiSourceEventReporter delegates events to per-source EventReporters. The reporters map is populated at construction and never mutated afterwards, so reads need no synchronization.

func NewMultiSourceEventReporter

func NewMultiSourceEventReporter(
	reporters map[string]analytics.EventReporter,
	logger logging.Logger,
	tracerProvider tracing.TracerProvider,
) *MultiSourceEventReporter

NewMultiSourceEventReporter returns a new MultiSourceEventReporter.

func ProvideMultiSourceEventReporter

func ProvideMultiSourceEventReporter(
	ctx context.Context,
	proxySources map[string]*analyticscfg.SourceConfig,
	logger logging.Logger,
	tracerProvider tracing.TracerProvider,
	metricsProvider metrics.Provider,
) (*MultiSourceEventReporter, error)

ProvideMultiSourceEventReporter builds a MultiSourceEventReporter from proxy sources config. For each source, attempts to create an EventReporter via ProvideCollector. If creation fails (e.g. missing credentials) or provider is unset, uses Noop for that source.

For PostHog: reporters are deduplicated by API key. Sources sharing the same PostHog API key reuse a single client (the source name is set as a property on each event), while sources with distinct API keys each get their own client so their credentials and circuit breaker are honored.

func (*MultiSourceEventReporter) AddUser

func (m *MultiSourceEventReporter) AddUser(ctx context.Context, source, userID string, properties map[string]any) error

AddUser identifies a user against the reporter for the given source, forwarding the user's traits. Every underlying reporter supports identify via analytics.EventReporter.AddUser.

func (*MultiSourceEventReporter) Close

func (m *MultiSourceEventReporter) Close()

Close flushes and closes every underlying reporter. Reporters shared across multiple sources (e.g. PostHog sources with the same API key) are closed exactly once.

func (*MultiSourceEventReporter) Shutdown

func (m *MultiSourceEventReporter) Shutdown()

Shutdown implements do.Shutdowner so the DI container flushes buffered events on shutdown.

func (*MultiSourceEventReporter) TrackAnonymousEvent

func (m *MultiSourceEventReporter) TrackAnonymousEvent(ctx context.Context, source, event, anonymousID string, properties map[string]any) error

TrackAnonymousEvent records an event for an anonymous user.

func (*MultiSourceEventReporter) TrackEvent

func (m *MultiSourceEventReporter) TrackEvent(ctx context.Context, source, event, userID string, properties map[string]any) error

TrackEvent records an event for an identified user.

Jump to

Keyboard shortcuts

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