Documentation ¶
Index ¶
- func Fingerprint(r *http.Request, salt string) string
- func RunAtMidnight(f func())
- type Analyzer
- func (analyzer *Analyzer) ActiveVisitors(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 HourlyVisitors
- type PageVisits
- type PostgresStore
- func (store *PostgresStore) ActiveVisitors(from time.Time) (int, error)
- func (store *PostgresStore) Days() ([]time.Time, error)
- func (store *PostgresStore) DeleteHitsByDay(day time.Time) error
- func (store *PostgresStore) HourlyVisitors(from, to time.Time) ([]HourlyVisitors, error)
- func (store *PostgresStore) PageVisits(path string, from, to time.Time) ([]VisitorsPerDay, error)
- func (store *PostgresStore) Paths(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(from, to time.Time) ([]VisitorLanguage, error)
- func (store *PostgresStore) Visitors(from, to time.Time) ([]VisitorsPerDay, error)
- func (store *PostgresStore) VisitorsPerDay(day time.Time) (int, error)
- func (store *PostgresStore) VisitorsPerDayAndHour(day time.Time) ([]VisitorsPerHour, error)
- func (store *PostgresStore) VisitorsPerLanguage(day time.Time) ([]VisitorsPerLanguage, error)
- func (store *PostgresStore) VisitorsPerPage(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 ¶
This section is empty.
Functions ¶
func Fingerprint ¶
Fingerprint returns a hash for given request and salt. The hash is unique for the visitor, not for the page.
func RunAtMidnight ¶
func RunAtMidnight(f func())
RunAtMidnight calls given function on each day of month on midnight.
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 Hit ¶
type Hit struct { ID int64 `db:"id" json:"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 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 ¶
func (store *PostgresStore) ActiveVisitors(from time.Time) (int, error)
ActiveVisitors implements the Store interface.
func (*PostgresStore) Days ¶
func (store *PostgresStore) Days() ([]time.Time, error)
Days implements the Store interface.
func (*PostgresStore) DeleteHitsByDay ¶
func (store *PostgresStore) DeleteHitsByDay(day time.Time) error
DeleteHitsByDay implements the Store interface.
func (*PostgresStore) HourlyVisitors ¶
func (store *PostgresStore) HourlyVisitors(from, to time.Time) ([]HourlyVisitors, error)
VisitorLanguages implements the Store interface.
func (*PostgresStore) PageVisits ¶
func (store *PostgresStore) PageVisits(path string, from, to time.Time) ([]VisitorsPerDay, error)
PageVisits implements the Store interface.
func (*PostgresStore) Paths ¶
func (store *PostgresStore) Paths(from, to time.Time) ([]string, error)
Paths 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(from, to time.Time) ([]VisitorLanguage, error)
VisitorLanguages implements the Store interface.
func (*PostgresStore) Visitors ¶
func (store *PostgresStore) Visitors(from, to time.Time) ([]VisitorsPerDay, error)
Visitors implements the Store interface.
func (*PostgresStore) VisitorsPerDay ¶
func (store *PostgresStore) VisitorsPerDay(day time.Time) (int, error)
VisitorsPerDay implements the Store interface.
func (*PostgresStore) VisitorsPerDayAndHour ¶
func (store *PostgresStore) VisitorsPerDayAndHour(day time.Time) ([]VisitorsPerHour, error)
VisitorsPerDayAndHour implements the Store interface.
func (*PostgresStore) VisitorsPerLanguage ¶
func (store *PostgresStore) VisitorsPerLanguage(day time.Time) ([]VisitorsPerLanguage, error)
VisitorsPerLanguage implements the Store interface.
func (*PostgresStore) VisitorsPerPage ¶
func (store *PostgresStore) VisitorsPerPage(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.
type Store ¶
type Store interface { // Save persists a list of hits. Save([]Hit) error // DeleteHitsByDay deletes all hits on given day. DeleteHitsByDay(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() ([]time.Time, error) // VisitorsPerDay returns the unique visitor count for per day. VisitorsPerDay(time.Time) (int, error) // VisitorsPerHour returns the unique visitor count per day and hour. VisitorsPerDayAndHour(time.Time) ([]VisitorsPerHour, error) // VisitorsPerLanguage returns the unique visitor count per language and day. VisitorsPerLanguage(time.Time) ([]VisitorsPerLanguage, error) // VisitorsPerPage returns the unique visitor count per page and day. VisitorsPerPage(time.Time) ([]VisitorsPerPage, error) // Paths returns distinct paths for page visits. // This does not include today. Paths(time.Time, time.Time) ([]string, error) // Visitors returns the visitors within given time frame. // This does not include today. Visitors(time.Time, time.Time) ([]VisitorsPerDay, error) // PageVisits returns the page visits within given time frame for given path. // This does not include today. PageVisits(string, time.Time, time.Time) ([]VisitorsPerDay, error) // VisitorLanguages returns the languages within given time frame for unique visitors. // It does include today. VisitorLanguages(time.Time, time.Time) ([]VisitorLanguage, error) // HourlyVisitors returns unique visitors per hour for given time frame. // It does include today. HourlyVisitors(time.Time, time.Time) ([]HourlyVisitors, error) // ActiveVisitors returns unique visitors starting at given time. ActiveVisitors(time.Time) (int, error) }
Store defines an interface to persists hits and other data.
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.
func (*Tracker) Hit ¶
Hit stores the given request. The request might be ignored if it meets certain conditions. The actions performed within this function run in their own goroutine, so you don't need to create one yourself.
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 or equal to 2. The hits are stored when the buffer size reaches half of its maximum. 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. // 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"` 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"` 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.