Documentation
¶
Overview ¶
Package analytics is an app-internal product-analytics plugin for togo — event tracking with volume, top-events, funnels, retention and active-user metrics (a Mixpanel-lite you self-host inside your togo app).
a, _ := analytics.FromKernel(k)
a.Track(ctx, analytics.Event{Name: "signup", UserID: "u1", Properties: map[string]any{"plan": "pro"}})
vol := a.Volume("signup", from, to, analytics.Daily)
Index ¶
- type Bucket
- type Count
- type Dashboard
- type Event
- type FunnelStep
- type RetentionRow
- type Service
- func (s *Service) ActiveUsers(from, to time.Time) int
- func (s *Service) DashboardSummary(days int) Dashboard
- func (s *Service) Funnel(steps []string, from, to time.Time) []FunnelStep
- func (s *Service) Identify(userID string, traits map[string]any)
- func (s *Service) Retention(from time.Time, offsets []int) []RetentionRow
- func (s *Service) TopEvents(from, to time.Time, limit int) []Count
- func (s *Service) TopProperties(event, prop string, from, to time.Time, limit int) []Count
- func (s *Service) Track(ctx context.Context, e Event)
- func (s *Service) Traits(userID string) map[string]any
- func (s *Service) Volume(name string, from, to time.Time, b Bucket) []VolumePoint
- type Store
- type VolumePoint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dashboard ¶
type Dashboard struct {
TotalEvents int `json:"total_events"`
DAU int `json:"dau"`
WAU int `json:"wau"`
TopEvents []Count `json:"top_events"`
}
Dashboard is a summary snapshot for an overview UI.
type Event ¶
type Event struct {
Name string `json:"name"`
UserID string `json:"user_id,omitempty"`
AnonID string `json:"anon_id,omitempty"`
Properties map[string]any `json:"properties,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
Event is a tracked product event.
type FunnelStep ¶
type FunnelStep struct {
Event string `json:"event"`
Count int `json:"count"`
Conversion float64 `json:"conversion"` // fraction of step 0 that reached here
}
FunnelStep is one step's conversion in a funnel.
type RetentionRow ¶
RetentionRow is a cohort retention row (returning users at an offset).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the analytics runtime stored on the kernel (k.Get("analytics")).
func FromKernel ¶
FromKernel returns the analytics Service registered on the kernel.
func (*Service) ActiveUsers ¶
ActiveUsers counts distinct users active in [from,to).
func (*Service) DashboardSummary ¶
Dashboard returns a summary over the last `days` days (default 7).
func (*Service) Funnel ¶
func (s *Service) Funnel(steps []string, from, to time.Time) []FunnelStep
Funnel computes ordered conversion: of users who did step 0, how many went on to do each subsequent step (in order, by time) within [from,to).
func (*Service) Retention ¶
func (s *Service) Retention(from time.Time, offsets []int) []RetentionRow
Retention: of users first seen in [from,from+1d), how many returned on day offsets (0,1,7 by default) — simple activity-based retention.
func (*Service) TopProperties ¶
TopProperties ranks values of a property for a given event.
type VolumePoint ¶
VolumePoint is one time bucket of an event-volume series.