Help us shape the future of Go! Take the 2026 Go Developer Survey

analytics

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package analytics computes the dashboard's Overview: contacts, Engagement rates, automations and the daily time series (GLOSSARY "Engagement rates").

Days are Report days (ADR 0057): calendar days in the Workspace time zone, cut by internal/reportday, so the whole history is re-bucketed the moment the zone changes.

Engagement rates are a send cohort: the denominator is the Broadcast recipients sent in the window, and opens and clicks are counted among that same cohort, so opened never exceeds sent and every rate is within [0, 1]. They are not the Sending-domain Complaint and Bounce rates of internal/reputation.

Index

Constants

View Source
const (
	OwnerBroadcast  = linkclicks.OwnerBroadcast
	OwnerAutomation = linkclicks.OwnerAutomation
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Automations

type Automations struct {
	Total, Active, RunsActive, RunsCompleted int
}

Automations is a point-in-time snapshot.

type Contacts

type Contacts struct {
	Total, Active, Unsubscribed, NewInWindow int
}

Contacts is the contact breakdown: Unsubscribed is "globally non-mailable" (ADR 0001), Active the remainder.

type Email

type Email struct {
	Sent, Opened, Clicked                int
	OpenRate, ClickRate, ClickToOpenRate float32
}

Email is the send cohort's counts and Engagement rates.

type EventAction

type EventAction struct {
	Action   string
	Count    int
	Contacts int
	LastAt   time.Time
}

EventAction is one action of the Events report: how often it happened in the window, for how many distinct Contacts (an anonymous Event counts as an occurrence, not as a Contact) and when it last happened.

type HourCell

type HourCell struct {
	Weekday, Hour, Opens int
}

HourCell is the human opens of one weekday and hour of day in the Workspace time zone. Weekday is ISO: 1 is Monday, 7 is Sunday.

type LinkClicks

type LinkClicks struct {
	URL    string
	Clicks int
	Owners []OwnerClicks
}

LinkClicks is one link with its clicks over the window and the Broadcasts and Automations that carried it, most clicked first.

type Module

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

Module computes Overviews. Its clock is time.Now.

func New

func New() *Module
func (m *Module) ClicksByLink(ctx context.Context, s *ent.Scoped, w Window) ([]LinkClicks, error)

ClicksByLink counts the human clicks of the window over the whole Workspace by link, each link split by the Broadcast or Automation that carried it (ADR 0053 leaves machine clicks out). Every click is an Event, so the counts cover the Event retention window.

func (*Module) Events

func (m *Module) Events(ctx context.Context, s *ent.Scoped, w Window) ([]EventAction, error)

Events groups the Events of the window by action, most frequent first. Reserved `email.*` actions and customer-tracked ones are both listed; machine opens and clicks are left out (ADR 0053). An Event is placed at the moment it happened, `occurred_at` and when it has none its creation time (ADR 0044), so backfilled history lands on the day it happened.

func (*Module) NewPeople

func (m *Module) NewPeople(ctx context.Context, s *ent.Scoped, w Window) (*NewPeople, error)

NewPeople reports the Contacts of the Workspace behind s created in the window.

func (*Module) OpensByHour

func (m *Module) OpensByHour(ctx context.Context, s *ent.Scoped, w Window) (*OpensByHour, error)

OpensByHour counts the human opens of the window by hour of day and day of week, both read in the Workspace time zone (ADR 0057). Machine opens (ADR 0053) are in no cell. An open happened when `occurred_at` says, falling back to the creation time (ADR 0044).

func (*Module) Overview

func (m *Module) Overview(ctx context.Context, s *ent.Scoped, w Window) (*Overview, error)

Overview computes the dashboard for the Workspace behind s over the window.

func (*Module) RetentionDays

func (m *Module) RetentionDays() int

RetentionDays is the Event retention in whole days, which a report over history states next to its figures.

func (*Module) SubscribedPeople

func (m *Module) SubscribedPeople(ctx context.Context, s *ent.Scoped, w Window) (*SubscribedPeople, error)

SubscribedPeople computes the report for the Workspace behind s over the window.

func (*Module) WithClock

func (m *Module) WithClock(now func() time.Time) *Module

WithClock returns the module reading now from the given clock.

func (*Module) WithRetention

func (m *Module) WithRetention(d time.Duration) *Module

WithRetention returns the module that reports d as the Event retention (config.EventsRetention): the age past which Events are deleted, 0 when they are kept forever.

type NewPeople

type NewPeople struct {
	// Total is every Contact created in the window.
	Total  int
	Series []NewPeoplePoint
}

NewPeople is the New people report: the Contacts created in the window, per Report day and by Contact source.

type NewPeoplePoint

type NewPeoplePoint struct {
	Date                          string
	Manual, API, Tracker, Unknown int
}

NewPeoplePoint is one Report day of the New people report, zero-filled across the window. Unknown counts the Contacts that predate the Contact source.

type OpensByHour

type OpensByHour struct {
	Cells []HourCell
	Total int
}

OpensByHour is the Opens by hour report: a cell for every weekday and hour, empty ones zero, ordered Monday 00:00 first.

type Overview

type Overview struct {
	Contacts    Contacts
	Email       Email
	Automations Automations
	Series      []Point
}

Overview is everything the dashboard shows for one Workspace and window.

type OwnerClicks

type OwnerClicks struct {
	Kind   OwnerKind
	ID     int64
	Name   string
	Clicks int
}

OwnerClicks is how often a link was clicked in the emails of one Broadcast or Automation.

type OwnerKind

type OwnerKind = linkclicks.OwnerKind

OwnerKind is what carried a clicked link, so the page can link to that report.

type Point

type Point struct {
	Date                  string
	Sent, Opened, Clicked int
}

Point is one Report day of the send cohort.

type SubscribedPeople

type SubscribedPeople struct {
	// Current is the Contacts that are not globally opted out, read from current state.
	Current int
	Series  []SubscribedPoint
}

SubscribedPeople is the Subscribed people report: the flow of subscriptions per Report day and the number of subscribed people now. There is no reconstructed running total, so the series never disagrees with Current after Contacts are deleted.

type SubscribedPoint

type SubscribedPoint struct {
	Date                          string
	Subscribed, Unsubscribed, Net int
}

SubscribedPoint is one Report day: people who subscribed (marketing.confirmed Events), people who unsubscribed (email.unsubscribed Events) and their difference.

type Window

type Window int

Window is the selectable trailing window in Report days, today included.

const (
	Window7Days  Window = 7
	Window30Days Window = 30
	Window90Days Window = 90
)

Jump to

Keyboard shortcuts

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