Documentation ¶
Index ¶
- Variables
- func Fingerprint(r *http.Request, salt string) string
- func RunAtMidnight(f func())
- type Analyzer
- func (analyzer *Analyzer) ActiveVisitors(tenantID sql.NullInt64, d time.Duration) (int, error)
- func (analyzer *Analyzer) HourlyVisitors(filter *Filter) ([]HourlyVisitors, error)
- func (analyzer *Analyzer) Languages(filter *Filter) ([]VisitorLanguage, int, error)
- func (analyzer *Analyzer) PageVisits(filter *Filter) ([]PageVisits, error)
- func (analyzer *Analyzer) Visitors(filter *Filter) ([]VisitorsPerDay, error)
- type Filter
- type Hit
- type HitOptions
- type HourlyVisitors
- type PageVisits
- type PostgresStore
- func (store *PostgresStore) ActiveVisitors(tenantID sql.NullInt64, from time.Time) (int, error)
- func (store *PostgresStore) Days(tenantID sql.NullInt64) ([]time.Time, error)
- func (store *PostgresStore) DeleteHitsByDay(tenantID sql.NullInt64, day time.Time) error
- func (store *PostgresStore) HourlyVisitors(tenantID sql.NullInt64, from, to time.Time) ([]HourlyVisitors, error)
- func (store *PostgresStore) PageVisits(tenantID sql.NullInt64, path string, from, to time.Time) ([]VisitorsPerDay, error)
- func (store *PostgresStore) Paths(tenantID sql.NullInt64, from, to time.Time) ([]string, error)
- func (store *PostgresStore) Save(hits []Hit) error
- func (store *PostgresStore) SaveVisitorsPerDay(visitors *VisitorsPerDay) error
- func (store *PostgresStore) SaveVisitorsPerHour(visitors *VisitorsPerHour) error
- func (store *PostgresStore) SaveVisitorsPerLanguage(visitors *VisitorsPerLanguage) error
- func (store *PostgresStore) SaveVisitorsPerPage(visitors *VisitorsPerPage) error
- func (store *PostgresStore) VisitorLanguages(tenantID sql.NullInt64, from, to time.Time) ([]VisitorLanguage, error)
- func (store *PostgresStore) Visitors(tenantID sql.NullInt64, from, to time.Time) ([]VisitorsPerDay, error)
- func (store *PostgresStore) VisitorsPerDay(tenantID sql.NullInt64, day time.Time) (int, error)
- func (store *PostgresStore) VisitorsPerDayAndHour(tenantID sql.NullInt64, day time.Time) ([]VisitorsPerHour, error)
- func (store *PostgresStore) VisitorsPerLanguage(tenantID sql.NullInt64, day time.Time) ([]VisitorsPerLanguage, error)
- func (store *PostgresStore) VisitorsPerPage(tenantID sql.NullInt64, day time.Time) ([]VisitorsPerPage, error)
- type Processor
- type Store
- type Tracker
- type TrackerConfig
- type VisitorLanguage
- type VisitorsPerDay
- type VisitorsPerHour
- type VisitorsPerLanguage
- type VisitorsPerPage
Constants ¶
This section is empty.
Variables ¶
var NullTenant = sql.NullInt64{}
NullTenant can be used to pass no tenant to filters and functions.
Functions ¶
func Fingerprint ¶
Fingerprint returns a hash for given request and salt. The hash is unique for the visitor.
func RunAtMidnight ¶
func RunAtMidnight(f func())
RunAtMidnight calls given function on each day of month on midnight (UTC).
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer provides an interface to analyze processed data and hits.
func NewAnalyzer ¶
NewAnalyzer returns a new Analyzer for given Store.
func (*Analyzer) ActiveVisitors ¶
ActiveVisitors returns unique visitors last active within given duration.
func (*Analyzer) HourlyVisitors ¶
func (analyzer *Analyzer) HourlyVisitors(filter *Filter) ([]HourlyVisitors, error)
HourlyVisitors returns the absolute and relative visitor count per language for given time frame.
func (*Analyzer) Languages ¶
func (analyzer *Analyzer) Languages(filter *Filter) ([]VisitorLanguage, int, error)
Languages returns the absolute and relative visitor count per language for given time frame.
func (*Analyzer) PageVisits ¶
func (analyzer *Analyzer) PageVisits(filter *Filter) ([]PageVisits, error)
PageVisits returns the visitors per page per day for given time frame.
type Filter ¶
type Filter struct { // TenantID is the optional tenant ID used to filter results. TenantID sql.NullInt64 // 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 and tenant for the Analyzer.
type Hit ¶
type Hit struct { ID int64 `db:"id" json:"id"` TenantID sql.NullInt64 `db:"tenant_id" json:"tenant_id"` Fingerprint string `db:"fingerprint" json:"fingerprint"` Path string `db:"path" json:"path,omitempty"` URL string `db:"url" json:"url,omitempty"` Language string `db:"language" json:"language,omitempty"` UserAgent string `db:"user_agent" json:"user_agent,omitempty"` Ref string `db:"ref" json:"ref,omitempty"` Time time.Time `db:"time" json:"time"` }
Hit represents a single data point/page visit.
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 // Path can be specified to manually overwrite the path stored for the request. // This will also affect the URL. Path string }
HitOptions is used to manipulate the data saved on a hit.
type HourlyVisitors ¶
type HourlyVisitors struct { Hour int `db:"hour" json:"hour"` Visitors int `db:"visitors" json:"visitors"` }
HourlyVisitors is the unique visitor count per hour.
type PageVisits ¶
type PageVisits struct { Path string Visits []VisitorsPerDay }
PageVisits is the visitor count per day for each path.
type PostgresStore ¶
PostgresStore implements the Store interface.
func NewPostgresStore ¶
func NewPostgresStore(db *sql.DB) *PostgresStore
NewPostgresStore creates a new postgres storage for given database connection.
func (*PostgresStore) ActiveVisitors ¶
ActiveVisitors implements the Store interface.
func (*PostgresStore) DeleteHitsByDay ¶
DeleteHitsByDay implements the Store interface.
func (*PostgresStore) HourlyVisitors ¶
func (store *PostgresStore) HourlyVisitors(tenantID sql.NullInt64, from, to time.Time) ([]HourlyVisitors, error)
VisitorLanguages implements the Store interface.
func (*PostgresStore) PageVisits ¶
func (store *PostgresStore) PageVisits(tenantID sql.NullInt64, path string, from, to time.Time) ([]VisitorsPerDay, error)
PageVisits implements the Store interface.
func (*PostgresStore) Save ¶
func (store *PostgresStore) Save(hits []Hit) error
Save implements the Store interface.
func (*PostgresStore) SaveVisitorsPerDay ¶
func (store *PostgresStore) SaveVisitorsPerDay(visitors *VisitorsPerDay) error
SaveVisitorsPerDay implements the Store interface.
func (*PostgresStore) SaveVisitorsPerHour ¶
func (store *PostgresStore) SaveVisitorsPerHour(visitors *VisitorsPerHour) error
SaveVisitorsPerHour implements the Store interface.
func (*PostgresStore) SaveVisitorsPerLanguage ¶
func (store *PostgresStore) SaveVisitorsPerLanguage(visitors *VisitorsPerLanguage) error
SaveVisitorsPerLanguage implements the Store interface.
func (*PostgresStore) SaveVisitorsPerPage ¶
func (store *PostgresStore) SaveVisitorsPerPage(visitors *VisitorsPerPage) error
SaveVisitorsPerPage implements the Store interface.
func (*PostgresStore) VisitorLanguages ¶
func (store *PostgresStore) VisitorLanguages(tenantID sql.NullInt64, from, to time.Time) ([]VisitorLanguage, error)
VisitorLanguages implements the Store interface.
func (*PostgresStore) Visitors ¶
func (store *PostgresStore) Visitors(tenantID sql.NullInt64, from, to time.Time) ([]VisitorsPerDay, error)
Visitors implements the Store interface.
func (*PostgresStore) VisitorsPerDay ¶
VisitorsPerDay implements the Store interface.
func (*PostgresStore) VisitorsPerDayAndHour ¶
func (store *PostgresStore) VisitorsPerDayAndHour(tenantID sql.NullInt64, day time.Time) ([]VisitorsPerHour, error)
VisitorsPerDayAndHour implements the Store interface.
func (*PostgresStore) VisitorsPerLanguage ¶
func (store *PostgresStore) VisitorsPerLanguage(tenantID sql.NullInt64, day time.Time) ([]VisitorsPerLanguage, error)
VisitorsPerLanguage implements the Store interface.
func (*PostgresStore) VisitorsPerPage ¶
func (store *PostgresStore) VisitorsPerPage(tenantID sql.NullInt64, day time.Time) ([]VisitorsPerPage, error)
VisitorsPerPage 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.
func (*Processor) Process ¶
Process processes all hits in database and deletes them afterwards. It will panic in case of an error.
func (*Processor) ProcessTenant ¶ added in v1.2.0
ProcessTenant processes all hits in database for given tenant and deletes them afterwards. The tenant can be set to nil if you don't split your data (which is usually the case). It will panic in case of an error.
type Store ¶
type Store interface { // Save persists a list of hits. Save([]Hit) error // DeleteHitsByDay deletes all hits on given day. DeleteHitsByDay(sql.NullInt64, time.Time) error // SaveVisitorsPerDay persists unique visitors per day. SaveVisitorsPerDay(*VisitorsPerDay) error // SaveVisitorsPerHour persists unique visitors per day and hour. SaveVisitorsPerHour(*VisitorsPerHour) error // SaveVisitorsPerLanguage persists unique visitors per day and language. SaveVisitorsPerLanguage(*VisitorsPerLanguage) error // SaveVisitorsPerPage persists unique visitors per day and page. SaveVisitorsPerPage(*VisitorsPerPage) error // Days returns the days at least one hit exists for. Days(sql.NullInt64) ([]time.Time, error) // VisitorsPerDay returns the unique visitor count for per day. VisitorsPerDay(sql.NullInt64, time.Time) (int, error) // VisitorsPerHour returns the unique visitor count per day and hour. VisitorsPerDayAndHour(sql.NullInt64, time.Time) ([]VisitorsPerHour, error) // VisitorsPerLanguage returns the unique visitor count per language and day. VisitorsPerLanguage(sql.NullInt64, time.Time) ([]VisitorsPerLanguage, error) // VisitorsPerPage returns the unique visitor count per page and day. VisitorsPerPage(sql.NullInt64, time.Time) ([]VisitorsPerPage, error) // Paths returns distinct paths for page visits. // This does not include today. Paths(sql.NullInt64, time.Time, time.Time) ([]string, error) // Visitors returns the visitors within given time frame. // This does not include today. Visitors(sql.NullInt64, time.Time, time.Time) ([]VisitorsPerDay, error) // PageVisits returns the page visits within given time frame for given path. // This does not include today. PageVisits(sql.NullInt64, string, time.Time, time.Time) ([]VisitorsPerDay, error) // VisitorLanguages returns the languages within given time frame for unique visitors. // It does include today. VisitorLanguages(sql.NullInt64, time.Time, time.Time) ([]VisitorLanguage, error) // HourlyVisitors returns unique visitors per hour for given time frame. // It does include today. HourlyVisitors(sql.NullInt64, time.Time, time.Time) ([]HourlyVisitors, error) // ActiveVisitors returns unique visitors starting at given time. ActiveVisitors(sql.NullInt64, time.Time) (int, error) }
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 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. In case of an error it will panic.
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.
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. WorkerTimeout time.Duration }
TrackerConfig is the optional configuration for the Tracker.
type VisitorLanguage ¶
type VisitorLanguage struct { Language string `db:"language" json:"language"` Visitors int `db:"visitors" json:"visitors"` RelativeVisitors float64 `db:"-" json:"relative_visitors"` }
VisitorLanguage is the unique visitor count per language.
type VisitorsPerDay ¶
type VisitorsPerDay struct { ID int64 `db:"id" json:"id"` TenantID sql.NullInt64 `db:"tenant_id" json:"tenant_id"` Day time.Time `db:"day" json:"day"` Visitors int `db:"visitors" json:"visitors"` }
VisitorsPerDay is the unique visitor count per day.
type VisitorsPerHour ¶
type VisitorsPerHour struct { ID int64 `db:"id" json:"id"` TenantID sql.NullInt64 `db:"tenant_id" json:"tenant_id"` DayAndHour time.Time `db:"day_and_hour" json:"day_and_hour"` Visitors int `db:"visitors" json:"visitors"` }
VisitorsPerHour is the unique visitor count per hour and day.
type VisitorsPerLanguage ¶
type VisitorsPerLanguage struct { ID int64 `db:"id" json:"id"` TenantID sql.NullInt64 `db:"tenant_id" json:"tenant_id"` Day time.Time `db:"day" json:"day"` Language string `db:"language" json:"language"` Visitors int `db:"visitors" json:"visitors"` }
VisitorsPerLanguage is the unique visitor count per language and day.
type VisitorsPerPage ¶
type VisitorsPerPage struct { ID int64 `db:"id" json:"id"` TenantID sql.NullInt64 `db:"tenant_id" json:"tenant_id"` Day time.Time `db:"day" json:"day"` Path string `db:"path" json:"path"` Visitors int `db:"visitors" json:"visitors"` }
VisitorsPerPage is the unique visitor count per path and day.