Documentation ¶
Index ¶
- Constants
- type ActiveVisitorStats
- type ActiveVisitorsData
- type BaseEntity
- type BrowserStats
- type BrowserVersionStats
- type CityStats
- type Client
- func (client *Client) ActiveVisitors(filter *Filter) (*ActiveVisitorsData, error)
- func (client *Client) Browser(filter *Filter) ([]BrowserStats, error)
- func (client *Client) BrowserVersions(filter *Filter) ([]BrowserVersionStats, error)
- func (client *Client) City(filter *Filter) ([]CityStats, error)
- func (client *Client) ConversionGoals(filter *Filter) ([]ConversionGoal, error)
- func (client *Client) Country(filter *Filter) ([]CountryStats, error)
- func (client *Client) Domain() (*Domain, error)
- func (client *Client) EntryPages(filter *Filter) ([]EntryStats, error)
- func (client *Client) Event(name string, durationSeconds int, meta map[string]string, r *http.Request, ...) error
- func (client *Client) EventMetadata(filter *Filter) ([]EventStats, error)
- func (client *Client) Events(filter *Filter) ([]EventStats, error)
- func (client *Client) ExitPages(filter *Filter) ([]ExitStats, error)
- func (client *Client) Growth(filter *Filter) (*Growth, error)
- func (client *Client) Keywords(filter *Filter) ([]Keyword, error)
- func (client *Client) Languages(filter *Filter) ([]LanguageStats, error)
- func (client *Client) ListEvents(filter *Filter) ([]EventListStats, error)
- func (client *Client) OS(filter *Filter) ([]OSStats, error)
- func (client *Client) OSVersions(filter *Filter) ([]OSVersionStats, error)
- func (client *Client) PageView(r *http.Request, options *PageViewOptions) error
- func (client *Client) Pages(filter *Filter) ([]PageStats, error)
- func (client *Client) Platform(filter *Filter) (*PlatformStats, error)
- func (client *Client) Referrer(filter *Filter) ([]ReferrerStats, error)
- func (client *Client) Screen(filter *Filter) ([]ScreenClassStats, error)
- func (client *Client) Session(r *http.Request, options *PageViewOptions) error
- func (client *Client) SessionDuration(filter *Filter) ([]TimeSpentStats, error)
- func (client *Client) TagKeys(filter *Filter) ([]TagStats, error)
- func (client *Client) Tags(filter *Filter) ([]TagStats, error)
- func (client *Client) TimeOfDay(filter *Filter) ([]VisitorHourStats, error)
- func (client *Client) TimeOnPage(filter *Filter) ([]TimeSpentStats, error)
- func (client *Client) TotalVisitors(filter *Filter) (*TotalVisitorStats, error)
- func (client *Client) UTMCampaign(filter *Filter) ([]UTMCampaignStats, error)
- func (client *Client) UTMContent(filter *Filter) ([]UTMContentStats, error)
- func (client *Client) UTMMedium(filter *Filter) ([]UTMMediumStats, error)
- func (client *Client) UTMSource(filter *Filter) ([]UTMSourceStats, error)
- func (client *Client) UTMTerm(filter *Filter) ([]UTMTermStats, error)
- func (client *Client) Visitors(filter *Filter) ([]VisitorStats, error)
- type ClientConfig
- type ConversionGoal
- type ConversionGoalStats
- type CountryStats
- type CustomMetricType
- type Domain
- type EntryStats
- type Event
- type EventListStats
- type EventStats
- type ExitStats
- type Filter
- type Growth
- type KeyValue
- type Keyword
- type LanguageStats
- type MetaStats
- type OSStats
- type OSVersionStats
- type PageConversionsStats
- type PageStats
- type PageView
- type PageViewOptions
- type PlatformStats
- type ReferrerStats
- type Scale
- type ScreenClassStats
- type TagStats
- type TimeSpentStats
- type TotalVisitorStats
- type UTMCampaignStats
- type UTMContentStats
- type UTMMediumStats
- type UTMSourceStats
- type UTMTermStats
- type VisitorHourStats
- type VisitorStats
Constants ¶
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" // CustomMetricTypeInteger sets the custom metric type to integer. CustomMetricTypeInteger = "integer" // CustomMetricTypeFloat sets the custom metric type to float. CustomMetricTypeFloat = "float" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActiveVisitorStats ¶
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 ¶
type ActiveVisitorsData struct { Stats []ActiveVisitorStats `json:"stats"` Visitors int `json:"visitors"` }
ActiveVisitorsData contains the active visitors data.
type BaseEntity ¶
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 ¶
BrowserStats is the result type for browser statistics.
type BrowserVersionStats ¶
type BrowserVersionStats struct { MetaStats Browser string `json:"browser"` BrowserVersion string `json:"browser_version"` }
BrowserVersionStats is the result type for browser version 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 ¶
func (client *Client) ActiveVisitors(filter *Filter) (*ActiveVisitorsData, error)
ActiveVisitors returns the active visitors and what pages they're on.
func (*Client) Browser ¶
func (client *Client) Browser(filter *Filter) ([]BrowserStats, error)
Browser returns browser statistics.
func (*Client) BrowserVersions ¶
func (client *Client) BrowserVersions(filter *Filter) ([]BrowserVersionStats, error)
BrowserVersions returns browser version statistics.
func (*Client) ConversionGoals ¶
func (client *Client) ConversionGoals(filter *Filter) ([]ConversionGoal, error)
ConversionGoals returns all conversion goals.
func (*Client) Country ¶
func (client *Client) Country(filter *Filter) ([]CountryStats, error)
Country returns country statistics.
func (*Client) EntryPages ¶
func (client *Client) EntryPages(filter *Filter) ([]EntryStats, error)
EntryPages returns the entry page statistics grouped by page.
func (*Client) Event ¶
func (client *Client) Event(name string, durationSeconds int, meta map[string]string, r *http.Request, options *PageViewOptions) error
Event sends an event to Pirsch for given http.Request and options.
func (*Client) EventMetadata ¶
func (client *Client) EventMetadata(filter *Filter) ([]EventStats, error)
EventMetadata returns the metadata values for an event and key.
func (*Client) Events ¶
func (client *Client) Events(filter *Filter) ([]EventStats, error)
Events returns all events.
func (*Client) Languages ¶
func (client *Client) Languages(filter *Filter) ([]LanguageStats, error)
Languages returns language statistics.
func (*Client) ListEvents ¶
func (client *Client) ListEvents(filter *Filter) ([]EventListStats, error)
ListEvents returns a list of all events including metadata.
func (*Client) OSVersions ¶
func (client *Client) OSVersions(filter *Filter) ([]OSVersionStats, error)
OSVersions returns operating system version statistics.
func (*Client) PageView ¶
func (client *Client) PageView(r *http.Request, options *PageViewOptions) error
PageView sends a page hit to Pirsch for given http.Request and options.
func (*Client) Platform ¶
func (client *Client) Platform(filter *Filter) (*PlatformStats, error)
Platform returns the platforms used by visitors.
func (*Client) Referrer ¶
func (client *Client) Referrer(filter *Filter) ([]ReferrerStats, error)
Referrer returns referrer statistics.
func (*Client) Screen ¶
func (client *Client) Screen(filter *Filter) ([]ScreenClassStats, error)
Screen returns the screen classes used by visitors.
func (*Client) Session ¶
func (client *Client) Session(r *http.Request, options *PageViewOptions) error
Session keeps a session alive for the given http.Request and options.
func (*Client) SessionDuration ¶
func (client *Client) SessionDuration(filter *Filter) ([]TimeSpentStats, error)
SessionDuration returns the session duration grouped by day.
func (*Client) TimeOfDay ¶
func (client *Client) TimeOfDay(filter *Filter) ([]VisitorHourStats, error)
TimeOfDay returns the number of unique visitors grouped by time of day.
func (*Client) TimeOnPage ¶
func (client *Client) TimeOnPage(filter *Filter) ([]TimeSpentStats, error)
TimeOnPage returns the time spent on pages.
func (*Client) TotalVisitors ¶
func (client *Client) TotalVisitors(filter *Filter) (*TotalVisitorStats, error)
TotalVisitors returns the total visitor statistics.
func (*Client) UTMCampaign ¶
func (client *Client) UTMCampaign(filter *Filter) ([]UTMCampaignStats, error)
UTMCampaign returnst he utm campaigns.
func (*Client) UTMContent ¶
func (client *Client) UTMContent(filter *Filter) ([]UTMContentStats, error)
UTMContent returns the utm content.
func (*Client) UTMMedium ¶
func (client *Client) UTMMedium(filter *Filter) ([]UTMMediumStats, error)
UTMMedium returns the utm medium.
func (*Client) UTMSource ¶
func (client *Client) UTMSource(filter *Filter) ([]UTMSourceStats, error)
UTMSource returns the utm sources.
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 slog.Handler }
ClientConfig is used to configure the Client.
type ConversionGoal ¶
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 ¶
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 ¶
CountryStats is the result type for country statistics.
type CustomMetricType ¶ added in v2.1.0
type CustomMetricType string
CustomMetricType is used to set the type for a custom metric in the Filter. Use one of the constants CustomMetricTypeInteger or CustomMetricTypeFloat.
type Domain ¶
type Domain struct { BaseEntity UserID string `json:"user_id"` OrganizationID string `json:"organization_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"` GroupByTitle bool `json:"group_by_title"` ActiveVisitorsSeconds null.Int64 `json:"active_visitors_seconds"` DisableScripts bool `json:"disable_scripts"` StatisticsStart null.Time `json:"statistics_start"` ImportedStatistics bool `json:"imported_statistics"` ThemeID string `json:"theme_id"` Theme KeyValue `json:"theme"` CustomDomain null.String `json:"custom_domain"` DisplayName null.String `json:"display_name"` UserRole string `json:"user_role"` Settings KeyValue `json:"settings"` ThemeSettings KeyValue `json:"theme_settings"` Pinned bool `json:"pinned"` SubscriptionActive bool `json:"subscription_active"` }
Domain is a domain on the dashboard.
type EntryStats ¶
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 ¶
type Event struct { PageView 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 PageView, but with some additional fields (event name, time, and meta fields).
type EventListStats ¶
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 ¶
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 ¶
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 ¶
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"` Timezone string `json:"tz,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"` EventMeta map[string]string `json:"-"` 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"` 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"` Tag []string `json:"tag"` Tags map[string]string `json:"-"` CustomMetricKey string `json:"custom_metric_key,omitempty"` CustomMetricType CustomMetricType `json:"custom_metric_type,omitempty"` IncludeAvgTimeOnPage bool `json:"include_avg_time_on_page,omitempty"` Offset int `json:"offset,omitempty"` Limit int `json:"limit,omitempty"` Sort string `json:"sort,omitempty"` Direction string `json:"direction,omitempty"` Search string `json:"search,omitempty"` }
Filter is used to filter statistics. DomainID, From, and To are required dates (the time is ignored).
type Growth ¶
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"` CRGrowth float64 `json:"cr_growth"` CustomMetricAvgGrowth float64 `json:"custom_metric_avg_growth"` CustomMetricTotalGrowth float64 `json:"custom_metric_total_growth"` }
Growth represents the visitors, views, sessions, bounces, and average session duration growth between two time periods.
type Keyword ¶
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 ¶
LanguageStats is the result type for language statistics.
type MetaStats ¶
type MetaStats struct { Visitors int `json:"visitors"` RelativeVisitors float64 `json:"relative_visitors"` }
MetaStats is the base for meta result types (languages, countries, ...).
type OSVersionStats ¶
OSVersionStats is the result type for operating system version statistics.
type PageConversionsStats ¶
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 ¶
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 PageView ¶
type PageView struct { Hostname string URL string `json:"url"` IP string `json:"ip"` UserAgent string `json:"user_agent"` AcceptLanguage string `json:"accept_language"` SecCHUA string `json:"sec_ch_ua"` SecCHUAMobile string `json:"sec_ch_ua_mobile"` SecCHUAPlatform string `json:"sec_ch_ua_platform"` SecCHUAPlatformVersion string `json:"sec_ch_ua_platform_version"` SecCHWidth string `json:"sec_ch_width"` SecCHViewportWidth string `json:"sec_ch_viewport_width"` Title string `json:"title"` Referrer string `json:"referrer"` ScreenWidth int `json:"screen_width"` ScreenHeight int `json:"screen_height"` Tags map[string]string `json:"tags"` }
PageView are the parameters to send a page hit to Pirsch.
type PageViewOptions ¶
type PageViewOptions struct { URL string IP string UserAgent string AcceptLanguage string SecCHUA string SecCHUAMobile string SecCHUAPlatform string SecCHUAPlatformVersion string SecCHWidth string SecCHViewportWidth string Title string Referrer string ScreenWidth int ScreenHeight int Tags map[string]string }
PageViewOptions optional parameters to send with the hit request.
type PlatformStats ¶
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 ¶
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 ¶
type Scale string
Scale is used to group results in the Filter. Use one of the constants ScaleDay, ScaleWeek, ScaleMonth, ScaleYear.
type ScreenClassStats ¶
ScreenClassStats is the result type for screen class statistics.
type TagStats ¶ added in v2.2.0
type TagStats struct { Key string `json:"key"` Value string `json:"value"` Visitors int `json:"visitors"` Views int `json:"views"` RelativeVisitors float64 `json:"relative_visitors"` RelativeViews float64 `json:"relative_views"` }
TagStats is the result type for tags.
type TimeSpentStats ¶
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 ¶
type TotalVisitorStats struct { Visitors int `json:"visitors"` Views int `json:"views"` Sessions int `json:"sessions"` Bounces int `json:"bounces"` BounceRate float64 `json:"bounce_rate"` CR float64 `json:"cr"` CustomMetricAvg float64 `json:"custom_metric_avg"` CustomMetricTotal float64 `json:"custom_metric_total"` }
TotalVisitorStats is the result type for total visitor statistics.
type UTMCampaignStats ¶
UTMCampaignStats is the result type for utm campaign statistics.
type UTMContentStats ¶
UTMContentStats is the result type for utm content statistics.
type UTMMediumStats ¶
UTMMediumStats is the result type for utm medium statistics.
type UTMSourceStats ¶
UTMSourceStats is the result type for utm source statistics.
type UTMTermStats ¶
UTMTermStats is the result type for utm term statistics.
type VisitorHourStats ¶
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"` CR float64 `json:"cr"` CustomMetricAvg float64 `json:"custom_metric_avg"` CustomMetricTotal float64 `json:"custom_metric_total"` }
VisitorHourStats is the result type for visitor statistics grouped by time of day.
type VisitorStats ¶
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"` CR float64 `json:"cr"` CustomMetricAvg float64 `json:"custom_metric_avg"` CustomMetricTotal float64 `json:"custom_metric_total"` }
VisitorStats is the result type for visitor statistics.