analytics

package
v0.19.8 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analytics

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

func New

func New(cfg *config.Config, client *api.ClientWithResponses, projectID string) *Analytics

New initializes a new Analytics instance. The config.Config parameters is required, but the others are optional. Analytics won't be sent if the api.ClientWithResponses is nil.

func (*Analytics) Identify

func (a *Analytics) Identify(options ...Option)

Identify associates the provided properties with the user for the sake of analytics. It automatically includes common properties like ProjectID. The identification is only sent if the client is initialized and analytics are enabled in the config, otherwise it is skipped.

func (*Analytics) Track

func (a *Analytics) Track(event string, options ...Option)

Track sends an analytics event with the provided event name and properties. It automatically includes common properties like ProjectID, OS, and architecture. Events are only sent if the client is initialized and analytics are enabled in the config, otherwise they are skipped.

type Option

type Option func(properties map[string]any)

Option is a function that modifies analytics event properties. Options are passed to Track and Identify methods to customize the data sent with events.

func Error

func Error(err error) Option

Error creates an Option that adds success and error information to event properties. If err is nil, sets success: true. If err is not nil, sets success: false and includes the error message.

This is commonly used at the end of command execution to track whether operations succeeded or failed, and what errors occurred.

func FlagSet

func FlagSet(flagSet *pflag.FlagSet) Option

FlagSet creates an Option that adds all flags that were explicitly set by the user (via Visit). Flag names are converted from kebab-case to snake_case (e.g., "no-wait" becomes "no_wait"). Flags in the ignore list are skipped.

This is useful for tracking which flags users actually use when running commands.

func Map

func Map(m map[string]any) Option

Map creates an Option that adds all key-value pairs from a map to the event properties. Keys specified in the ignore list are skipped.

This is useful for including arbitrary map data (like MCP tool arguments) in analytics events without manually specifying each field.

func Property

func Property(key string, value any) Option

Property creates an Option that adds a single key-value pair to the event properties. This is useful for adding custom analytics data that isn't covered by other Option functions.

Jump to

Keyboard shortcuts

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