analyticsapi

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package analyticsapi provides integration with Hanzo Analytics.

Hanzo Analytics is a privacy-focused web analytics platform (similar to Umami). This package enables Commerce to send events to Analytics for tracking page views, sessions, and custom events.

Usage:

client := analyticsapi.NewClient(&analyticsapi.Config{
    Endpoint: "https://analytics.hanzo.ai",
    WebsiteID: "website-uuid",
})

client.TrackPageView(&analyticsapi.PageViewEvent{
    URL: "https://example.com/products",
    Title: "Products",
    Referrer: "https://google.com",
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the Analytics API client.

func NewClient

func NewClient(config *Config) *Client

NewClient creates a new Analytics client.

func (*Client) Close

func (c *Client) Close() error

Close gracefully shuts down the client.

func (*Client) Flush

func (c *Client) Flush() error

Flush sends all queued events immediately.

func (*Client) Identify

func (c *Client) Identify(event *IdentifyEvent) error

Identify sends session identification data.

func (*Client) TrackCommerceEvent

func (c *Client) TrackCommerceEvent(eventName string, orderID string, total float64, properties map[string]interface{}) error

TrackCommerceEvent sends a commerce-specific event.

func (*Client) TrackEvent

func (c *Client) TrackEvent(event *CustomEvent) error

TrackEvent sends a custom event.

func (*Client) TrackPageView

func (c *Client) TrackPageView(event *PageViewEvent) error

TrackPageView sends a page view event.

type Config

type Config struct {
	// Endpoint is the Analytics API endpoint (e.g., "https://analytics.hanzo.ai")
	Endpoint string

	// WebsiteID is the website identifier
	WebsiteID string

	// BatchSize is the number of events to batch before sending (default: 50)
	BatchSize int

	// FlushInterval is how often to flush batched events (default: 10s)
	FlushInterval time.Duration

	// Timeout is the HTTP request timeout (default: 5s)
	Timeout time.Duration

	// Async enables asynchronous event sending (default: true)
	Async bool
}

Config holds Analytics client configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with sensible defaults.

type CustomEvent

type CustomEvent struct {
	Name      string                 `json:"name"`
	Data      map[string]interface{} `json:"data,omitempty"`
	URL       string                 `json:"url,omitempty"`
	SessionID string                 `json:"session_id,omitempty"`
}

CustomEvent represents a custom analytics event.

type IdentifyEvent

type IdentifyEvent struct {
	SessionID string                 `json:"session_id"`
	Data      map[string]interface{} `json:"data"`
}

IdentifyEvent represents a session identification event.

type PageViewEvent

type PageViewEvent struct {
	URL       string `json:"url"`
	Title     string `json:"title,omitempty"`
	Referrer  string `json:"referrer,omitempty"`
	Hostname  string `json:"hostname,omitempty"`
	Language  string `json:"language,omitempty"`
	Screen    string `json:"screen,omitempty"`
	SessionID string `json:"session_id,omitempty"`
}

PageViewEvent represents a page view event.

Jump to

Keyboard shortcuts

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