Documentation ¶
Index ¶
- Constants
- Variables
- func Fingerprint(r *http.Request, salt string) string
- func GetGeoLite2(path, licenseKey string) error
- func IgnoreHit(r *http.Request) bool
- func NewTenantID(id int64) sql.NullInt64
- func RunAtMidnight(f func()) context.CancelFunc
- type Analyzer
- func (analyzer *Analyzer) ActiveVisitors(filter *Filter, duration time.Duration) ([]Stats, int, error)
- func (analyzer *Analyzer) Browser(filter *Filter) ([]BrowserStats, error)
- func (analyzer *Analyzer) Country(filter *Filter) ([]CountryStats, error)
- func (analyzer *Analyzer) Languages(filter *Filter) ([]LanguageStats, error)
- func (analyzer *Analyzer) OS(filter *Filter) ([]OSStats, error)
- func (analyzer *Analyzer) PageBrowser(filter *Filter) ([]BrowserStats, error)
- func (analyzer *Analyzer) PageLanguages(filter *Filter) ([]LanguageStats, error)
- func (analyzer *Analyzer) PageOS(filter *Filter) ([]OSStats, error)
- func (analyzer *Analyzer) PagePlatform(filter *Filter) *VisitorStats
- func (analyzer *Analyzer) PageReferrer(filter *Filter) ([]ReferrerStats, error)
- func (analyzer *Analyzer) PageVisitors(filter *Filter) ([]PathVisitors, error)
- func (analyzer *Analyzer) Platform(filter *Filter) *VisitorStats
- func (analyzer *Analyzer) Referrer(filter *Filter) ([]ReferrerStats, error)
- func (analyzer *Analyzer) Screen(filter *Filter) ([]ScreenStats, error)
- func (analyzer *Analyzer) TimeOfDay(filter *Filter) ([]TimeOfDayVisitors, error)
- func (analyzer *Analyzer) VisitorHours(filter *Filter) ([]VisitorTimeStats, error)
- func (analyzer *Analyzer) Visitors(filter *Filter) ([]Stats, error)
- type AnalyzerConfig
- type BaseEntity
- type BrowserStats
- type CountryStats
- type Filter
- type GeoDB
- type Hit
- type HitOptions
- type LanguageStats
- type OSStats
- type PathVisitors
- type PostgresConfig
- type PostgresStore
- func (store *PostgresStore) ActivePageVisitors(tenantID sql.NullInt64, from time.Time) ([]Stats, error)
- func (store *PostgresStore) ActiveVisitors(tenantID sql.NullInt64, from time.Time) int
- func (store *PostgresStore) Commit(tx *sqlx.Tx)
- func (store *PostgresStore) CountVisitors(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) *Stats
- func (store *PostgresStore) CountVisitorsByBrowser(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]BrowserStats, error)
- func (store *PostgresStore) CountVisitorsByCountryCode(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]CountryStats, error)
- func (store *PostgresStore) CountVisitorsByLanguage(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]LanguageStats, error)
- func (store *PostgresStore) CountVisitorsByOS(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]OSStats, error)
- func (store *PostgresStore) CountVisitorsByPath(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string, ...) ([]VisitorStats, error)
- func (store *PostgresStore) CountVisitorsByPathAndBrowser(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]BrowserStats, error)
- func (store *PostgresStore) CountVisitorsByPathAndHour(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]VisitorTimeStats, error)
- func (store *PostgresStore) CountVisitorsByPathAndLanguage(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]LanguageStats, error)
- func (store *PostgresStore) CountVisitorsByPathAndMaxOneHit(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) int
- func (store *PostgresStore) CountVisitorsByPathAndOS(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]OSStats, error)
- func (store *PostgresStore) CountVisitorsByPathAndReferrer(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]ReferrerStats, error)
- func (store *PostgresStore) CountVisitorsByPlatform(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) *VisitorStats
- func (store *PostgresStore) CountVisitorsByReferrer(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]ReferrerStats, error)
- func (store *PostgresStore) CountVisitorsByScreenSize(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]ScreenStats, error)
- func (store *PostgresStore) DeleteHitsByDay(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) error
- func (store *PostgresStore) HitDays(tenantID sql.NullInt64) ([]time.Time, error)
- func (store *PostgresStore) HitPaths(tenantID sql.NullInt64, day time.Time) ([]string, error)
- func (store *PostgresStore) NewTx() *sqlx.Tx
- func (store *PostgresStore) PageBrowser(tenantID sql.NullInt64, path string, from time.Time, to time.Time) ([]BrowserStats, error)
- func (store *PostgresStore) PageLanguages(tenantID sql.NullInt64, path string, from time.Time, to time.Time) ([]LanguageStats, error)
- func (store *PostgresStore) PageOS(tenantID sql.NullInt64, path string, from time.Time, to time.Time) ([]OSStats, error)
- func (store *PostgresStore) PagePlatform(tenantID sql.NullInt64, path string, from time.Time, to time.Time) *VisitorStats
- func (store *PostgresStore) PageReferrer(tenantID sql.NullInt64, path string, from time.Time, to time.Time) ([]ReferrerStats, error)
- func (store *PostgresStore) PageVisitors(tenantID sql.NullInt64, path string, from, to time.Time) ([]Stats, error)
- func (store *PostgresStore) Paths(tenantID sql.NullInt64, from, to time.Time) ([]string, error)
- func (store *PostgresStore) Rollback(tx *sqlx.Tx)
- func (store *PostgresStore) SaveBrowserStats(tx *sqlx.Tx, entity *BrowserStats) error
- func (store *PostgresStore) SaveCountryStats(tx *sqlx.Tx, entity *CountryStats) error
- func (store *PostgresStore) SaveHits(hits []Hit) error
- func (store *PostgresStore) SaveLanguageStats(tx *sqlx.Tx, entity *LanguageStats) error
- func (store *PostgresStore) SaveOSStats(tx *sqlx.Tx, entity *OSStats) error
- func (store *PostgresStore) SaveReferrerStats(tx *sqlx.Tx, entity *ReferrerStats) error
- func (store *PostgresStore) SaveScreenStats(tx *sqlx.Tx, entity *ScreenStats) error
- func (store *PostgresStore) SaveVisitorStats(tx *sqlx.Tx, entity *VisitorStats) error
- func (store *PostgresStore) SaveVisitorTimeStats(tx *sqlx.Tx, entity *VisitorTimeStats) error
- func (store *PostgresStore) Session(tenantID sql.NullInt64, fingerprint string, maxAge time.Time) time.Time
- func (store *PostgresStore) VisitorBrowser(tenantID sql.NullInt64, from, to time.Time) ([]BrowserStats, error)
- func (store *PostgresStore) VisitorCountry(tenantID sql.NullInt64, from, to time.Time) ([]CountryStats, error)
- func (store *PostgresStore) VisitorHours(tenantID sql.NullInt64, from time.Time, to time.Time) ([]VisitorTimeStats, error)
- func (store *PostgresStore) VisitorLanguages(tenantID sql.NullInt64, from, to time.Time) ([]LanguageStats, error)
- func (store *PostgresStore) VisitorOS(tenantID sql.NullInt64, from, to time.Time) ([]OSStats, error)
- func (store *PostgresStore) VisitorPlatform(tenantID sql.NullInt64, from, to time.Time) *VisitorStats
- func (store *PostgresStore) VisitorReferrer(tenantID sql.NullInt64, from, to time.Time) ([]ReferrerStats, error)
- func (store *PostgresStore) VisitorScreenSize(tenantID sql.NullInt64, from, to time.Time) ([]ScreenStats, error)
- func (store *PostgresStore) Visitors(tenantID sql.NullInt64, from, to time.Time) ([]Stats, error)
- type Processor
- type ReferrerStats
- type ScreenStats
- type Stats
- type Store
- type TimeOfDayVisitors
- type Tracker
- type TrackerConfig
- type UserAgent
- type VisitorStats
- type VisitorTimeStats
Constants ¶
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 NullTenant = NewTenantID(0)
NullTenant can be used to pass no (null) tenant to filters and functions. This is a sql.NullInt64 with a value of 0.
Functions ¶
func Fingerprint ¶
Fingerprint returns a hash for given request and salt. The hash is unique for the visitor.
func GetGeoLite2 ¶ added in v1.6.0
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 IgnoreHit ¶ added in v1.3.0
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 NewTenantID ¶ added in v1.3.0
NewTenantID is a helper function to return a sql.NullInt64. The ID is considered valid if greater than 0.
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 Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer provides an interface to analyze processed data and hits.
func NewAnalyzer ¶
func NewAnalyzer(store Store, config *AnalyzerConfig) *Analyzer
NewAnalyzer returns a new Analyzer for given Store.
func (*Analyzer) ActiveVisitors ¶
func (analyzer *Analyzer) ActiveVisitors(filter *Filter, duration time.Duration) ([]Stats, int, error)
ActiveVisitors returns the active visitors per path and the total number of active visitors for given duration. Use time.Minute*5 for example to see the active visitors for the past 5 minutes. The correct date/time is not included.
func (*Analyzer) Browser ¶ added in v1.4.0
func (analyzer *Analyzer) Browser(filter *Filter) ([]BrowserStats, error)
Browser returns the visitor count per browser.
func (*Analyzer) Country ¶ added in v1.6.0
func (analyzer *Analyzer) Country(filter *Filter) ([]CountryStats, error)
Country returns the visitor count per country.
func (*Analyzer) Languages ¶
func (analyzer *Analyzer) Languages(filter *Filter) ([]LanguageStats, error)
Languages returns the visitor count per language.
func (*Analyzer) PageBrowser ¶ added in v1.5.0
func (analyzer *Analyzer) PageBrowser(filter *Filter) ([]BrowserStats, error)
PageBrowser returns the visitor count per brower, day, path, and for the given time frame. The path is mandatory.
func (*Analyzer) PageLanguages ¶ added in v1.5.0
func (analyzer *Analyzer) PageLanguages(filter *Filter) ([]LanguageStats, error)
PageLanguages returns the visitor count per language, day, path, and for the given time frame. The path is mandatory.
func (*Analyzer) PageOS ¶ added in v1.5.0
PageOS returns the visitor count per operating system, day, path, and for the given time frame. The path is mandatory.
func (*Analyzer) PagePlatform ¶ added in v1.5.0
func (analyzer *Analyzer) PagePlatform(filter *Filter) *VisitorStats
PagePlatform returns the visitor count per platform, day, path, and for the given time frame. The path is mandatory.
func (*Analyzer) PageReferrer ¶ added in v1.5.0
func (analyzer *Analyzer) PageReferrer(filter *Filter) ([]ReferrerStats, error)
PageReferrer returns the visitor count per referrer, day, path, and for the given time frame. The path is mandatory.
func (*Analyzer) PageVisitors ¶ added in v1.5.0
func (analyzer *Analyzer) PageVisitors(filter *Filter) ([]PathVisitors, error)
PageVisitors returns the visitor count, session count, and bounce rate per day for the given time frame grouped by path.
func (*Analyzer) Platform ¶ added in v1.4.0
func (analyzer *Analyzer) Platform(filter *Filter) *VisitorStats
Platform returns the visitor count per browser.
func (*Analyzer) Referrer ¶ added in v1.3.2
func (analyzer *Analyzer) Referrer(filter *Filter) ([]ReferrerStats, error)
Referrer returns the visitor count per referrer.
func (*Analyzer) Screen ¶ added in v1.6.0
func (analyzer *Analyzer) Screen(filter *Filter) ([]ScreenStats, error)
Screen returns the visitor count per screen size (width and height).
func (*Analyzer) TimeOfDay ¶ added in v1.7.0
func (analyzer *Analyzer) TimeOfDay(filter *Filter) ([]TimeOfDayVisitors, error)
TimeOfDay returns the visitor count per day and hour for given time frame.
func (*Analyzer) VisitorHours ¶ added in v1.5.0
func (analyzer *Analyzer) VisitorHours(filter *Filter) ([]VisitorTimeStats, error)
VisitorHours returns the visitor and session count grouped by hour of day for given time frame.
type AnalyzerConfig ¶ added in v1.7.0
type AnalyzerConfig struct { // Timezone sets the time zone for the result set. // If not set, UTC will be used. Timezone *time.Location }
AnalyzerConfig is the (optional) configuration for the Analyzer.
type BaseEntity ¶ added in v1.4.0
type BaseEntity struct { ID int64 `db:"id" json:"id"` TenantID sql.NullInt64 `db:"tenant_id" json:"tenant_id"` }
BaseEntity is the base entity for all other entities.
type BrowserStats ¶ added in v1.5.0
type BrowserStats struct { Stats Browser sql.NullString `db:"browser" json:"browser"` BrowserVersion sql.NullString `db:"browser_version" json:"version"` }
BrowserStats is the visitor count for each path on each day and browser.
type CountryStats ¶ added in v1.6.0
type CountryStats struct { Stats CountryCode sql.NullString `db:"country_code" json:"country_code"` }
CountryStats is the visitor count for each country on each day.
type Filter ¶
type Filter struct { // TenantID is the optional tenant ID used to filter results. TenantID sql.NullInt64 // Path is the optional path for the selection. Path string // From is the start of the selection. From time.Time // To is the end of the selection. To time.Time }
Filter is used to specify the time frame, path and tenant for the Analyzer.
type GeoDB ¶ added in v1.6.0
type GeoDB struct {
// contains filtered or unexported fields
}
GeoDB maps IPs to their geo location based on MaxMinds GeoLite2 or GeoIP2 database.
func NewGeoDB ¶ added in v1.6.0
NewGeoDB creates a new GeoDB for given database file. Make sure you call GeoDB.Close to release the system resources! If you use this in combination with GetGeoLite2, you should pass in the path to GeoLite2Filename (including the filename). The database should be updated on a regular basis.
func (*GeoDB) Close ¶ added in v1.6.0
Close closes the database file handle and frees the system resources. It's important to call this when you don't need the GeoDB anymore!
func (*GeoDB) CountryCode ¶ added in v1.6.0
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 Hit ¶
type Hit struct { BaseEntity Fingerprint string `db:"fingerprint" json:"fingerprint"` Session sql.NullTime `db:"session" json:"session"` Path sql.NullString `db:"path" json:"path,omitempty"` URL sql.NullString `db:"url" json:"url,omitempty"` Language sql.NullString `db:"language" json:"language,omitempty"` UserAgent sql.NullString `db:"user_agent" json:"user_agent,omitempty"` Referrer sql.NullString `db:"referrer" json:"referrer,omitempty"` OS sql.NullString `db:"os" json:"os,omitempty"` OSVersion sql.NullString `db:"os_version" json:"os_version,omitempty"` Browser sql.NullString `db:"browser" json:"browser,omitempty"` BrowserVersion sql.NullString `db:"browser_version" json:"browser_version,omitempty"` CountryCode sql.NullString `db:"country_code" json:"country_code"` Desktop bool `db:"desktop" json:"desktop"` Mobile bool `db:"mobile" json:"mobile"` ScreenWidth int `db:"screen_width" json:"screen_width"` ScreenHeight int `db:"screen_height" json:"screen_height"` Time time.Time `db:"time" json:"time"` }
Hit represents a single data point/page visit and is the central entity of pirsch.
func HitFromRequest ¶ added in v1.3.0
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 ¶ added in v1.2.0
type HitOptions struct { // TenantID is optionally saved with a hit to split the data between multiple tenants. TenantID sql.NullInt64 // 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 // Referrer can be set to manually overwrite the referrer from the request. Referrer string // ReferrerDomainBlacklist is used to filter out unwanted referrer 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 equally. 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 ¶ added in v1.6.0
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.TenantID).
type LanguageStats ¶ added in v1.5.0
type LanguageStats struct { Stats Language sql.NullString `db:"language" json:"language"` }
LanguageStats is the visitor count for each path on each day and language.
type OSStats ¶ added in v1.5.0
type OSStats struct { Stats OS sql.NullString `db:"os" json:"os"` OSVersion sql.NullString `db:"os_version" json:"version"` }
OSStats is the visitor count for each path on each day and operating system.
type PathVisitors ¶ added in v1.5.0
PathVisitors represents visitor statistics per day for a path.
type PostgresConfig ¶ added in v1.4.2
type PostgresConfig struct { // 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 }
PostgresConfig is the optional configuration for the PostgresStore.
type PostgresStore ¶
PostgresStore implements the Store interface.
func NewPostgresStore ¶
func NewPostgresStore(db *sql.DB, config *PostgresConfig) *PostgresStore
NewPostgresStore creates a new postgres storage for given database connection and logger.
func (*PostgresStore) ActivePageVisitors ¶ added in v1.5.1
func (store *PostgresStore) ActivePageVisitors(tenantID sql.NullInt64, from time.Time) ([]Stats, error)
ActivePageVisitors implements the Store interface.
func (*PostgresStore) ActiveVisitors ¶
ActiveVisitors implements the Store interface.
func (*PostgresStore) Commit ¶ added in v1.4.2
func (store *PostgresStore) Commit(tx *sqlx.Tx)
Commit implements the Store interface.
func (*PostgresStore) CountVisitors ¶ added in v1.5.0
func (store *PostgresStore) CountVisitors(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) *Stats
CountVisitors implements the Store interface.
func (*PostgresStore) CountVisitorsByBrowser ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByBrowser(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]BrowserStats, error)
CountVisitorsByBrowser implements the Store interface.
func (*PostgresStore) CountVisitorsByCountryCode ¶ added in v1.6.0
func (store *PostgresStore) CountVisitorsByCountryCode(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]CountryStats, error)
CountVisitorsByCountryCode implements the Store interface.
func (*PostgresStore) CountVisitorsByLanguage ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByLanguage(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]LanguageStats, error)
CountVisitorsByLanguage implements the Store interface.
func (*PostgresStore) CountVisitorsByOS ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByOS(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]OSStats, error)
CountVisitorsByOS implements the Store interface.
func (*PostgresStore) CountVisitorsByPath ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByPath(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string, includePlatform bool) ([]VisitorStats, error)
CountVisitorsByPath implements the Store interface.
func (*PostgresStore) CountVisitorsByPathAndBrowser ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByPathAndBrowser(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]BrowserStats, error)
CountVisitorsByPathAndBrowser implements the Store interface.
func (*PostgresStore) CountVisitorsByPathAndHour ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByPathAndHour(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]VisitorTimeStats, error)
CountVisitorsByPathAndHour implements the Store interface.
func (*PostgresStore) CountVisitorsByPathAndLanguage ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByPathAndLanguage(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]LanguageStats, error)
CountVisitorsByPathAndLanguage implements the Store interface.
func (*PostgresStore) CountVisitorsByPathAndMaxOneHit ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByPathAndMaxOneHit(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) int
CountVisitorsByPathAndMaxOneHit implements the Store interface.
func (*PostgresStore) CountVisitorsByPathAndOS ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByPathAndOS(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]OSStats, error)
CountVisitorsByPathAndOS implements the Store interface.
func (*PostgresStore) CountVisitorsByPathAndReferrer ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByPathAndReferrer(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time, path string) ([]ReferrerStats, error)
CountVisitorsByPathAndReferrer implements the Store interface.
func (*PostgresStore) CountVisitorsByPlatform ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByPlatform(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) *VisitorStats
CountVisitorsByPlatform implements the Store interface.
func (*PostgresStore) CountVisitorsByReferrer ¶ added in v1.5.0
func (store *PostgresStore) CountVisitorsByReferrer(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]ReferrerStats, error)
CountVisitorsByReferrer implements the Store interface.
func (*PostgresStore) CountVisitorsByScreenSize ¶ added in v1.6.0
func (store *PostgresStore) CountVisitorsByScreenSize(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) ([]ScreenStats, error)
CountVisitorsByScreenSize implements the Store interface.
func (*PostgresStore) DeleteHitsByDay ¶
func (store *PostgresStore) DeleteHitsByDay(tx *sqlx.Tx, tenantID sql.NullInt64, day time.Time) error
DeleteHitsByDay implements the Store interface.
func (*PostgresStore) NewTx ¶ added in v1.4.2
func (store *PostgresStore) NewTx() *sqlx.Tx
NewTx implements the Store interface.
func (*PostgresStore) PageBrowser ¶ added in v1.5.0
func (store *PostgresStore) PageBrowser(tenantID sql.NullInt64, path string, from time.Time, to time.Time) ([]BrowserStats, error)
PageBrowser implements the Store interface.
func (*PostgresStore) PageLanguages ¶ added in v1.5.0
func (store *PostgresStore) PageLanguages(tenantID sql.NullInt64, path string, from time.Time, to time.Time) ([]LanguageStats, error)
PageLanguages implements the Store interface.
func (*PostgresStore) PageOS ¶ added in v1.5.0
func (store *PostgresStore) PageOS(tenantID sql.NullInt64, path string, from time.Time, to time.Time) ([]OSStats, error)
PageOS implements the Store interface.
func (*PostgresStore) PagePlatform ¶ added in v1.5.0
func (store *PostgresStore) PagePlatform(tenantID sql.NullInt64, path string, from time.Time, to time.Time) *VisitorStats
PagePlatform implements the Store interface.
func (*PostgresStore) PageReferrer ¶ added in v1.5.0
func (store *PostgresStore) PageReferrer(tenantID sql.NullInt64, path string, from time.Time, to time.Time) ([]ReferrerStats, error)
PageReferrer implements the Store interface.
func (*PostgresStore) PageVisitors ¶ added in v1.5.0
func (store *PostgresStore) PageVisitors(tenantID sql.NullInt64, path string, from, to time.Time) ([]Stats, error)
PageVisitors implements the Store interface.
func (*PostgresStore) Rollback ¶ added in v1.4.2
func (store *PostgresStore) Rollback(tx *sqlx.Tx)
Rollback implements the Store interface.
func (*PostgresStore) SaveBrowserStats ¶ added in v1.5.0
func (store *PostgresStore) SaveBrowserStats(tx *sqlx.Tx, entity *BrowserStats) error
SaveBrowserStats implements the Store interface.
func (*PostgresStore) SaveCountryStats ¶ added in v1.6.0
func (store *PostgresStore) SaveCountryStats(tx *sqlx.Tx, entity *CountryStats) error
SaveCountryStats implements the Store interface.
func (*PostgresStore) SaveHits ¶ added in v1.5.0
func (store *PostgresStore) SaveHits(hits []Hit) error
SaveHits implements the Store interface.
func (*PostgresStore) SaveLanguageStats ¶ added in v1.5.0
func (store *PostgresStore) SaveLanguageStats(tx *sqlx.Tx, entity *LanguageStats) error
SaveLanguageStats implements the Store interface.
func (*PostgresStore) SaveOSStats ¶ added in v1.5.0
func (store *PostgresStore) SaveOSStats(tx *sqlx.Tx, entity *OSStats) error
SaveOSStats implements the Store interface.
func (*PostgresStore) SaveReferrerStats ¶ added in v1.5.0
func (store *PostgresStore) SaveReferrerStats(tx *sqlx.Tx, entity *ReferrerStats) error
SaveReferrerStats implements the Store interface.
func (*PostgresStore) SaveScreenStats ¶ added in v1.6.0
func (store *PostgresStore) SaveScreenStats(tx *sqlx.Tx, entity *ScreenStats) error
SaveScreenStats implements the Store interface.
func (*PostgresStore) SaveVisitorStats ¶ added in v1.5.0
func (store *PostgresStore) SaveVisitorStats(tx *sqlx.Tx, entity *VisitorStats) error
SaveVisitorStats implements the Store interface.
func (*PostgresStore) SaveVisitorTimeStats ¶ added in v1.5.0
func (store *PostgresStore) SaveVisitorTimeStats(tx *sqlx.Tx, entity *VisitorTimeStats) error
SaveVisitorTimeStats implements the Store interface.
func (*PostgresStore) Session ¶ added in v1.5.0
func (store *PostgresStore) Session(tenantID sql.NullInt64, fingerprint string, maxAge time.Time) time.Time
Session implements the Store interface.
func (*PostgresStore) VisitorBrowser ¶ added in v1.4.0
func (store *PostgresStore) VisitorBrowser(tenantID sql.NullInt64, from, to time.Time) ([]BrowserStats, error)
VisitorBrowser implements the Store interface.
func (*PostgresStore) VisitorCountry ¶ added in v1.6.0
func (store *PostgresStore) VisitorCountry(tenantID sql.NullInt64, from, to time.Time) ([]CountryStats, error)
VisitorCountry implements the Store interface.
func (*PostgresStore) VisitorHours ¶ added in v1.5.0
func (store *PostgresStore) VisitorHours(tenantID sql.NullInt64, from time.Time, to time.Time) ([]VisitorTimeStats, error)
VisitorHours implements the Store interface.
func (*PostgresStore) VisitorLanguages ¶
func (store *PostgresStore) VisitorLanguages(tenantID sql.NullInt64, from, to time.Time) ([]LanguageStats, error)
VisitorLanguages implements the Store interface.
func (*PostgresStore) VisitorOS ¶ added in v1.4.0
func (store *PostgresStore) VisitorOS(tenantID sql.NullInt64, from, to time.Time) ([]OSStats, error)
VisitorOS implements the Store interface.
func (*PostgresStore) VisitorPlatform ¶ added in v1.4.0
func (store *PostgresStore) VisitorPlatform(tenantID sql.NullInt64, from, to time.Time) *VisitorStats
VisitorPlatform implements the Store interface.
func (*PostgresStore) VisitorReferrer ¶ added in v1.3.2
func (store *PostgresStore) VisitorReferrer(tenantID sql.NullInt64, from, to time.Time) ([]ReferrerStats, error)
VisitorReferrer implements the Store interface.
func (*PostgresStore) VisitorScreenSize ¶ added in v1.6.0
func (store *PostgresStore) VisitorScreenSize(tenantID sql.NullInt64, from, to time.Time) ([]ScreenStats, error)
VisitorScreenSize implements the Store interface.
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor processes hits to reduce them into meaningful statistics.
func NewProcessor ¶
NewProcessor creates a new Processor for given Store.
type ReferrerStats ¶ added in v1.5.0
type ReferrerStats struct { Stats Referrer sql.NullString `db:"referrer" json:"referrer"` }
ReferrerStats is the visitor count for each path on each day and referrer.
type ScreenStats ¶ added in v1.6.0
type ScreenStats struct { Stats Width int `db:"width" json:"width"` Height int `db:"height" json:"height"` }
ScreenStats is the visitor count for each screen resolution on each day.
type Stats ¶ added in v1.4.0
type Stats struct { BaseEntity Day time.Time `db:"day" json:"day"` Path string `db:"path" json:"path"` Visitors int `db:"visitors" json:"visitors"` Sessions int `db:"sessions" json:"sessions"` Bounces int `db:"bounces" json:"bounces"` RelativeVisitors float64 `db:"-" json:"relative_visitors"` BounceRate float64 `db:"-" json:"bounce_rate"` }
Stats is the base entity for all statistics.
func (*Stats) GetVisitors ¶ added in v1.5.0
GetVisitors returns the visitor count.
type Store ¶
type Store interface { // NewTx creates a new transaction and panic on failure. NewTx() *sqlx.Tx // Commit commits given transaction and logs the error. Commit(*sqlx.Tx) // Rollback rolls back given transaction and logs the error. Rollback(*sqlx.Tx) // SaveHits persists a list of hits. SaveHits([]Hit) error // DeleteHitsByDay deletes all hits on given day. DeleteHitsByDay(*sqlx.Tx, sql.NullInt64, time.Time) error // SaveVisitorStats saves VisitorStats. SaveVisitorStats(*sqlx.Tx, *VisitorStats) error // SaveVisitorTimeStats saves VisitorTimeStats. SaveVisitorTimeStats(*sqlx.Tx, *VisitorTimeStats) error // SaveLanguageStats saves LanguageStats. SaveLanguageStats(*sqlx.Tx, *LanguageStats) error // SaveReferrerStats saves ReferrerStats. SaveReferrerStats(*sqlx.Tx, *ReferrerStats) error // SaveOSStats saves OSStats. SaveOSStats(*sqlx.Tx, *OSStats) error // SaveBrowserStats saves BrowserStats. SaveBrowserStats(*sqlx.Tx, *BrowserStats) error // SaveScreenStats saves ScreenStats. SaveScreenStats(*sqlx.Tx, *ScreenStats) error // SaveCountryStats saves CountryStats. SaveCountryStats(*sqlx.Tx, *CountryStats) error // Session returns the hits session timestamp for given fingerprint and max age. Session(sql.NullInt64, string, time.Time) time.Time // HitDays returns the distinct days with at least one hit. HitDays(sql.NullInt64) ([]time.Time, error) // HitPaths returns the distinct paths for given day. HitPaths(sql.NullInt64, time.Time) ([]string, error) // Paths returns the distinct paths for given time frame. Paths(sql.NullInt64, time.Time, time.Time) ([]string, error) // CountVisitors returns the visitor count for given day. CountVisitors(*sqlx.Tx, sql.NullInt64, time.Time) *Stats // CountVisitorsByPath returns the visitor count for given day, path, and if the platform should be included or not. CountVisitorsByPath(*sqlx.Tx, sql.NullInt64, time.Time, string, bool) ([]VisitorStats, error) // CountVisitorsByPathAndHour returns the visitor count for given day and path grouped by hour of day. CountVisitorsByPathAndHour(*sqlx.Tx, sql.NullInt64, time.Time, string) ([]VisitorTimeStats, error) // CountVisitorsByPathAndLanguage returns the visitor count for given day and path grouped by language. CountVisitorsByPathAndLanguage(*sqlx.Tx, sql.NullInt64, time.Time, string) ([]LanguageStats, error) // CountVisitorsByPathAndReferrer returns the visitor count for given day and path grouped by referrer. CountVisitorsByPathAndReferrer(*sqlx.Tx, sql.NullInt64, time.Time, string) ([]ReferrerStats, error) // CountVisitorsByPathAndOS returns the visitor count for given day and path grouped by operating system and operating system version. CountVisitorsByPathAndOS(*sqlx.Tx, sql.NullInt64, time.Time, string) ([]OSStats, error) // CountVisitorsByPathAndBrowser returns the visitor count for given day and path grouped by browser and browser version. CountVisitorsByPathAndBrowser(*sqlx.Tx, sql.NullInt64, time.Time, string) ([]BrowserStats, error) // CountVisitorsByLanguage returns the visitor count for given day grouped by language. CountVisitorsByLanguage(*sqlx.Tx, sql.NullInt64, time.Time) ([]LanguageStats, error) // CountVisitorsByReferrer returns the visitor count for given day grouped by referrer. CountVisitorsByReferrer(*sqlx.Tx, sql.NullInt64, time.Time) ([]ReferrerStats, error) // CountVisitorsByOS returns the visitor count for given day grouped by operating system. CountVisitorsByOS(*sqlx.Tx, sql.NullInt64, time.Time) ([]OSStats, error) // CountVisitorsByBrowser returns the visitor count for given day grouped by browser. CountVisitorsByBrowser(*sqlx.Tx, sql.NullInt64, time.Time) ([]BrowserStats, error) // CountVisitorsByScreenSize returns the visitor count for given day grouped by screen size (width and height). CountVisitorsByScreenSize(*sqlx.Tx, sql.NullInt64, time.Time) ([]ScreenStats, error) // CountVisitorsByCountryCode returns the visitor count for given day grouped by country code. CountVisitorsByCountryCode(*sqlx.Tx, sql.NullInt64, time.Time) ([]CountryStats, error) // CountVisitorsByPlatform returns the visitor count for given day grouped by platform. CountVisitorsByPlatform(*sqlx.Tx, sql.NullInt64, time.Time) *VisitorStats // CountVisitorsByPathAndMaxOneHit returns the visitor count for given day and optional path with a maximum of one hit. // This returns the absolut number of hits without further page calls and is used to calculate the bounce rate. CountVisitorsByPathAndMaxOneHit(*sqlx.Tx, sql.NullInt64, time.Time, string) int // ActiveVisitors returns the active visitor count for given duration. ActiveVisitors(sql.NullInt64, time.Time) int // ActivePageVisitors returns the active visitors grouped by path for given duration. ActivePageVisitors(sql.NullInt64, time.Time) ([]Stats, error) // Visitors returns the visitors for given time frame grouped by days. Visitors(sql.NullInt64, time.Time, time.Time) ([]Stats, error) // VisitorHours returns the visitors for given time frame grouped by hour of day. VisitorHours(sql.NullInt64, time.Time, time.Time) ([]VisitorTimeStats, error) // VisitorLanguages returns the visitors for given time frame grouped by language. VisitorLanguages(sql.NullInt64, time.Time, time.Time) ([]LanguageStats, error) // VisitorReferrer returns the visitor count for given time frame grouped by referrer. VisitorReferrer(sql.NullInt64, time.Time, time.Time) ([]ReferrerStats, error) // VisitorOS returns the visitor count for given time frame grouped by operating system. VisitorOS(sql.NullInt64, time.Time, time.Time) ([]OSStats, error) // VisitorBrowser returns the visitor count for given time frame grouped by browser. VisitorBrowser(sql.NullInt64, time.Time, time.Time) ([]BrowserStats, error) // VisitorPlatform returns the visitor count for given time frame grouped by platform. VisitorPlatform(sql.NullInt64, time.Time, time.Time) *VisitorStats // VisitorScreenSize returns the visitor count for given time frame grouped by screen size (width and height). VisitorScreenSize(sql.NullInt64, time.Time, time.Time) ([]ScreenStats, error) // VisitorCountry returns the visitor count for given time frame grouped by country code. VisitorCountry(sql.NullInt64, time.Time, time.Time) ([]CountryStats, error) // PageVisitors returns the visitors for given path and time frame grouped by days. PageVisitors(sql.NullInt64, string, time.Time, time.Time) ([]Stats, error) // PageReferrer returns the visitors for given path and time frame grouped by referrer. PageReferrer(sql.NullInt64, string, time.Time, time.Time) ([]ReferrerStats, error) // PageLanguages returns the visitors for given path and time frame grouped by language. PageLanguages(sql.NullInt64, string, time.Time, time.Time) ([]LanguageStats, error) // PageOS returns the visitors for given path and time frame grouped by operating system. PageOS(sql.NullInt64, string, time.Time, time.Time) ([]OSStats, error) // PageBrowser returns the visitors for given path and time frame grouped by browser. PageBrowser(sql.NullInt64, string, time.Time, time.Time) ([]BrowserStats, error) // PagePlatform returns the visitors for given path and time frame grouped by platform. PagePlatform(sql.NullInt64, string, time.Time, time.Time) *VisitorStats }
Store defines an interface to persists hits and other data. The first parameter (if required) is always the tenant ID and can be left out (pirsch.NullTenant), if you don't want to split your data. This is usually the case if you integrate Pirsch into your application.
type TimeOfDayVisitors ¶ added in v1.7.0
type TimeOfDayVisitors struct { Day time.Time Stats []VisitorTimeStats }
TimeOfDayVisitors represents the visitor count per day and hour for a path.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker is the main component of Pirsch. It provides methods to track requests and store them in a data store. Make sure you call Stop to make sure the hits get stored before shutting down the server.
func NewTracker ¶
func NewTracker(store Store, salt string, config *TrackerConfig) *Tracker
NewTracker creates a new tracker for given store, salt and config. Pass nil for the config to use the defaults. The salt is mandatory.
func (*Tracker) Flush ¶
func (tracker *Tracker) Flush()
Flush flushes all hits to store 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 store hits. // Must be greater or equal to 1. Worker int // WorkerBufferSize is the size of the buffer used to store 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 store hits. // This is used to allow the workers to store 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 limted to 60 seconds. WorkerTimeout time.Duration // ReferrerDomainBlacklist see HitOptions.ReferrerDomainBlacklist. ReferrerDomainBlacklist []string // ReferrerDomainBlacklistIncludesSubdomains see HitOptions.ReferrerDomainBlacklistIncludesSubdomains. ReferrerDomainBlacklistIncludesSubdomains bool // Sessions enables/disables session tracking. // It's enabled by default. Sessions bool // SessionMaxAge is used to define how long a session runs at maximum. // Set to two hours by default. SessionMaxAge time.Duration // SessionCleanupInterval sets the session cache lifetime. // If not passed, the default will be used. SessionCleanupInterval 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 UserAgent ¶ added in v1.4.0
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 ¶ added in v1.4.0
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 VisitorStats ¶ added in v1.5.0
type VisitorStats struct { Stats 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:"-" json:"relative_platform_desktop"` RelativePlatformMobile float64 `db:"-" json:"relative_platform_mobile"` RelativePlatformUnknown float64 `db:"-" json:"relative_platform_unknown"` }
VisitorStats is the visitor count for each path on each day and platform and it is used to calculate the total visitor count for each day.
type VisitorTimeStats ¶ added in v1.5.0
VisitorTimeStats is the visitor count for each path on each day and hour (ranging from 0 to 23).