analytics

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 6 Imported by: 5

README

analytics

Analytics abstraction layer - log uniformly to Google Analytics, PostHog, etc.

Documentation

Index

Constants

View Source
const ErrorEvent = "error"

Variables

This section is empty.

Functions

func AddSender

func AddSender(sender Sender)

func QueueMessage

func QueueMessage(ctx context.Context, msg Message)

Types

type ErrorMessage added in v0.0.4

type ErrorMessage interface {
	Message
	ErrorText() string
}

func NewErrorMessage added in v0.0.4

func NewErrorMessage(err error) ErrorMessage

type Event

type Event interface {
	Message

	Action() string
	SetAction(string) Event

	Label() string
	SetLabel(string) Event

	Value() uint
	SetValue(uint) Event

	Title() string
	SetTitle(string) Event
}

func NewEvent

func NewEvent(name, category, action string) Event

type Message

type Message interface {
	Event() string
	User() UserContext
	SetUserContext(user UserContext)
	Properties() Properties
	Validate() error
	GetApiClientID() string

	// Category retrieves the category of the message.
	Category() string
	// SetCategory sets the category value for the message.
	SetCategory(category string)
}

type Pageview

type Pageview interface {
	Message
	Host() string
	Path() string
	Title() string
	SetTitle(title string) Pageview
	URL() string
	SetURL(url string) Pageview
	SetUserAgent(userAgent string) Pageview
}

func NewPageview

func NewPageview(host, path string) Pageview

type Product

type Product struct {
	ID    string  `json:"id,omitempty"`
	SKU   string  `json:"sky,omitempty"`
	Name  string  `json:"name,omitempty"`
	Price float64 `json:"price"`
}

Product represents products in the E-commerce API.

type Properties

type Properties map[string]any

Properties are used to represent properties in messages that support it. It is a free-form object, so the application can set any value it sees fit, but a few helper methods are defined to make it easier to instantiate properties with common fields. Here's a quick example of how this type is meant to be used:

analytics.page{
	UserId: "0123456789",
	Properties: analytics.NewProperties()
		.SetRevenue(10.0)
		.SetCurrency("USD"),
}

func NewProperties

func NewProperties() Properties

func (Properties) Set

func (p Properties) Set(name string, value interface{}) Properties

func (Properties) SetCategory

func (p Properties) SetCategory(category string) Properties

func (Properties) SetCoupon

func (p Properties) SetCoupon(coupon string) Properties

func (Properties) SetCurrency

func (p Properties) SetCurrency(currency string) Properties

func (Properties) SetDiscount

func (p Properties) SetDiscount(discount float64) Properties

func (Properties) SetName

func (p Properties) SetName(name string) Properties

func (Properties) SetOrderId

func (p Properties) SetOrderId(id string) Properties

func (Properties) SetPath

func (p Properties) SetPath(path string) Properties

func (Properties) SetPrice

func (p Properties) SetPrice(price float64) Properties

func (Properties) SetProductId

func (p Properties) SetProductId(id string) Properties

func (Properties) SetProducts

func (p Properties) SetProducts(products ...Product) Properties

func (Properties) SetReferrer

func (p Properties) SetReferrer(referrer string) Properties

func (Properties) SetRepeat

func (p Properties) SetRepeat(repeat bool) Properties

func (Properties) SetRevenue

func (p Properties) SetRevenue(revenue float64) Properties

func (Properties) SetSKU

func (p Properties) SetSKU(sku string) Properties

func (Properties) SetShipping

func (p Properties) SetShipping(shipping float64) Properties

func (Properties) SetSubtotal

func (p Properties) SetSubtotal(subtotal float64) Properties

func (Properties) SetTax

func (p Properties) SetTax(tax float64) Properties

func (Properties) SetTitle

func (p Properties) SetTitle(title string) Properties

func (Properties) SetTotal

func (p Properties) SetTotal(total float64) Properties

func (Properties) SetURL

func (p Properties) SetURL(url string) Properties

func (Properties) SetValue

func (p Properties) SetValue(value float64) Properties

type Sender

type Sender interface {
	QueueMessage(ctx context.Context, message Message)
}

type Timing

type Timing interface {
	Message
	Duration() time.Duration
}

func NewTiming added in v0.0.2

func NewTiming(event string, duration time.Duration) Timing

type UserContext

type UserContext interface {
	GetUserID() string

	Validate() error

	GetUserLanguage() string
	SetUserLanguage(language string) UserContext

	GetUserAgent() string
	SetUserAgent(userAgent string) UserContext

	QueueMessage(ctx context.Context, msg Message)
}

func NewUserContext

func NewUserContext(userID string) UserContext

Jump to

Keyboard shortcuts

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