splitter

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package splitter provides session splitting conditions.

Package splitter provides session splitting functionality.

Index

Constants

This section is empty.

Variables

AllCauses is a list of all possible split causes, usable for documentation.

Functions

This section is empty.

Types

type Condition

type Condition interface {
	ShouldSplit(ctx *Context, current *schema.Event) (SplitCause, bool)
}

Condition determines if a session should be split at a given event.

func NewMaxXEventsCondition

func NewMaxXEventsCondition(maxXEvents int) Condition

NewMaxXEventsCondition creates a new split condition that splits the session when the number of events exceeds the maximum number of events.

func NewTimeSinceFirstEventCondition

func NewTimeSinceFirstEventCondition(timeSinceFirstEvent time.Duration) Condition

NewTimeSinceFirstEventCondition creates a new split condition that splits the session when the time since the first event exceeds the maximum time.

func NewUTMCampaignCondition

func NewUTMCampaignCondition() Condition

NewUTMCampaignCondition creates a new split condition that splits the session when the UTM campaign value changes.

func NewUserIDCondition

func NewUserIDCondition() Condition

NewUserIDCondition creates a new split condition that splits the session when the user id value changes.

type Context

type Context struct {
	// EventCount is the number of events processed so far in the current session.
	EventCount int
	// FirstEvent is the timestamp of the first event in the current session.
	FirstEvent *schema.Event
	// ColumnValues stores the last seen value for each column name.
	// Conditions can use this to track value changes without re-scanning all events.
	ColumnValues map[string]any
}

Context holds state accumulated while processing events. Conditions can read and update this context to maintain state efficiently.

func NewSplitContext

func NewSplitContext() *Context

NewSplitContext creates a new context for session splitting.

type Registry

type Registry interface {
	Splitter(propertyID string) (SessionModifier, error)
}

Registry provides session splitters for properties.

func NewFromPropertySettingsRegistry

func NewFromPropertySettingsRegistry(psr properties.SettingsRegistry) Registry

NewFromPropertySettingsRegistry creates a registry that builds splitters from property settings.

func NewStaticRegistry

func NewStaticRegistry(splitter SessionModifier) Registry

NewStaticRegistry always returns the same splitter.

type SessionModifier added in v0.17.0

type SessionModifier interface {
	Split(*schema.Session) ([]*schema.Session, error)
}

SessionModifier splits a session into multiple sessions based on conditions.

func New

func New(conditions ...Condition) SessionModifier

New creates a new session splitter with the given conditions.

func NewNoop

func NewNoop() SessionModifier

NewNoop creates a new session splitter that does not split the session.

type SplitCause

type SplitCause string

SplitCause indicates the reason why a session was split.

const (
	// SplitCauseNone indicates no split occurred.
	SplitCauseNone SplitCause = ""
	// SplitCauseUtmCampaignChange indicates split due to UTM campaign change.
	SplitCauseUtmCampaignChange SplitCause = "utm_campaign_changed"
	// SplitCauseUserIDChange indicates split due to user ID change.
	SplitCauseUserIDChange SplitCause = "user_id_changed"
	// SplitCauseMaxXEvents indicates split due to maximum number of events.
	SplitCauseMaxXEvents SplitCause = "max_events_reached"
	// SplitCauseTimeSinceFirstEvent indicates split due to time since first event.
	SplitCauseTimeSinceFirstEvent SplitCause = "max_time_since_first_event_reached"
)

Jump to

Keyboard shortcuts

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