sessioncolumns

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sessioncolumns provides column implementations for session data tracking.

Package sessioncolumns provides column implementations for session data tracking.

Index

Constants

This section is empty.

Variables

View Source
var DurationColumn = columns.NewSimpleSessionColumn(
	columns.CoreInterfaces.SessionDuration.ID,
	columns.CoreInterfaces.SessionDuration.Field,
	func(session *schema.Session) (any, error) {
		lastEventTime, ok := session.Values[columns.CoreInterfaces.SessionLastEventTime.Field.Name]
		if !ok {
			return nil, columns.NewBrokenSessionError("session last event time not found")
		}
		firstEventTime, ok := session.Values[columns.CoreInterfaces.SessionFirstEventTime.Field.Name]
		if !ok {
			return nil, columns.NewBrokenSessionError("session first event time not found")
		}
		lastEventTimeInt, ok := lastEventTime.(int64)
		if !ok {
			return nil, columns.NewBrokenSessionError("session last event time is not an int64")
		}
		firstEventTimeInt, ok := firstEventTime.(int64)
		if !ok {
			return nil, columns.NewBrokenSessionError("session first event time is not an int64")
		}
		if lastEventTimeInt < firstEventTimeInt {
			return nil, columns.NewBrokenSessionError("session last event time is earlier than session first event time")
		}
		return lastEventTimeInt - firstEventTimeInt, nil
	}, columns.WithSessionColumnDependsOn(
		schema.DependsOnEntry{
			Interface:        columns.CoreInterfaces.SessionLastEventTime.ID,
			GreaterOrEqualTo: "1.0.0",
		}, schema.DependsOnEntry{
			Interface:        columns.CoreInterfaces.SessionFirstEventTime.ID,
			GreaterOrEqualTo: "1.0.0",
		}),
	columns.WithSessionColumnDocs(
		"Session Duration",
		"The duration of the session in seconds, calculated as the difference between the last event time and the first event time. Zero for single-event sessions.",
	),
)

DurationColumn is the column for the duration of a session

View Source
var FirstEventTimeColumn = columns.NewSimpleSessionColumn(
	columns.CoreInterfaces.SessionFirstEventTime.ID,
	columns.CoreInterfaces.SessionFirstEventTime.Field,
	func(session *schema.Session) (any, error) {
		if len(session.Events) == 0 {
			return nil, columns.NewBrokenSessionError("session has no events")
		}
		return session.Events[0].BoundHit.ServerReceivedTime.Unix(), nil
	},
	columns.WithSessionColumnDocs(
		"Session First Event Time",
		"The timestamp of the first event in the session. Marks the beginning of the user's session and is used as the baseline for calculating session duration.",
	),
)

FirstEventTimeColumn is the column for the first event time of a session

View Source
var LastEventTimeColumn = columns.NewSimpleSessionColumn(
	columns.CoreInterfaces.SessionLastEventTime.ID,
	columns.CoreInterfaces.SessionLastEventTime.Field,
	func(session *schema.Session) (any, error) {
		if len(session.Events) == 0 {
			return nil, columns.NewBrokenSessionError("session has no events")
		}
		return session.Events[len(session.Events)-1].BoundHit.ServerReceivedTime.Unix(), nil
	},
	columns.WithSessionColumnDocs(
		"Session Last Event Time",
		"The timestamp of the last event in the session. Marks the end of the user's session and is used along with first_event_time to calculate session duration.",
	),
)

LastEventTimeColumn is the column for the last event time of a session

View Source
var ReferrerColumn = columns.NewSimpleSessionColumn(
	columns.CoreInterfaces.SessionReferrer.ID,
	columns.CoreInterfaces.SessionReferrer.Field,
	func(session *schema.Session) (any, error) {
		if len(session.Events) == 0 {
			return nil, nil
		}
		firstEventReferrer, ok := session.Events[0].Values[columns.CoreInterfaces.EventPageReferrer.Field.Name]
		if !ok {
			return nil, nil
		}
		return firstEventReferrer, nil
	},
	columns.WithSessionColumnDocs(
		"Session Referrer",
		"The referrer of the session. Collected from the first event in the session.",
	),
	columns.WithSessionColumnDependsOn(
		schema.DependsOnEntry{
			Interface:        columns.CoreInterfaces.EventPageReferrer.ID,
			GreaterOrEqualTo: "1.0.0",
		},
	),
)

ReferrerColumn is the column for the referrer of a whole session

View Source
var SessionIDColumn = columns.NewSimpleSessionColumn(
	columns.CoreInterfaces.SessionID.ID,
	columns.CoreInterfaces.SessionID.Field,
	func(session *schema.Session) (any, error) {
		if len(session.Events) == 0 {
			return nil, fmt.Errorf("session has no events")
		}
		firstEventID, ok := session.Events[0].Values[columns.CoreInterfaces.EventID.Field.Name]
		if !ok {
			return nil, errors.New("first event doesn't have ID")
		}
		return firstEventID, nil
	},
	columns.WithSessionColumnDependsOn(
		schema.DependsOnEntry{
			Interface:        columns.CoreInterfaces.EventID.ID,
			GreaterOrEqualTo: "1.0.0",
		},
	),
	columns.WithSessionColumnDocs(
		"Session ID",
		"A unique identifier for the session, derived from the first event's ID in the session, used to group all events that belong to the same user session.",
	),
)

SessionIDColumn is the column for the session ID

View Source
var SplitCauseColumn = columns.NewSimpleSessionColumn(
	columns.CoreInterfaces.SessionSplitCause.ID,
	columns.CoreInterfaces.SessionSplitCause.Field,
	func(session *schema.Session) (any, error) {
		if len(session.Events) == 0 {
			return nil, nil
		}
		v, ok := session.Events[0].Metadata["session_split_cause"]
		if !ok {
			return nil, nil
		}
		splitCause, ok := v.(splitter.SplitCause)
		if !ok {
			logrus.Warnf("session split cause is not a splitter.SplitCause: %v", v)
			return nil, nil
		}
		return string(splitCause), nil
	},
	columns.WithSessionColumnDocs(
		"Session Split Cause",
		fmt.Sprintf("The cause of the split of the session. If the session was not split, this will be null. Possible values: null, %s.", strings.Join(func() []string {
			values := make([]string, len(splitter.AllCauses))
			for i, cause := range splitter.AllCauses {
				values[i] = string(cause)
			}
			return values
		}(), ", ")),
	),
)

SplitCauseColumn is the column for the split cause of a session

View Source
var TotalEventsColumn = columns.NewSimpleSessionColumn(
	columns.CoreInterfaces.SessionTotalEvents.ID,
	columns.CoreInterfaces.SessionTotalEvents.Field,
	func(session *schema.Session) (any, error) {
		return len(session.Events), nil
	},
	columns.WithSessionColumnDocs(
		"Session Total Events",
		"The total number of events that occurred during this session. Includes all event types (page views, clicks, custom events, etc.).",
	),
)

TotalEventsColumn is the column for the total events of a session

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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