analytics

package
v0.0.0-...-2bc12df Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package analytics provides tools for sending over Wash events and screenviews to Google Analytics

Index

Constants

View Source
const FlushDuration = 250 * time.Millisecond

FlushDuration represents the amount of time of a typical Client#Flush operation. Users of the analytics package should use this value when they need to flush outstanding analytics hits prior to exiting their application.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Screenview(name string, params Params) error
	Event(category string, action string, params Params) error
	Flush()
}

Client represents a Google Analytics client. Hits are submitted to GA in batches of 20 to avoid overloading the network.

Screenview queues a screenview hit, while Event queues an event hit. Params represents additional measurement protocol parameters to pass into Client#Screenview or Client#Event. These will typically be custom dimension values. The currently supported custom dimensions are "Plugin" and "Entry Type". Note that Event hits can also specify the event's (optional) label and value via the "Label" and "Value" keys in params.

NOTE: See https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters for more details about the measurement protocol.

NOTE: Screenview and Event will only return an error for invalid input. If you always expect valid input, then feel free to ignore the error or to panic on it.

func GetClient

func GetClient(ctx context.Context) Client

GetClient retrieves the analytics client from the provided context. If the context does not contain an analytics client, then this will return a silenced noopClient. The latter's useful for testing.

func NewClient

func NewClient(config Config) Client

NewClient returns a new Google Analytics client for submitting Wash analytics.

type Config

type Config struct {
	Disabled bool      `yaml:"disabled"`
	UserID   uuid.UUID `yaml:"user-id"`
}

Config represents Wash's Google Analytics Config

func GetConfig

func GetConfig() (Config, error)

GetConfig returns Wash's analytics config, which is located at $HOME/.puppetlabs/wash/analytics.yaml.

type KeyType

type KeyType int

KeyType is used to type keys for looking up context values.

const ClientKey KeyType = iota

ClientKey is used to identify an analytics client in a context.

type Params

type Params map[string]string

Params represents additional measurement protocol parameters to pass into Client#Screenview or Client#Event.

func (Params) String

func (p Params) String() string

Jump to

Keyboard shortcuts

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