Documentation ¶
Index ¶
- Constants
- Variables
- func Fingerprint(r *http.Request, salt string) string
- func GetGeoLite2(path, licenseKey string) error
- func GetScreenClass(width int) string
- func IgnoreHit(r *http.Request) bool
- func Migrate(connection string) error
- func RunAtMidnight(f func()) context.CancelFunc
- func Today() time.Time
- type ActiveVisitorStats
- type Analyzer
- func (analyzer *Analyzer) ActiveVisitors(filter *Filter, duration time.Duration) ([]ActiveVisitorStats, int, error)
- func (analyzer *Analyzer) AvgSessionDuration(filter *Filter) ([]TimeSpentStats, error)
- func (analyzer *Analyzer) AvgTimeOnPage(filter *Filter) ([]TimeSpentStats, error)
- func (analyzer *Analyzer) AvgTimeOnPages(filter *Filter) ([]TimeSpentStats, error)
- func (analyzer *Analyzer) Browser(filter *Filter) ([]BrowserStats, error)
- func (analyzer *Analyzer) BrowserVersion(filter *Filter) ([]BrowserVersionStats, error)
- func (analyzer *Analyzer) Countries(filter *Filter) ([]CountryStats, error)
- func (analyzer *Analyzer) EntryPages(filter *Filter) ([]EntryStats, error)
- func (analyzer *Analyzer) EventBreakdown(filter *Filter) ([]EventStats, error)
- func (analyzer *Analyzer) Events(filter *Filter) ([]EventStats, error)
- func (analyzer *Analyzer) ExitPages(filter *Filter) ([]ExitStats, error)
- func (analyzer *Analyzer) Growth(filter *Filter) (*Growth, error)
- func (analyzer *Analyzer) Languages(filter *Filter) ([]LanguageStats, error)
- func (analyzer *Analyzer) OS(filter *Filter) ([]OSStats, error)
- func (analyzer *Analyzer) OSVersion(filter *Filter) ([]OSVersionStats, error)
- func (analyzer *Analyzer) PageConversions(filter *Filter) (*PageConversionsStats, error)
- func (analyzer *Analyzer) Pages(filter *Filter) ([]PageStats, error)
- func (analyzer *Analyzer) Platform(filter *Filter) (*PlatformStats, error)
- func (analyzer *Analyzer) Referrer(filter *Filter) ([]ReferrerStats, error)
- func (analyzer *Analyzer) ScreenClass(filter *Filter) ([]ScreenClassStats, error)
- func (analyzer *Analyzer) TotalSessionDuration(filter *Filter) (int, error)
- func (analyzer *Analyzer) TotalTimeOnPage(filter *Filter) (int, error)
- func (analyzer *Analyzer) UTMCampaign(filter *Filter) ([]UTMCampaignStats, error)
- func (analyzer *Analyzer) UTMContent(filter *Filter) ([]UTMContentStats, error)
- func (analyzer *Analyzer) UTMMedium(filter *Filter) ([]UTMMediumStats, error)
- func (analyzer *Analyzer) UTMSource(filter *Filter) ([]UTMSourceStats, error)
- func (analyzer *Analyzer) UTMTerm(filter *Filter) ([]UTMTermStats, error)
- func (analyzer *Analyzer) VisitorHours(filter *Filter) ([]VisitorHourStats, error)
- func (analyzer *Analyzer) Visitors(filter *Filter) ([]VisitorStats, error)
- type BrowserStats
- type BrowserVersionStats
- type Client
- func (client *Client) Count(query string, args ...interface{}) (int, error)
- func (client *Client) Get(result interface{}, query string, args ...interface{}) error
- func (client *Client) SaveEvents(events []Event) error
- func (client *Client) SaveHits(hits []Hit) error
- func (client *Client) Select(results interface{}, query string, args ...interface{}) error
- func (client *Client) Session(clientID int64, fingerprint string, maxAge time.Time) (Session, error)
- type CountryStats
- type EntryStats
- type Event
- type EventOptions
- type EventStats
- type ExitStats
- type Filter
- type GeoDB
- type GeoDBConfig
- type Growth
- type Hit
- type HitOptions
- type LanguageStats
- type MetaStats
- type MockClient
- func (client *MockClient) Count(query string, args ...interface{}) (int, error)
- func (client *MockClient) Get(result interface{}, query string, args ...interface{}) error
- func (client *MockClient) SaveEvents(events []Event) error
- func (client *MockClient) SaveHits(hits []Hit) error
- func (client *MockClient) Select(results interface{}, query string, args ...interface{}) error
- func (client *MockClient) Session(clientID int64, fingerprint string, maxAge time.Time) (Session, error)
- type OSStats
- type OSVersionStats
- type PageConversionsStats
- type PageStats
- type PlatformStats
- type ReferrerStats
- type ScreenClassStats
- type Session
- type SessionCache
- type Store
- type TimeSpentStats
- type Tracker
- type TrackerConfig
- type UTMCampaignStats
- type UTMContentStats
- type UTMMediumStats
- type UTMSourceStats
- type UTMTermStats
- type UserAgent
- type VisitorHourStats
- type VisitorStats
Constants ¶
const ( // PlatformDesktop filters for everything on desktops. PlatformDesktop = "desktop" // PlatformMobile filters for everything on mobile devices. PlatformMobile = "mobile" // PlatformUnknown filters for everything where the platform is unspecified. PlatformUnknown = "unknown" )
const ( // BrowserChrome represents the Chrome and Chromium browser. BrowserChrome = "Chrome" // BrowserFirefox represents the Firefox browser. BrowserFirefox = "Firefox" // BrowserSafari represents the Safari browser. BrowserSafari = "Safari" // BrowserOpera represents the Opera browser. BrowserOpera = "Opera" // BrowserEdge represents the Edge browser. BrowserEdge = "Edge" // BrowserIE represents the Internet Explorer browser. BrowserIE = "IE" // OSWindows represents the Windows operating system. OSWindows = "Windows" // OSMac represents the Mac operating system. OSMac = "Mac" // OSLinux represents a Linux distribution. OSLinux = "Linux" // OSAndroid represents the Android operating system. OSAndroid = "Android" // OSiOS represents the iOS operating system. OSiOS = "iOS" // OSWindowsMobile represents the Windows Mobile operating system. OSWindowsMobile = "Windows Mobile" )
const (
// GeoLite2Filename is the default filename of the GeoLite2 database.
GeoLite2Filename = "GeoLite2-Country.mmdb"
)
Variables ¶
var ( // ErrNoPeriodOrDay is returned in case no period or day was specified to calculate the growth rate. ErrNoPeriodOrDay = errors.New("no period or day specified") )
var NullClient = int64(0)
NullClient is a placeholder for no client (0).
var ScreenClasses = []screenClass{
{5120, "UHD 5K"},
{3840, "UHD 4K"},
{2560, "WQHD"},
{1920, "Full HD"},
{1280, "HD"},
{1024, "XL"},
{800, "L"},
{600, "M"},
{415, "S"},
}
ScreenClasses is a list of typical screen sizes used to group resolutions. Everything below is considered "XS" (tiny).
Functions ¶
func Fingerprint ¶
Fingerprint returns a hash for given request and salt. The hash is unique for the visitor.
func GetGeoLite2 ¶
GetGeoLite2 downloads and unpacks the MaxMind GeoLite2 database. The tarball is downloaded and unpacked at the provided path. The directories will created if required. The license key is used for the download and must be provided for a registered account. Please refer to MaxMinds website on how to do that: https://dev.maxmind.com/geoip/geoip2/geolite2/ The database should be updated on a regular basis.
func GetScreenClass ¶
GetScreenClass returns the screen class for given width in pixels.
func IgnoreHit ¶
IgnoreHit returns true, if a hit should be ignored for given request, or false otherwise. The easiest way to track visitors is to use the Tracker.
func Migrate ¶
Migrate runs the database migration for given connection string. This will use the embedded schema migration scripts. You have to set the x-multi-statement to true, or else it will fail to run the queries.
func RunAtMidnight ¶
func RunAtMidnight(f func()) context.CancelFunc
RunAtMidnight calls given function on each day of month on midnight (UTC), unless it is cancelled by calling the cancel function.
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 Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer provides an interface to analyze statistics.
func NewAnalyzer ¶
NewAnalyzer returns a new Analyzer for given Store.
func (*Analyzer) ActiveVisitors ¶
func (analyzer *Analyzer) ActiveVisitors(filter *Filter, duration time.Duration) ([]ActiveVisitorStats, int, error)
ActiveVisitors returns the active visitors per path and (optional) page title and the total number of active visitors for given duration. Use time.Minute*5 for example to get the active visitors for the past 5 minutes.
func (*Analyzer) AvgSessionDuration ¶
func (analyzer *Analyzer) AvgSessionDuration(filter *Filter) ([]TimeSpentStats, error)
AvgSessionDuration returns the average session duration grouped by day.
func (*Analyzer) AvgTimeOnPage ¶
func (analyzer *Analyzer) AvgTimeOnPage(filter *Filter) ([]TimeSpentStats, error)
AvgTimeOnPage returns the average time on page grouped by day.
func (*Analyzer) AvgTimeOnPages ¶
func (analyzer *Analyzer) AvgTimeOnPages(filter *Filter) ([]TimeSpentStats, error)
AvgTimeOnPages returns the average time on page grouped by path and (optional) page title.
func (*Analyzer) Browser ¶
func (analyzer *Analyzer) Browser(filter *Filter) ([]BrowserStats, error)
Browser returns the visitor count grouped by browser.
func (*Analyzer) BrowserVersion ¶ added in v2.2.2
func (analyzer *Analyzer) BrowserVersion(filter *Filter) ([]BrowserVersionStats, error)
BrowserVersion returns the visitor count grouped by browser and version.
func (*Analyzer) Countries ¶
func (analyzer *Analyzer) Countries(filter *Filter) ([]CountryStats, error)
Countries returns the visitor count grouped by country.
func (*Analyzer) EntryPages ¶ added in v2.2.0
func (analyzer *Analyzer) EntryPages(filter *Filter) ([]EntryStats, error)
EntryPages returns the visitor count and time on page grouped by path and (optional) page title for the first page visited.
func (*Analyzer) EventBreakdown ¶ added in v2.4.0
func (analyzer *Analyzer) EventBreakdown(filter *Filter) ([]EventStats, error)
EventBreakdown returns the visitor count, views, and conversion rate for a custom event grouping them by a meta value for given key. The Filter.EventName and Filter.EventMetaKey must be set, or otherwise the result set will be empty.
func (*Analyzer) Events ¶ added in v2.4.0
func (analyzer *Analyzer) Events(filter *Filter) ([]EventStats, error)
Events returns the visitor count, views, and conversion rate for custom events.
func (*Analyzer) ExitPages ¶ added in v2.2.0
ExitPages returns the visitor count and time on page grouped by path and (optional) page title for the last page visited.
func (*Analyzer) Growth ¶
Growth returns the growth rate for visitor count, session count, bounces, views, and average session duration or average time on page (if path is set). The growth rate is relative to the previous time range or day. The period or day for the filter must be set, else an error is returned.
func (*Analyzer) Languages ¶
func (analyzer *Analyzer) Languages(filter *Filter) ([]LanguageStats, error)
Languages returns the visitor count grouped by language.
func (*Analyzer) OSVersion ¶ added in v2.2.2
func (analyzer *Analyzer) OSVersion(filter *Filter) ([]OSVersionStats, error)
OSVersion returns the visitor count grouped by operating systems and version.
func (*Analyzer) PageConversions ¶ added in v2.2.5
func (analyzer *Analyzer) PageConversions(filter *Filter) (*PageConversionsStats, error)
PageConversions returns the visitor count, views, and conversion rate for conversion goals. This function is supposed to be used with the Filter.PathPattern, to list page conversions.
func (*Analyzer) Pages ¶
Pages returns the visitor count, session count, bounce rate, views, and average time on page grouped by path and (optional) page title.
func (*Analyzer) Platform ¶
func (analyzer *Analyzer) Platform(filter *Filter) (*PlatformStats, error)
Platform returns the visitor count grouped by platform.
func (*Analyzer) Referrer ¶
func (analyzer *Analyzer) Referrer(filter *Filter) ([]ReferrerStats, error)
Referrer returns the visitor count and bounce rate grouped by referrer.
func (*Analyzer) ScreenClass ¶
func (analyzer *Analyzer) ScreenClass(filter *Filter) ([]ScreenClassStats, error)
ScreenClass returns the visitor count grouped by screen class.
func (*Analyzer) TotalSessionDuration ¶
TotalSessionDuration returns the total session duration in seconds.
func (*Analyzer) TotalTimeOnPage ¶
TotalTimeOnPage returns the total time on page in seconds.
func (*Analyzer) UTMCampaign ¶
func (analyzer *Analyzer) UTMCampaign(filter *Filter) ([]UTMCampaignStats, error)
UTMCampaign returns the visitor count grouped by utm source.
func (*Analyzer) UTMContent ¶
func (analyzer *Analyzer) UTMContent(filter *Filter) ([]UTMContentStats, error)
UTMContent returns the visitor count grouped by utm source.
func (*Analyzer) UTMMedium ¶
func (analyzer *Analyzer) UTMMedium(filter *Filter) ([]UTMMediumStats, error)
UTMMedium returns the visitor count grouped by utm medium.
func (*Analyzer) UTMSource ¶
func (analyzer *Analyzer) UTMSource(filter *Filter) ([]UTMSourceStats, error)
UTMSource returns the visitor count grouped by utm source.
func (*Analyzer) UTMTerm ¶
func (analyzer *Analyzer) UTMTerm(filter *Filter) ([]UTMTermStats, error)
UTMTerm returns the visitor count grouped by utm source.
func (*Analyzer) VisitorHours ¶
func (analyzer *Analyzer) VisitorHours(filter *Filter) ([]VisitorHourStats, error)
VisitorHours returns the visitor count grouped by time of day.
type BrowserStats ¶
BrowserStats is the result type for browser statistics.
type BrowserVersionStats ¶ added in v2.2.2
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 Client ¶
Client is a ClickHouse database client.
func NewClient ¶
NewClient returns a new client for given database connection string. The logger is optional.
func (*Client) SaveEvents ¶ added in v2.4.0
SaveEvents implements the Store interface.
type CountryStats ¶
CountryStats is the result type for country statistics.
type EntryStats ¶ added in v2.2.1
type EntryStats struct { Path string `json:"path"` Title string `json:"title"` Visitors int `json:"visitors"` Entries int `json:"entries"` AverageTimeSpentSeconds int `db:"average_time_spent_seconds" json:"average_time_spent_seconds"` }
EntryStats is the result type for entry page statistics.
type Event ¶ added in v2.4.0
type Event struct { Hit Name string `db:"event_name" json:"name"` DurationSeconds int `db:"event_duration_seconds" json:"duration_seconds"` MetaKeys []string `db:"event_meta_keys" json:"meta_keys"` MetaValues []string `db:"event_meta_values" json:"meta_values"` }
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 EventOptions ¶ added in v2.4.0
type EventOptions struct { // Name is the name of the event (required). Name string // Duration is an optional duration that is used to calculate an average time on the dashboard. Duration int // Meta are optional fields used to break down the events that were send for a name. Meta map[string]string }
EventOptions are the options to save a new event. The name is required. All other fields are optional.
type EventStats ¶ added in v2.4.0
type EventStats struct { Name string `db:"event_name" json:"name"` Visitors int `json:"visitors"` Views int `json:"views"` CR float64 `json:"cr"` AverageDurationSeconds int `db:"average_duration_seconds" json:"average_duration_seconds"` MetaKeys []string `db:"meta_keys" json:"meta_keys"` MetaValue string `db:"meta_value" json:"meta_value"` }
EventStats is the result type for custom events.
type ExitStats ¶ added in v2.2.1
type ExitStats struct { Path string `json:"path"` Title string `json:"title"` Visitors int `json:"visitors"` Exits int `json:"exits"` ExitRate float64 `db:"exit_rate" json:"exit_rate"` }
ExitStats is the result type for exit page statistics.
type Filter ¶
type Filter struct { // ClientID is the optional. ClientID int64 // Timezone sets the timezone used to interpret dates and times. // It will be set to UTC by default. Timezone *time.Location // From is the start date of the selected period. From time.Time // To is the end date of the selected period. To time.Time // Day is an exact match for the result set ("on this day"). Day time.Time // Start is the start date and time of the selected period. Start time.Time // Path filters for the path. // Note that if this and PathPattern are both set, Path will be preferred. Path string // PathPattern filters for the path using a (ClickHouse supported) regex pattern. // Note that if this and Path are both set, Path will be preferred. // Examples for useful patterns (all case-insensitive, * is used for every character but slashes, ** is used for all characters including slashes): // (?i)^/path/[^/]+$ // matches /path/* // (?i)^/path/[^/]+/.* // matches /path/*/** // (?i)^/path/[^/]+/slashes$ // matches /path/*/slashes // (?i)^/path/.+/slashes$ // matches /path/**/slashes PathPattern string // Language filters for the ISO language code. Language string // Country filters for the ISO country code. Country string // Referrer filters for the referrer. Referrer string // OS filters for the operating system. OS string // OSVersion filters for the operating system version. OSVersion string // Browser filters for the browser. Browser string // BrowserVersion filters for the browser version. BrowserVersion string // Platform filters for the platform (desktop, mobile, unknown). Platform string // ScreenClass filters for the screen class. ScreenClass string // UTMSource filters for the utm_source query parameter. UTMSource string // UTMMedium filters for the utm_medium query parameter. UTMMedium string // UTMCampaign filters for the utm_campaign query parameter. UTMCampaign string // UTMContent filters for the utm_content query parameter. UTMContent string // UTMTerm filters for the utm_term query parameter. UTMTerm string // EventName filters for an event by its name. EventName string // EventMetaKey filters for an event meta key. // This must be used together with an EventName. EventMetaKey string // Limit limits the number of results. Less or equal to zero means no limit. Limit int // IncludeTitle indicates whether the Analyzer.Pages, Analyzer.EntryPages, and Analyzer.ExitPages should contain the page title or not. IncludeTitle bool // IncludeAvgTimeOnPage indicates whether Analyzer.Pages and Analyzer.EntryPages should contain the average time on page or not. IncludeAvgTimeOnPage bool // MaxTimeOnPageSeconds is an optional maximum for the time spent on page. // Visitors who are idle artificially increase the average time spent on a page, this option can be used to limit the effect. // Set to 0 to disable this option (default). MaxTimeOnPageSeconds int }
Filter are all fields that can be used to filter the result sets. Fields can be inverted by adding a "!" in front of the string.
type GeoDB ¶
type GeoDB struct {
// contains filtered or unexported fields
}
GeoDB maps IPs to their geo location based on MaxMinds GeoLite2 or GeoIP2 database.
func NewGeoDB ¶
func NewGeoDB(config GeoDBConfig) (*GeoDB, error)
NewGeoDB creates a new GeoDB for given database file. The file is loaded into memory, therefore it's not necessary to close the reader (see oschwald/maxminddb-golang documentatio). The database should be updated on a regular basis.
func (*GeoDB) CountryCode ¶
CountryCode looks up the country code for given IP. If the IP is invalid it will return an empty string. The country code is returned in lowercase.
type GeoDBConfig ¶
type GeoDBConfig struct { // File is the path (including the filename) to the GeoLite2 country database file. // See GeoLite2Filename for the required filename. File string // Logger is the log.Logger used for logging. // Note that this will log the IP address and should therefore only be used for debugging. // Set it to nil to disable logging for GeoDB. Logger *log.Logger }
GeoDBConfig is the configuration for the GeoDB.
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"` }
Growth represents the visitors, views, sessions, bounces, and average session duration growth between two time periods.
type Hit ¶
type Hit struct { ClientID int64 `db:"client_id"` Fingerprint string Time time.Time Session time.Time PreviousTimeOnPageSeconds int `db:"previous_time_on_page_seconds"` UserAgent string `db:"user_agent"` Path string URL string Title string Language string CountryCode string `db:"country_code"` Referrer string ReferrerName string `db:"referrer_name"` ReferrerIcon string `db:"referrer_icon"` OS string OSVersion string `db:"os_version"` Browser string BrowserVersion string `db:"browser_version"` Desktop bool Mobile bool ScreenWidth int `db:"screen_width"` ScreenHeight int `db:"screen_height"` ScreenClass string `db:"screen_class"` UTMSource string `db:"utm_source"` UTMMedium string `db:"utm_medium"` UTMCampaign string `db:"utm_campaign"` UTMContent string `db:"utm_content"` UTMTerm string `db:"utm_term"` }
Hit represents a single data point/page visit and is the central entity of Pirsch.
func HitFromRequest ¶
func HitFromRequest(r *http.Request, salt string, options *HitOptions) Hit
HitFromRequest returns a new Hit for given request, salt and HitOptions. The salt must stay consistent to track visitors across multiple calls. The easiest way to track visitors is to use the Tracker.
type HitOptions ¶
type HitOptions struct { // SessionCache is the cache to look up sessions. SessionCache *SessionCache // ClientID is optionally saved with a hit to split the data between multiple clients. ClientID int64 // SessionMaxAge defines the maximum time a session stays active. // A session is kept active if requests are made within the time frame. // Set to 15 minutes by default. SessionMaxAge time.Duration // URL can be set to manually overwrite the URL stored for this request. // This will also affect the Path, except it is set too. URL string // Path can be set to manually overwrite the path stored for the request. // This will also affect the URL. Path string // Title is the page title. Title string // Referrer can be set to manually overwrite the referrer from the request. Referrer string // ReferrerDomainBlacklist is used to filter out unwanted referrers from the Referrer header. // This can be used to filter out traffic from your own site or subdomains. // To filter your own domain and subdomains, add your domain to the list and set ReferrerDomainBlacklistIncludesSubdomains to true. // This way the referrer for blog.mypage.com -> mypage.com won't be saved. ReferrerDomainBlacklist []string // ReferrerDomainBlacklistIncludesSubdomains set to true to include all subdomains in the ReferrerDomainBlacklist, // or else subdomains must explicitly be included in the blacklist. // If the blacklist contains domain.com, sub.domain.com and domain.com will be treated as equals. ReferrerDomainBlacklistIncludesSubdomains bool // ScreenWidth sets the screen width to be stored with the hit. ScreenWidth int // ScreenHeight sets the screen height to be stored with the hit. ScreenHeight int // contains filtered or unexported fields }
HitOptions is used to manipulate the data saved on a hit.
func HitOptionsFromRequest ¶
func HitOptionsFromRequest(r *http.Request) *HitOptions
HitOptionsFromRequest returns the HitOptions for given client request. This function can be used to accept hits from pirsch.js. Invalid parameters are ignored and left empty. You might want to add additional checks before calling HitFromRequest afterwards (like for the HitOptions.ClientID).
type LanguageStats ¶
LanguageStats is the result type for language statistics.
type MetaStats ¶
type MetaStats struct { Visitors int `json:"visitors"` RelativeVisitors float64 `db:"relative_visitors" json:"relative_visitors"` }
MetaStats is the base for meta result types (languages, countries, ...).
type MockClient ¶
type MockClient struct { Hits []Hit Events []Event ReturnSession *Session // contains filtered or unexported fields }
MockClient is a mock Store implementation.
func (*MockClient) Count ¶
func (client *MockClient) Count(query string, args ...interface{}) (int, error)
Count implements the Store interface.
func (*MockClient) Get ¶
func (client *MockClient) Get(result interface{}, query string, args ...interface{}) error
Get implements the Store interface.
func (*MockClient) SaveEvents ¶ added in v2.4.0
func (client *MockClient) SaveEvents(events []Event) error
SaveEvents implements the Store interface.
func (*MockClient) SaveHits ¶
func (client *MockClient) SaveHits(hits []Hit) error
SaveHits implements the Store interface.
func (*MockClient) Select ¶
func (client *MockClient) Select(results interface{}, query string, args ...interface{}) error
Select implements the Store interface.
type OSVersionStats ¶ added in v2.2.2
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 v2.2.5
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"` Title string `json:"title"` Visitors int `json:"visitors"` Views int `json:"views"` Sessions int `json:"sessions"` Bounces int `json:"bounces"` RelativeVisitors float64 `db:"relative_visitors" json:"relative_visitors"` RelativeViews float64 `db:"relative_views" json:"relative_views"` BounceRate float64 `db:"bounce_rate" json:"bounce_rate"` AverageTimeSpentSeconds int `db:"average_time_spent_seconds" json:"average_time_spent_seconds"` }
PageStats is the result type for page statistics.
type PlatformStats ¶
type PlatformStats struct { PlatformDesktop int `db:"platform_desktop" json:"platform_desktop"` PlatformMobile int `db:"platform_mobile" json:"platform_mobile"` PlatformUnknown int `db:"platform_unknown" json:"platform_unknown"` RelativePlatformDesktop float64 `db:"relative_platform_desktop" json:"relative_platform_desktop"` RelativePlatformMobile float64 `db:"relative_platform_mobile" json:"relative_platform_mobile"` RelativePlatformUnknown float64 `db:"relative_platform_unknown" json:"relative_platform_unknown"` }
PlatformStats is the result type for platform statistics.
type ReferrerStats ¶
type ReferrerStats struct { Referrer string `json:"referrer"` ReferrerName string `db:"referrer_name" json:"referrer_name"` ReferrerIcon string `db:"referrer_icon" json:"referrer_icon"` Visitors int `json:"visitors"` RelativeVisitors float64 `db:"relative_visitors" json:"relative_visitors"` Bounces int `json:"bounces"` BounceRate float64 `db:"bounce_rate" json:"bounce_rate"` }
ReferrerStats is the result type for referrer statistics.
type ScreenClassStats ¶
type ScreenClassStats struct { MetaStats ScreenClass string `db:"screen_class" json:"screen_class"` }
ScreenClassStats is the result type for screen class statistics.
type Session ¶ added in v2.6.0
Session represents a visitor session as it is returned by the Client from the database. This is not used for any actual statistic.
type SessionCache ¶ added in v2.6.0
type SessionCache struct {
// contains filtered or unexported fields
}
SessionCache caches sessions.
func NewSessionCache ¶ added in v2.6.0
func NewSessionCache(client Store, maxSessions int) *SessionCache
NewSessionCache creates a new cache for given client and maximum size.
type Store ¶
type Store interface { // SaveHits saves given hits. SaveHits([]Hit) error // SaveEvents saves given events. SaveEvents([]Event) error // Session returns the last path, time, and session timestamp for given client, fingerprint, and maximum age. Session(int64, string, time.Time) (Session, error) // Count returns the number of results for given query. Count(string, ...interface{}) (int, error) // Get returns a single result for given query. // The result must be a pointer. Get(interface{}, string, ...interface{}) error // Select returns the results for given query. // The results must be a pointer to a slice. Select(interface{}, string, ...interface{}) error }
Store is the database storage interface.
type TimeSpentStats ¶
type TimeSpentStats struct { Day time.Time `json:"day"` Path string `json:"path"` Title string `json:"title"` AverageTimeSpentSeconds int `db:"average_time_spent_seconds" json:"average_time_spent_seconds"` }
TimeSpentStats is the result type for average time spent statistics (sessions, time on page).
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker provides methods to track requests (hits and events). Make sure you call Stop to make sure the hits get stored before shutting down the server.
func NewTracker ¶
func NewTracker(client Store, salt string, config *TrackerConfig) *Tracker
NewTracker creates a new tracker for given client, salt and config. Pass nil for the config to use the defaults. The salt is mandatory. It creates the same amount of workers for both, hits and events.
func (*Tracker) Event ¶ added in v2.4.0
func (tracker *Tracker) Event(r *http.Request, eventOptions EventOptions, options *HitOptions)
Event stores the given request as a new event. The event name in the options must be set, or otherwise the request will be ignored. The request might be ignored if it meets certain conditions. The HitOptions, if passed, will overwrite the Tracker configuration. It's save (and recommended!) to call this function in its own goroutine.
func (*Tracker) Flush ¶
func (tracker *Tracker) Flush()
Flush flushes all hits to client that are currently buffered by the workers. Call Tracker.Stop to also save hits that are in the queue.
func (*Tracker) Hit ¶
func (tracker *Tracker) Hit(r *http.Request, options *HitOptions)
Hit stores the given request. The request might be ignored if it meets certain conditions. The HitOptions, if passed, will overwrite the Tracker configuration. It's save (and recommended!) to call this function in its own goroutine.
type TrackerConfig ¶
type TrackerConfig struct { // Worker sets the number of workers that are used to client hits. // Must be greater or equal to 1. Worker int // WorkerBufferSize is the size of the buffer used to client hits. // Must be greater than 0. The hits are stored in batch when the buffer is full. WorkerBufferSize int // WorkerTimeout sets the timeout used to client hits. // This is used to allow the workers to client hits even if the buffer is not full yet. // It's recommended to set this to a few seconds. // If you leave it 0, the default timeout is used, else it is limited to 60 seconds. WorkerTimeout time.Duration // ReferrerDomainBlacklist see HitOptions.ReferrerDomainBlacklist. ReferrerDomainBlacklist []string // ReferrerDomainBlacklistIncludesSubdomains see HitOptions.ReferrerDomainBlacklistIncludesSubdomains. ReferrerDomainBlacklistIncludesSubdomains bool // MaxSessions sets the maximum size for the session cache. // If you leave it 0, the default will be used. MaxSessions int // SessionMaxAge see HitOptions.SessionMaxAge. SessionMaxAge time.Duration // GeoDB enables/disabled mapping IPs to country codes. // Can be set/updated at runtime by calling Tracker.SetGeoDB. GeoDB *GeoDB // Logger is the log.Logger used for logging. // The default log will be used printing to os.Stdout with "pirsch" in its prefix in case it is not set. Logger *log.Logger }
TrackerConfig is the optional configuration for the Tracker.
type UTMCampaignStats ¶
type UTMCampaignStats struct { MetaStats UTMCampaign string `db:"utm_campaign" json:"utm_campaign"` }
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 UserAgent ¶
type UserAgent struct { // Browser is the browser name. Browser string // BrowserVersion is the browser (non technical) version number. BrowserVersion string // OS is the operating system. OS string // OSVersion is the operating system version number. OSVersion string }
UserAgent contains information extracted from the User-Agent header.
func ParseUserAgent ¶
ParseUserAgent parses given User-Agent header and returns the extracted information. This just supports major browsers and operating systems, we don't care about browsers and OSes that have no market share, unless you prove us wrong.
type VisitorHourStats ¶
VisitorHourStats is the result type for visitor statistics grouped by time of day.
type VisitorStats ¶
type VisitorStats struct { Day time.Time `json:"day"` Visitors int `json:"visitors"` Views int `json:"views"` Sessions int `json:"sessions"` Bounces int `json:"bounces"` BounceRate float64 `db:"bounce_rate" json:"bounce_rate"` }
VisitorStats is the result type for visitor statistics.
Source Files ¶
- analyzer.go
- client.go
- event.go
- filter.go
- fingerprint.go
- geodb.go
- hit.go
- ip.go
- language.go
- migrate.go
- mock.go
- model.go
- referrer.go
- referrer_blacklist.go
- screen.go
- session_cache.go
- store.go
- today.go
- tracker.go
- user_agent.go
- user_agent_blacklist.go
- user_agent_lists.go
- user_agent_test_data.go
- util.go
- utm.go