groups

package
v0.50.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package groups computes account-level (B2B) analytics — aggregate by a group property (company, account_id, team) instead of by user. Answers "which accounts are most active", "how many accounts", "account engagement" — the questions other tools gate behind expensive plans. Deterministic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveWithin added in v0.30.0

func ActiveWithin(regrouped []event.Event, from, to time.Time) int

ActiveWithin counts accounts with any activity in the window — the B2B health number that a user count cannot express, because one champion logging in daily and a fifty-seat rollout look identical at user grain.

Types

type Grain added in v0.30.0

type Grain struct {
	Property string `json:"property"`
	// Groups is how many distinct accounts the re-keyed slice covers.
	Groups int `json:"groups"`
	// Events kept and dropped. Dropped events belong to nobody: their user never carried the group
	// property on any event, so there is no account to attribute them to. Reporting an
	// account-level funnel over a slice that quietly omits a third of the traffic would be exactly
	// the truncated-denominator lie this codebase has spent its history removing, so the count
	// travels with the result and every surface prints it.
	Kept    int `json:"events_kept"`
	Dropped int `json:"events_dropped"`
	// Unattributed is how many distinct USERS had no account at all — the number that says whether
	// the group property is instrumented properly or only on a corner of the product.
	Unattributed int `json:"users_unattributed"`
	// Note states the coverage in words when it is poor enough to change how the report reads.
	Note string `json:"note,omitempty"`
}

Grain is the result of re-keying, and the honesty half of the feature.

func Regroup added in v0.30.0

func Regroup(evs []event.Event, property string) ([]event.Event, Grain)

Regroup re-keys events so the unit of analysis is the account.

First-touch stamping runs first, and it is not optional. A group property is set once — on signup, or on an identify — and is absent from the pageviews and clicks that follow. Re-keying on the raw property would keep one event per user and drop the rest, so every account-level funnel would collapse to a single step. StampFirstTouch carries the account across all of a user's events, which is the same rule the segmented funnel already uses; using a different one here would make "conversion by company" and "the company funnel" two different reports.

type Group

type Group struct {
	Value    string    `json:"value"`
	Events   int       `json:"events"`
	Users    int       `json:"users"`
	LastSeen time.Time `json:"last_seen"`
}

Group is one account: its activity, distinct users, and recency.

type Result

type Result struct {
	Property        string  `json:"property"`
	TotalGroups     int     `json:"total_groups"`
	ActiveGroups7d  int     `json:"active_groups_7d"`
	ActiveGroups30d int     `json:"active_groups_30d"`
	Groups          []Group `json:"groups"`
}

Result is the account roll-up for a group property.

func Compute

func Compute(events []event.Event, property string, asof time.Time, limit int) Result

Compute rolls events up by the group property (events without it are skipped). Groups are returned sorted by event volume; limit<=0 means 50.

Jump to

Keyboard shortcuts

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