analytics

package
v0.0.0-...-e8b1e36 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Onboarding

func Onboarding()

func TrackCommand

func TrackCommand(cmdName string) error

TrackCommand is the main entrypoint for analytics. This does all the checking for no tracking, the onboarding, and the actual tracking itself.

This should be called after your command has finished, because it will sometimes flush data over the network.

Any errors are assumed to be non-fatal and just sent to logs.

Types

type Client

type Client struct {
	*Config
	// contains filtered or unexported fields
}

Client provides a thin layer over Segment's client for tracking CLI metrics.

Events are buffered on disk to improve user experience, only periodically flushing to the Segemnt API.

You should call Flush() when desired in order to flush to Segment. You may choose to do this after a certain number of events (see Size()) have been buffered, or after a given duration (see LastFlush()).

Based on https://github.com/tj/go-cli-analytics

func NewClient

func NewClient(config *Config) (*Client, error)

func (*Client) Close

func (a *Client) Close() error

Close the underlying file descriptor(s).

func (*Client) ConditionalFlush

func (a *Client) ConditionalFlush(aboveSize int, aboveDuration time.Duration) error

ConditionalFlush flushes if event count is above `aboveSize`, or age is `aboveDuration`, otherwise Close() is called and the underlying file(s) are closed.

func (*Client) Events

func (a *Client) Events() (v []*Event, err error)

Events reads the events from disk.

func (*Client) Flush

func (a *Client) Flush() error

Flush the events to Segment, removing them from disk. FIXME (bfirsh): two clients could potentially flush at the same time. Maybe this needs a lock, or something.

func (*Client) LastFlush

func (a *Client) LastFlush() (time.Time, error)

LastFlush returns the last flush time.

func (*Client) LastFlushDuration

func (a *Client) LastFlushDuration() (time.Duration, error)

LastFlushDuration returns the last flush time delta.

func (*Client) Size

func (a *Client) Size() (int, error)

Size returns the number of events.

func (*Client) Touch

func (a *Client) Touch() error

Touch ~/<dir>/last_flush.

func (*Client) Track

func (a *Client) Track(name string, props map[string]interface{}) error

Track event `name` with optional `props`.

type Config

type Config struct {
	SegmentKey  string
	AnonymousID string
	Dir         string // Dir for storing state
}

Config configures the analytics client

type Event

type Event struct {
	Event      string                 `json:"event"`
	Properties map[string]interface{} `json:"properties"`
	Timestamp  time.Time              `json:"timestamp"`
}

Event used for repository on disk.

Jump to

Keyboard shortcuts

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