pirsch

package module
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 12 Imported by: 5

README

Pirsch Golang SDK

Go Reference Chat on Discord

This is the official Golang client SDK for Pirsch. For details, please check out our documentation.

Changelog

See CHANGELOG.md.

License

MIT

Documentation

Index

Constants

View Source
const (
	// ScaleDay groups results by day.
	ScaleDay = "day"

	// ScaleWeek groups results by week.
	ScaleWeek = "week"

	// ScaleMonth groups results by month.
	ScaleMonth = "month"

	// ScaleYear groups results by year.
	ScaleYear = "year"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveVisitorStats added in v1.3.1

type ActiveVisitorStats struct {
	Path     string `json:"path"`
	Title    string `json:"title"`
	Visitors int    `json:"visitors"`
}

ActiveVisitorStats is the result type for active visitor statistics.

type ActiveVisitorsData added in v1.3.1

type ActiveVisitorsData struct {
	Stats    []ActiveVisitorStats `json:"stats"`
	Visitors int                  `json:"visitors"`
}

ActiveVisitorsData contains the active visitors data.

type BaseEntity added in v1.3.1

type BaseEntity struct {
	ID      string    `json:"id"`
	DefTime time.Time `json:"def_time"`
	ModTime time.Time `json:"mod_time"`
}

BaseEntity contains the base data for all entities.

type BrowserStats added in v1.3.1

type BrowserStats struct {
	MetaStats
	Browser string `json:"browser"`
}

BrowserStats is the result type for browser statistics.

type BrowserVersionStats added in v1.6.0

type BrowserVersionStats struct {
	MetaStats
	Browser        string `json:"browser"`
	BrowserVersion string `db:"browser_version" json:"browser_version"`
}

BrowserVersionStats is the result type for browser version statistics.

type CityStats added in v1.5.0

type CityStats struct {
	MetaStats
	City string `json:"city"`
}

CityStats is the result type for city statistics.

type Client

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

Client is used to access the Pirsch API.

func NewClient

func NewClient(clientID, clientSecret string, config *ClientConfig) *Client

NewClient creates a new client for given client ID, client secret, hostname, and optional configuration. A new client ID and secret can be generated on the Pirsch dashboard. The hostname must match the hostname you configured on the Pirsch dashboard (e.g. example.com). The clientID is optional when using single access tokens.

func (*Client) ActiveVisitors added in v1.3.1

func (client *Client) ActiveVisitors(filter *Filter) (*ActiveVisitorsData, error)

ActiveVisitors returns the active visitors and what pages they're on.

func (*Client) Browser added in v1.3.1

func (client *Client) Browser(filter *Filter) ([]BrowserStats, error)

Browser returns browser statistics.

func (*Client) BrowserVersions added in v1.6.0

func (client *Client) BrowserVersions(filter *Filter) ([]BrowserVersionStats, error)

BrowserVersions returns browser version statistics.

func (*Client) City added in v1.5.0

func (client *Client) City(filter *Filter) ([]CityStats, error)

City returns city statistics.

func (*Client) ConversionGoals added in v1.3.1

func (client *Client) ConversionGoals(filter *Filter) ([]ConversionGoal, error)

ConversionGoals returns all conversion goals.

func (*Client) Country added in v1.3.1

func (client *Client) Country(filter *Filter) ([]CountryStats, error)

Country returns country statistics.

func (*Client) Domain added in v1.3.1

func (client *Client) Domain() (*Domain, error)

Domain returns the domain for this client.

func (*Client) EntryPages added in v1.5.0

func (client *Client) EntryPages(filter *Filter) ([]EntryStats, error)

EntryPages returns the entry page statistics grouped by page.

func (*Client) Event added in v1.4.0

func (client *Client) Event(name string, durationSeconds int, meta map[string]string, r *http.Request) error

Event sends an event to Pirsch for given http.Request.

func (*Client) EventMetadata added in v1.4.0

func (client *Client) EventMetadata(filter *Filter) ([]EventStats, error)

EventMetadata returns the metadata values for an event and key.

func (*Client) EventWithOptions added in v1.4.0

func (client *Client) EventWithOptions(name string, durationSeconds int, meta map[string]string, r *http.Request, options *HitOptions) error

EventWithOptions sends an event to Pirsch for given http.Request and options.

func (*Client) Events added in v1.4.0

func (client *Client) Events(filter *Filter) ([]EventStats, error)

Events returns all events.

func (*Client) ExitPages added in v1.5.0

func (client *Client) ExitPages(filter *Filter) ([]ExitStats, error)

ExitPages returns the exit page statistics grouped by page.

func (*Client) Growth added in v1.3.1

func (client *Client) Growth(filter *Filter) (*Growth, error)

Growth returns the growth rates for visitors, bounces, ...

func (*Client) Hit

func (client *Client) Hit(r *http.Request) error

Hit sends a page hit to Pirsch for given http.Request.

func (*Client) HitWithOptions added in v1.2.0

func (client *Client) HitWithOptions(r *http.Request, options *HitOptions) error

HitWithOptions sends a page hit to Pirsch for given http.Request and options.

func (*Client) Keywords added in v1.3.1

func (client *Client) Keywords(filter *Filter) ([]Keyword, error)

Keywords returns the Google keywords, rank, and CTR.

func (*Client) Languages added in v1.3.1

func (client *Client) Languages(filter *Filter) ([]LanguageStats, error)

Languages returns language statistics.

func (*Client) ListEvents added in v1.6.0

func (client *Client) ListEvents(filter *Filter) ([]EventListStats, error)

ListEvents returns a list of all events including metadata.

func (*Client) OS added in v1.3.1

func (client *Client) OS(filter *Filter) ([]OSStats, error)

OS returns operating system statistics.

func (*Client) OSVersions added in v1.6.0

func (client *Client) OSVersions(filter *Filter) ([]OSVersionStats, error)

OSVersions returns operating system version statistics.

func (*Client) Pages added in v1.3.1

func (client *Client) Pages(filter *Filter) ([]PageStats, error)

Pages returns the page statistics grouped by page.

func (*Client) Platform added in v1.3.1

func (client *Client) Platform(filter *Filter) (*PlatformStats, error)

Platform returns the platforms used by visitors.

func (*Client) Referrer added in v1.3.1

func (client *Client) Referrer(filter *Filter) ([]ReferrerStats, error)

Referrer returns referrer statistics.

func (*Client) Screen added in v1.3.1

func (client *Client) Screen(filter *Filter) ([]ScreenClassStats, error)

Screen returns the screen classes used by visitors.

func (*Client) Session added in v1.5.0

func (client *Client) Session(r *http.Request) error

Session keeps a session alive for the given http.Request.

func (*Client) SessionDuration added in v1.3.1

func (client *Client) SessionDuration(filter *Filter) ([]TimeSpentStats, error)

SessionDuration returns the session duration grouped by day.

func (*Client) SessionWithOptions added in v1.5.0

func (client *Client) SessionWithOptions(r *http.Request, options *HitOptions) error

SessionWithOptions keeps a session alive for the given http.Request and options.

func (*Client) TimeOfDay added in v1.3.1

func (client *Client) TimeOfDay(filter *Filter) ([]VisitorHourStats, error)

TimeOfDay returns the number of unique visitors grouped by time of day.

func (*Client) TimeOnPage added in v1.3.1

func (client *Client) TimeOnPage(filter *Filter) ([]TimeSpentStats, error)

TimeOnPage returns the time spent on pages.

func (*Client) TotalVisitors added in v1.5.1

func (client *Client) TotalVisitors(filter *Filter) (*TotalVisitorStats, error)

TotalVisitors returns the total visitor statistics.

func (*Client) UTMCampaign added in v1.3.1

func (client *Client) UTMCampaign(filter *Filter) ([]UTMCampaignStats, error)

UTMCampaign returnst he utm campaigns.

func (*Client) UTMContent added in v1.3.1

func (client *Client) UTMContent(filter *Filter) ([]UTMContentStats, error)

UTMContent returns the utm content.

func (*Client) UTMMedium added in v1.3.1

func (client *Client) UTMMedium(filter *Filter) ([]UTMMediumStats, error)

UTMMedium returns the utm medium.

func (*Client) UTMSource added in v1.3.1

func (client *Client) UTMSource(filter *Filter) ([]UTMSourceStats, error)

UTMSource returns the utm sources.

func (*Client) UTMTerm added in v1.3.1

func (client *Client) UTMTerm(filter *Filter) ([]UTMTermStats, error)

UTMTerm returns the utm term.

func (*Client) Visitors added in v1.3.1

func (client *Client) Visitors(filter *Filter) ([]VisitorStats, error)

Visitors returns the visitor statistics grouped by day.

type ClientConfig

type ClientConfig struct {
	// BaseURL is optional and can be used to configure a different host for the API.
	// This is usually left empty in production environments.
	BaseURL string

	// Timeout is the timeout for HTTP requests. 5 seconds by default.
	Timeout time.Duration

	// RequestRetries sets the maximum number of requests before an error is returned. 5 retries by default.
	RequestRetries int

	// Logger is an optional logger for debugging.
	Logger *log.Logger
}

ClientConfig is used to configure the Client.

type ConversionGoal added in v1.3.1

type ConversionGoal struct {
	BaseEntity

	PageGoal struct {
		DomainID      string       `json:"domain_id"`
		Name          string       `json:"name"`
		PathPattern   string       `json:"path_pattern"`
		Pattern       string       `json:"pattern"`
		VisitorGoal   null.Int64   `json:"visitor_goal"`
		CRGoal        null.Float64 `json:"cr_goal"`
		DeleteReached bool         `json:"delete_reached"`
		EmailReached  bool         `json:"email_reached"`
	} `json:"page_goal"`
	Stats struct {
		Visitors int     `json:"visitors"`
		Views    int     `json:"views"`
		CR       float64 `json:"cr"`
	} `json:"stats"`
}

ConversionGoal is a conversion goal as configured on the dashboard.

type ConversionGoalStats added in v1.3.1

type ConversionGoalStats struct {
	ConversionGoal *ConversionGoal       `json:"page_goal"` // page_goal is returned by the API, but we name it differently here
	Stats          *PageConversionsStats `json:"stats"`
}

ConversionGoalStats are the statistics for a conversion goal.

type CountryStats added in v1.3.1

type CountryStats struct {
	MetaStats
	CountryCode string `json:"country_code"`
}

CountryStats is the result type for country statistics.

type Domain added in v1.3.1

type Domain struct {
	BaseEntity

	UserID             string      `json:"user_id"`
	Hostname           string      `json:"hostname"`
	Subdomain          string      `json:"subdomain"`
	IdentificationCode string      `json:"identification_code"`
	Public             bool        `json:"public"`
	GoogleUserID       null.String `json:"google_user_id"`
	GoogleUserEmail    null.String `json:"google_user_email"`
	GSCDomain          null.String `json:"gsc_domain"`
	NewOwner           null.Int64  `json:"new_owner"`
	Timezone           null.String `json:"timezone"`
}

Domain is a domain on the dashboard.

type EntryStats added in v1.5.0

type EntryStats struct {
	Path                    string  `json:"path"`
	Title                   string  `json:"title"`
	Visitors                int     `json:"visitors"`
	Sessions                int     `json:"sessions"`
	Entries                 int     `json:"entries"`
	EntryRate               float64 `json:"entry_rate"`
	AverageTimeSpentSeconds int     `json:"average_time_spent_seconds"`
}

EntryStats is the result type for entry page statistics.

type Event added in v1.4.0

type Event struct {
	Hit
	Name            string            `json:"event_name"`
	DurationSeconds int               `json:"event_duration"`
	Metadata        map[string]string `json:"event_meta"`
}

Event represents a single data point for custom events. It's basically the same as Hit, but with some additional fields (event name, time, and meta fields).

type EventListStats added in v1.6.0

type EventListStats struct {
	Name     string            `json:"name"`
	Meta     map[string]string `json:"meta"`
	Visitors int               `json:"visitors"`
	Count    int               `json:"count"`
}

EventListStats is the result type for a custom event list.

type EventStats added in v1.4.0

type EventStats struct {
	Name                   string   `json:"name"`
	Visitors               int      `json:"visitors"`
	Views                  int      `json:"views"`
	CR                     float64  `json:"cr"`
	AverageDurationSeconds int      `json:"average_duration_seconds"`
	MetaKeys               []string `json:"meta_keys"`
	MetaValue              string   `json:"meta_value"`
}

EventStats is the result type for custom events.

type ExitStats added in v1.5.0

type ExitStats struct {
	Path     string  `json:"path"`
	Title    string  `json:"title"`
	Visitors int     `json:"visitors"`
	Sessions int     `json:"sessions"`
	Exits    int     `json:"exits"`
	ExitRate float64 `json:"exit_rate"`
}

ExitStats is the result type for exit page statistics.

type Filter added in v1.3.1

type Filter struct {
	DomainID             string    `json:"id"`
	From                 time.Time `json:"from"`
	To                   time.Time `json:"to"`
	Start                int       `json:"start,omitempty"`
	Scale                Scale     `json:"scale,omitempty"`
	Path                 string    `json:"path,omitempty"`
	Pattern              string    `json:"pattern,omitempty"`
	EntryPath            string    `json:"entry_path,omitempty"`
	ExitPath             string    `json:"exit_path,omitempty"`
	Event                string    `json:"event,omitempty"`
	EventMetaKey         string    `json:"event_meta_key,omitempty"`
	Language             string    `json:"language,omitempty"`
	Country              string    `json:"country,omitempty"`
	City                 string    `json:"city,omitempty"`
	Referrer             string    `json:"referrer,omitempty"`
	ReferrerName         string    `json:"referrer_name,omitempty"`
	OS                   string    `json:"os,omitempty"`
	Browser              string    `json:"browser,omitempty"`
	Platform             string    `json:"platform,omitempty"`
	ScreenClass          string    `json:"screen_class,omitempty"`
	ScreenWidth          string    `json:"screen_width,omitempty"`
	ScreenHeight         string    `json:"screen_height,omitempty"`
	UTMSource            string    `json:"utm_source,omitempty"`
	UTMMedium            string    `json:"utm_medium,omitempty"`
	UTMCampaign          string    `json:"utm_campaign,omitempty"`
	UTMContent           string    `json:"utm_content,omitempty"`
	UTMTerm              string    `json:"utm_term,omitempty"`
	Limit                int       `json:"limit,omitempty"`
	IncludeAvgTimeOnPage bool      `json:"include_avg_time_on_page,omitempty"`
}

Filter is used to filter statistics. DomainID, From, and To are required dates (the time is ignored).

type Growth added in v1.3.1

type Growth struct {
	VisitorsGrowth  float64 `json:"visitors_growth"`
	ViewsGrowth     float64 `json:"views_growth"`
	SessionsGrowth  float64 `json:"sessions_growth"`
	BouncesGrowth   float64 `json:"bounces_growth"`
	TimeSpentGrowth float64 `json:"time_spent_growth"`
}

Growth represents the visitors, views, sessions, bounces, and average session duration growth between two time periods.

type Hit

type Hit struct {
	Hostname       string
	URL            string `json:"url"`
	IP             string `json:"ip"`
	UserAgent      string `json:"user_agent"`
	AcceptLanguage string `json:"accept_language"`
	Title          string `json:"title"`
	Referrer       string `json:"referrer"`
	ScreenWidth    int    `json:"screen_width"`
	ScreenHeight   int    `json:"screen_height"`
}

Hit are the parameters to send a page hit to Pirsch.

type HitOptions added in v1.2.0

type HitOptions struct {
	URL            string
	IP             string
	UserAgent      string
	AcceptLanguage string
	Title          string
	Referrer       string
	ScreenWidth    int
	ScreenHeight   int
}

HitOptions optional parameters to send with the hit request.

type Keyword added in v1.3.1

type Keyword struct {
	Keys        []string `json:"keys"`
	Clicks      int      `json:"clicks"`
	Impressions int      `json:"impressions"`
	CTR         float64  `json:"ctr"`
	Position    float64  `json:"position"`
}

Keyword is the result type for keyword statistics.

type LanguageStats added in v1.3.1

type LanguageStats struct {
	MetaStats
	Language string `json:"language"`
}

LanguageStats is the result type for language statistics.

type MetaStats added in v1.3.1

type MetaStats struct {
	Visitors         int     `json:"visitors"`
	RelativeVisitors float64 `json:"relative_visitors"`
}

MetaStats is the base for meta result types (languages, countries, ...).

type OSStats added in v1.3.1

type OSStats struct {
	MetaStats
	OS string `json:"os"`
}

OSStats is the result type for operating system statistics.

type OSVersionStats added in v1.6.0

type OSVersionStats struct {
	MetaStats
	OS        string `json:"os"`
	OSVersion string `db:"os_version" json:"os_version"`
}

OSVersionStats is the result type for operating system version statistics.

type PageConversionsStats added in v1.3.1

type PageConversionsStats struct {
	Visitors int     `json:"visitors"`
	Views    int     `json:"views"`
	CR       float64 `json:"cr"`
}

PageConversionsStats is the result type for page conversions.

type PageStats added in v1.3.1

type PageStats struct {
	Path                    string  `json:"path"`
	Visitors                int     `json:"visitors"`
	Views                   int     `json:"views"`
	Sessions                int     `json:"sessions"`
	Bounces                 int     `json:"bounces"`
	RelativeVisitors        float64 `json:"relative_visitors"`
	RelativeViews           float64 `json:"relative_views"`
	BounceRate              float64 `json:"bounce_rate"`
	AverageTimeSpentSeconds int     `json:"average_time_spent_seconds"`
}

PageStats is the result type for page statistics.

type PlatformStats added in v1.3.1

type PlatformStats struct {
	PlatformDesktop         int     `json:"platform_desktop"`
	PlatformMobile          int     `json:"platform_mobile"`
	PlatformUnknown         int     `json:"platform_unknown"`
	RelativePlatformDesktop float64 `json:"relative_platform_desktop"`
	RelativePlatformMobile  float64 `json:"relative_platform_mobile"`
	RelativePlatformUnknown float64 `json:"relative_platform_unknown"`
}

PlatformStats is the result type for platform statistics.

type ReferrerStats added in v1.3.1

type ReferrerStats struct {
	Referrer         string  `json:"referrer"`
	ReferrerName     string  `json:"referrer_name"`
	ReferrerIcon     string  `json:"referrer_icon"`
	Visitors         int     `json:"visitors"`
	Sessions         int     `json:"sessions"`
	RelativeVisitors float64 `json:"relative_visitors"`
	Bounces          int     `json:"bounces"`
	BounceRate       float64 `json:"bounce_rate"`
}

ReferrerStats is the result type for referrer statistics.

type Scale added in v1.6.0

type Scale string

Scale is used to group results in the Filter. Use one of the constants ScaleDay, ScaleWeek, ScaleMonth, ScaleYear.

type ScreenClassStats added in v1.3.1

type ScreenClassStats struct {
	MetaStats
	ScreenClass string `json:"screen_class"`
}

ScreenClassStats is the result type for screen class statistics.

type TimeSpentStats added in v1.3.1

type TimeSpentStats struct {
	Day                     null.Time `json:"day"`
	Week                    null.Time `json:"week"`
	Month                   null.Time `json:"month"`
	Year                    null.Time `json:"year"`
	Path                    string    `json:"path"`
	Title                   string    `json:"title"`
	AverageTimeSpentSeconds int       `json:"average_time_spent_seconds"`
}

TimeSpentStats is the time spent on the website or specific pages.

type TotalVisitorStats added in v1.5.1

type TotalVisitorStats struct {
	Visitors   int     `json:"visitors"`
	Views      int     `json:"views"`
	Sessions   int     `json:"sessions"`
	Bounces    int     `json:"bounces"`
	BounceRate float64 `json:"bounce_rate"`
}

TotalVisitorStats is the result type for total visitor statistics.

type UTMCampaignStats added in v1.3.1

type UTMCampaignStats struct {
	MetaStats
	UTMCampaign string `json:"utm_campaign"`
}

UTMCampaignStats is the result type for utm campaign statistics.

type UTMContentStats added in v1.3.1

type UTMContentStats struct {
	MetaStats
	UTMContent string `json:"utm_content"`
}

UTMContentStats is the result type for utm content statistics.

type UTMMediumStats added in v1.3.1

type UTMMediumStats struct {
	MetaStats
	UTMMedium string `json:"utm_medium"`
}

UTMMediumStats is the result type for utm medium statistics.

type UTMSourceStats added in v1.3.1

type UTMSourceStats struct {
	MetaStats
	UTMSource string `json:"utm_source"`
}

UTMSourceStats is the result type for utm source statistics.

type UTMTermStats added in v1.3.1

type UTMTermStats struct {
	MetaStats
	UTMTerm string `json:"utm_term"`
}

UTMTermStats is the result type for utm term statistics.

type VisitorHourStats added in v1.3.1

type VisitorHourStats struct {
	Hour       int     `json:"hour"`
	Visitors   int     `json:"visitors"`
	Views      int     `json:"views"`
	Sessions   int     `json:"sessions"`
	Bounces    int     `json:"bounces"`
	BounceRate float64 `json:"bounce_rate"`
}

VisitorHourStats is the result type for visitor statistics grouped by time of day.

type VisitorStats added in v1.3.1

type VisitorStats struct {
	Day        null.Time `json:"day"`
	Week       null.Time `json:"week"`
	Month      null.Time `json:"month"`
	Year       null.Time `json:"year"`
	Visitors   int       `json:"visitors"`
	Views      int       `json:"views"`
	Sessions   int       `json:"sessions"`
	Bounces    int       `json:"bounces"`
	BounceRate float64   `json:"bounce_rate"`
}

VisitorStats is the result type for visitor statistics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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