Documentation
¶
Overview ¶
Package holdout is the holdout group (M63 G-33): while a period is open, a random share of the workspace's contacts gets no campaigns and/or no automation messages, and a nightly measurement compares what they did with everyone else.
Who is held out is decided by one SQL function, rc_holdout_bucket(contact, seed) < basis_points (migration 03540): the sending engine, Send Readiness, automations, text, push and WhatsApp campaigns, the segment field and the measurement all ask it, so they never disagree. Raising the share keeps everyone already held out; "Start over" draws a new seed. Transactional and system mail are never held out.
Index ¶
- Constants
- Variables
- func End(p store.HoldoutPeriod, now time.Time) time.Time
- func Ended(p store.HoldoutPeriod) bool
- func FromAutomations(ctx context.Context, q *store.Queries, workspaceID, contactID uuid.UUID) (bool, error)
- func HeldFromCampaigns(ctx context.Context, q *store.Queries, workspaceID uuid.UUID, ...) (map[uuid.UUID]bool, error)
- func Open(ctx context.Context, q *store.Queries, workspaceID uuid.UUID) (*store.HoldoutPeriod, error)
- func Percent(bp int32) float64
- func Register(h huma.API, s *Service)
- type Group
- type HoldoutGroupResult
- type HoldoutMetric
- type HoldoutOtherCurrency
- type HoldoutPeriodItem
- type HoldoutResults
- type Inserter
- type MeasureArgs
- type MeasureWorker
- type Measured
- type Metric
- type OtherCurrency
- type ScheduleArgs
- type ScheduleWorker
- type Service
- func (s *Service) Measure(ctx context.Context, workspaceID uuid.UUID) error
- func (s *Service) RequestMeasure(ctx context.Context, ws *store.Workspace) (HoldoutResults, error)
- func (s *Service) Results(ctx context.Context, ws *store.Workspace, periodID *uuid.UUID, span string) (HoldoutResults, error)
- func (s *Service) ScheduleMeasures(ctx context.Context) (int, error)
- type Share
Constants ¶
const ( MinBasisPoints = 10 // 0.1% MaxBasisPoints = 2000 // 20% )
Limits of the share, in basis points (hundredths of a percent).
const ( SpanPeriod = "period" Span30 = "30d" Span90 = "90d" )
Spans of a measurement.
const ( // MinHoldout is how many contacts the holdout group needs before its // results mean anything. MinHoldout = 1000 // TooEarly is how long a period must have run. TooEarly = 14 * 24 * time.Hour // Confidence is what a difference needs to count (two-sided). Confidence = 0.95 // MeasureEvery is how often a person may ask for a recompute. MeasureEvery = 10 * time.Minute )
Thresholds of the verdict.
const ( MetricConversion = "conversion_rate" MetricRevenue = "revenue_per_contact" MetricOrders = "orders_per_contact" // MetricVisitors is the share of a group seen on a tracked site (M62), // only when the workspace tracks one. MetricVisitors = "site_visitors" )
Metric keys, in the order the results show them. A metric is computed from the stored sums when the results are read.
const ( VerdictPending = "pending" // not measured yet VerdictTooFew = "too_few" // fewer than MinHoldout in the holdout group VerdictTooEarly = "too_early" // the open period is younger than TooEarly VerdictAdded = "added" // marketing brought more, significantly VerdictLost = "lost" // the holdout group brought more, significantly VerdictNoDifference = "no_difference" // not significant )
Verdicts of a span, on revenue per contact.
const MeasureHour = 4
MeasureHour is the workspace's local hour of the nightly measurement.
Variables ¶
var Spans = []string{SpanPeriod, Span30, Span90}
Spans lists every span.
Functions ¶
func FromAutomations ¶
func FromAutomations(ctx context.Context, q *store.Queries, workspaceID, contactID uuid.UUID) (bool, error)
FromAutomations reports whether the open period holds the contact out of automation messages.
func HeldFromCampaigns ¶
func HeldFromCampaigns(ctx context.Context, q *store.Queries, workspaceID uuid.UUID, contacts []uuid.UUID) (map[uuid.UUID]bool, error)
HeldFromCampaigns lists which of the contacts the open period holds out of campaigns (text, push and WhatsApp campaigns skip them). Nil when nobody is.
func Open ¶
func Open(ctx context.Context, q *store.Queries, workspaceID uuid.UUID) (*store.HoldoutPeriod, error)
Open is the workspace's open period; nil when the holdout group is off.
Types ¶
type Group ¶
type Group struct {
Contacts int64 `json:"contacts"`
Converters int64 `json:"converters"`
// Visitors were seen on a tracked site (Measured.Tracking).
Visitors int64 `json:"visitors"`
Orders float64 `json:"orders"`
OrdersSq float64 `json:"orders_sq"`
Revenue float64 `json:"revenue"`
RevenueSq float64 `json:"revenue_sq"`
}
Group is what one group did in a span: sums over its contacts, with the sums of squares that their variances need. Revenue is in minor units of Measured.Currency.
type HoldoutGroupResult ¶
type HoldoutGroupResult struct {
Contacts int64 `json:"contacts"`
Converters int64 `json:"converters"`
// Visitors were seen on a tracked site (HoldoutResults.Tracking).
Visitors int64 `json:"visitors"`
Orders int64 `json:"orders"`
RevenueCents int64 `json:"revenueCents"`
}
HoldoutGroupResult is what one group did: its contacts, how many of them converted, their orders and revenue (minor units of the main currency).
type HoldoutMetric ¶
type HoldoutMetric struct {
Key string `json:"key" enum:"conversion_rate,revenue_per_contact,orders_per_contact,site_visitors"`
Holdout float64 `json:"holdout"`
Marketing float64 `json:"marketing"`
Lift float64 `json:"lift"`
Confidence float64 `json:"confidence"`
Tested bool `json:"tested"`
Significant bool `json:"significant"`
}
HoldoutMetric compares the groups on one measure. Values are in the metric's unit: conversion_rate and site_visitors in percent, revenue_per_contact in minor units of the main currency, orders_per_contact in orders. site_visitors is there only when the workspace tracks a site (Website tracking). Lift is the marketing group's over the holdout group's, in percent; Confidence is 1 − p (two-sided); Tested is false when there was nothing to test.
type HoldoutOtherCurrency ¶
type HoldoutOtherCurrency struct {
Currency string `json:"currency"`
HoldoutCents int64 `json:"holdoutCents"`
MarketingCents int64 `json:"marketingCents"`
}
HoldoutOtherCurrency is what was recorded in another currency: named apart, never converted.
type HoldoutPeriodItem ¶
type HoldoutPeriodItem struct {
ID string `json:"id"`
StartedAt time.Time `json:"startedAt"`
EndedAt *time.Time `json:"endedAt,omitempty"`
BasisPoints int `json:"basisPoints"`
Percent float64 `json:"percent"`
Campaigns bool `json:"campaigns"`
Automations bool `json:"automations"`
Open bool `json:"open"`
}
HoldoutPeriodItem is one period of the holdout group: its share, scope and when it ran.
type HoldoutResults ¶
type HoldoutResults struct {
// Periods are the open period and the last closed one, newest first;
// empty when the workspace never had a holdout group.
Periods []HoldoutPeriodItem `json:"periods"`
Period *HoldoutPeriodItem `json:"period,omitempty"`
Window string `json:"window" enum:"period,30d,90d"`
// From and To are the span's dates (omitted until measured).
From *time.Time `json:"from,omitempty"`
To *time.Time `json:"to,omitempty"`
// Verdict: none (no holdout group ever), pending (not measured yet),
// too_few, too_early, added, lost or no_difference.
Verdict string `json:"verdict" enum:"none,pending,too_few,too_early,added,lost,no_difference"`
ComputedAt *time.Time `json:"computedAt,omitempty"`
// Computing is true while a requested recompute hasn't finished;
// NextMeasureAt is when Recompute is allowed again.
Computing bool `json:"computing"`
NextMeasureAt *time.Time `json:"nextMeasureAt,omitempty"`
Holdout HoldoutGroupResult `json:"holdout"`
Marketing HoldoutGroupResult `json:"marketing"`
Metrics []HoldoutMetric `json:"metrics"`
Currency string `json:"currency"`
OtherCurrencies []HoldoutOtherCurrency `json:"otherCurrencies"`
// CampaignsIncluded counts the email campaigns of the span that went
// to the holdout group too.
CampaignsIncluded int64 `json:"campaignsIncluded"`
MinHoldout int64 `json:"minHoldout"`
// Tracking: the workspace tracked a site when this span was measured,
// so the groups count site visitors and the metrics include them.
Tracking bool `json:"tracking"`
}
HoldoutResults is Audience › Holdout: the period and span shown, its verdict on revenue per contact, the groups, the metrics, and whether a recompute is running or allowed.
type Inserter ¶
type Inserter interface {
InsertTx(ctx context.Context, tx pgx.Tx, args river.JobArgs, opts *river.InsertOpts) (*rivertype.JobInsertResult, error)
}
Inserter queues jobs in a transaction (the River client).
type MeasureArgs ¶
MeasureArgs measures one workspace's holdout group (holdout.measure).
func (MeasureArgs) InsertOpts ¶
func (MeasureArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts: one per workspace in any 10 minutes.
type MeasureWorker ¶
type MeasureWorker struct {
river.WorkerDefaults[MeasureArgs]
S *Service
}
MeasureWorker runs MeasureArgs.
func (*MeasureWorker) Timeout ¶
func (w *MeasureWorker) Timeout(*river.Job[MeasureArgs]) time.Duration
Timeout implements river.Worker: a large workspace takes a while.
func (*MeasureWorker) Work ¶
func (w *MeasureWorker) Work(ctx context.Context, job *river.Job[MeasureArgs]) error
Work implements river.Worker.
type Measured ¶
type Measured struct {
From time.Time `json:"from"`
To time.Time `json:"to"`
Currency string `json:"currency"`
Holdout Group `json:"holdout"`
Marketing Group `json:"marketing"`
OtherCurrencies []OtherCurrency `json:"other_currencies"`
CampaignsIncluded int64 `json:"campaigns_included"`
// Tracking: the workspace tracked a site (M62) when this was measured,
// so the groups count site visitors.
Tracking bool `json:"tracking,omitempty"`
}
Measured is holdout_results.data: one span of one period.
type Metric ¶
type Metric struct {
Key string
Holdout float64
Marketing float64
Lift float64
Confidence float64
Tested bool
Significant bool
}
Metric compares the two groups on one measure: the holdout group's value and the marketing group's (conversion rate in percent, revenue per contact in minor units, orders per contact), the marketing group's lift over the holdout's in percent, and the test's confidence (1 − p, two-sided). Tested is false when the test can't run or the holdout's value is 0 (no lift to express).
type OtherCurrency ¶
type OtherCurrency struct {
Currency string `json:"currency"`
HoldoutCents int64 `json:"holdout_cents"`
MarketingCents int64 `json:"marketing_cents"`
}
OtherCurrency is what a span recorded in a currency other than the main one, per group: named apart, never converted or added.
type ScheduleArgs ¶
type ScheduleArgs struct{}
ScheduleArgs is the hourly tick that queues the nightly measurements (holdout.schedule).
func (ScheduleArgs) InsertOpts ¶
func (ScheduleArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts.
type ScheduleWorker ¶
type ScheduleWorker struct {
river.WorkerDefaults[ScheduleArgs]
S *Service
}
ScheduleWorker runs ScheduleArgs.
func (*ScheduleWorker) Work ¶
func (w *ScheduleWorker) Work(ctx context.Context, _ *river.Job[ScheduleArgs]) error
Work implements river.Worker.
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Jobs Inserter
Log *slog.Logger
Now func() time.Time
}
Service measures holdout periods and reads the results.
func (*Service) Measure ¶
Measure computes and stores the results of the workspace's open period and its last closed one, every span.
func (*Service) RequestMeasure ¶
RequestMeasure queues a recompute of the workspace's results, at most once every MeasureEvery.
type Share ¶
type Share struct {
}
Share is who an audience query holds out: contacts whose bucket for Seed is under BasisPoints. The zero Share holds out nobody.
func ForCampaigns ¶
ForCampaigns is the share the open period holds out of campaigns; the zero Share when there is none or it holds out automations only.