analyzer

package
v4.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FieldCount is a query result column.
	FieldCount = Field{

		Name: "count",
		// contains filtered or unexported fields
	}

	// FieldPath is a query result column.
	FieldPath = Field{

		Name: "path",
		// contains filtered or unexported fields
	}

	// FieldEntryPath is a query result column.
	FieldEntryPath = Field{

		Name: "entry_path",
		// contains filtered or unexported fields
	}

	// FieldEntries is a query result column.
	FieldEntries = Field{

		Name: "entries",
		// contains filtered or unexported fields
	}

	// FieldExitPath is a query result column.
	FieldExitPath = Field{

		Name: "exit_path",
		// contains filtered or unexported fields
	}

	// FieldExits is a query result column.
	FieldExits = Field{

		Name: "exits",
		// contains filtered or unexported fields
	}

	// FieldVisitors is a query result column.
	FieldVisitors = Field{

		Name: "visitors",
		// contains filtered or unexported fields
	}

	// FieldRelativeVisitors is a query result column.
	FieldRelativeVisitors = Field{

		Name: "relative_visitors",
		// contains filtered or unexported fields
	}

	// FieldCR is a query result column.
	FieldCR = Field{

		Name: "cr",
		// contains filtered or unexported fields
	}

	// FieldSessions is a query result column.
	FieldSessions = Field{

		Name: "sessions",
		// contains filtered or unexported fields
	}

	// FieldViews is a query result column.
	FieldViews = Field{

		Name: "views",
		// contains filtered or unexported fields
	}

	// FieldRelativeViews is a query result column.
	FieldRelativeViews = Field{

		Name: "relative_views",
		// contains filtered or unexported fields
	}

	// FieldBounces is a query result column.
	FieldBounces = Field{

		Name: "bounces",
		// contains filtered or unexported fields
	}

	// FieldBounceRate is a query result column.
	FieldBounceRate = Field{

		Name: "bounce_rate",
		// contains filtered or unexported fields
	}

	// FieldReferrer is a query result column.
	FieldReferrer = Field{

		Name: "referrer",
		// contains filtered or unexported fields
	}

	// FieldAnyReferrer is a query result column.
	FieldAnyReferrer = Field{

		Name: "referrer",
		// contains filtered or unexported fields
	}

	// FieldReferrerName is a query result column.
	FieldReferrerName = Field{

		Name: "referrer_name",
		// contains filtered or unexported fields
	}

	// FieldReferrerIcon is a query result column.
	FieldReferrerIcon = Field{

		Name: "referrer_icon",
		// contains filtered or unexported fields
	}

	// FieldLanguage is a query result column.
	FieldLanguage = Field{

		Name: "language",
		// contains filtered or unexported fields
	}

	// FieldCountryCity is a query result column.
	// This field can only be used in combination with the FieldCity.
	FieldCountryCity = Field{

		Name: "country_code",
		// contains filtered or unexported fields
	}

	// FieldCountry is a query result column.
	FieldCountry = Field{

		Name: "country_code",
		// contains filtered or unexported fields
	}

	// FieldCity is a query result column.
	FieldCity = Field{

		Name: "city",
		// contains filtered or unexported fields
	}

	// FieldBrowser is a query result column.
	FieldBrowser = Field{

		Name: "browser",
		// contains filtered or unexported fields
	}

	// FieldBrowserVersion is a query result column.
	FieldBrowserVersion = Field{

		Name: "browser_version",
		// contains filtered or unexported fields
	}

	// FieldOS is a query result column.
	FieldOS = Field{

		Name: "os",
		// contains filtered or unexported fields
	}

	// FieldOSVersion is a query result column.
	FieldOSVersion = Field{

		Name: "os_version",
		// contains filtered or unexported fields
	}

	// FieldScreenClass is a query result column.
	FieldScreenClass = Field{

		Name: "screen_class",
		// contains filtered or unexported fields
	}

	// FieldUTMSource is a query result column.
	FieldUTMSource = Field{

		Name: "utm_source",
		// contains filtered or unexported fields
	}

	// FieldUTMMedium is a query result column.
	FieldUTMMedium = Field{

		Name: "utm_medium",
		// contains filtered or unexported fields
	}

	// FieldUTMCampaign is a query result column.
	FieldUTMCampaign = Field{

		Name: "utm_campaign",
		// contains filtered or unexported fields
	}

	// FieldUTMContent is a query result column.
	FieldUTMContent = Field{

		Name: "utm_content",
		// contains filtered or unexported fields
	}

	// FieldUTMTerm is a query result column.
	FieldUTMTerm = Field{

		Name: "utm_term",
		// contains filtered or unexported fields
	}

	// FieldTitle is a query result column.
	FieldTitle = Field{

		Name: "title",
		// contains filtered or unexported fields
	}

	// FieldEntryTitle is a query result column.
	FieldEntryTitle = Field{

		Name: "title",
		// contains filtered or unexported fields
	}

	// FieldExitTitle is a query result column.
	FieldExitTitle = Field{

		Name: "title",
		// contains filtered or unexported fields
	}

	// FieldDay is a query result column.
	FieldDay = Field{

		Name: "day",
		// contains filtered or unexported fields
	}

	// FieldHour is a query result column.
	FieldHour = Field{

		Name: "hour",
		// contains filtered or unexported fields
	}

	// FieldEventName is a query result column.
	FieldEventName = Field{

		Name: "event_name",
		// contains filtered or unexported fields
	}

	// FieldEventMeta is a query result column.
	FieldEventMeta = Field{

		Name: "meta",
		// contains filtered or unexported fields
	}

	// FieldEventMetaKeys is a query result column.
	FieldEventMetaKeys = Field{

		Name: "meta_keys",
		// contains filtered or unexported fields
	}

	// FieldEventMetaValues is a query result column.
	FieldEventMetaValues = Field{

		Name: "meta_value",
		// contains filtered or unexported fields
	}

	// FieldEventTimeSpent is a query result column.
	FieldEventTimeSpent = Field{

		Name: "average_time_spent_seconds",
		// contains filtered or unexported fields
	}
)
View Source
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")
)

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct {
	Visitors     Visitors
	Pages        Pages
	Demographics Demographics
	Device       Device
	UTM          UTM
	Events       Events
	Time         Time
	Options      FilterOptions
	// contains filtered or unexported fields
}

Analyzer provides an interface to analyze statistics.

func NewAnalyzer

func NewAnalyzer(store db.Store, config *Config) *Analyzer

NewAnalyzer returns a new Analyzer for given Store.

type Config

type Config struct {
	// IsBotThreshold see HitOptions.IsBotThreshold.
	IsBotThreshold uint8

	// DisableBotFilter disables IsBotThreshold (otherwise these would be set to the default value).
	DisableBotFilter bool
}

Config is the optional configuration for the Analyzer.

type Demographics

type Demographics struct {
	// contains filtered or unexported fields
}

Demographics aggregates metadata statistics like the referrer, browser, and OS.

func (*Demographics) Cities

func (demographics *Demographics) Cities(filter *Filter) ([]model.CityStats, error)

Cities returns the visitor count grouped by city.

func (*Demographics) Countries

func (demographics *Demographics) Countries(filter *Filter) ([]model.CountryStats, error)

Countries returns the visitor count grouped by country.

func (*Demographics) Languages

func (demographics *Demographics) Languages(filter *Filter) ([]model.LanguageStats, error)

Languages returns the visitor count grouped by language.

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device aggregates device statistics.

func (*Device) Browser

func (device *Device) Browser(filter *Filter) ([]model.BrowserStats, error)

Browser returns the visitor count grouped by browser.

func (*Device) BrowserVersion

func (device *Device) BrowserVersion(filter *Filter) ([]model.BrowserVersionStats, error)

BrowserVersion returns the visitor count grouped by browser and version.

func (*Device) OS

func (device *Device) OS(filter *Filter) ([]model.OSStats, error)

OS returns the visitor count grouped by operating system.

func (*Device) OSVersion

func (device *Device) OSVersion(filter *Filter) ([]model.OSVersionStats, error)

OSVersion returns the visitor count grouped by operating systems and version.

func (*Device) Platform

func (device *Device) Platform(filter *Filter) (*model.PlatformStats, error)

Platform returns the visitor count grouped by platform.

func (*Device) ScreenClass

func (device *Device) ScreenClass(filter *Filter) ([]model.ScreenClassStats, error)

ScreenClass returns the visitor count grouped by screen class.

type Events

type Events struct {
	// contains filtered or unexported fields
}

Events aggregates statistics regarding events.

func (*Events) Breakdown

func (events *Events) Breakdown(filter *Filter) ([]model.EventStats, error)

Breakdown 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 (*Events) Events

func (events *Events) Events(filter *Filter) ([]model.EventStats, error)

Events returns the visitor count, views, and conversion rate for custom events.

func (*Events) List

func (events *Events) List(filter *Filter) ([]model.EventListStats, error)

List returns events as a list. The metadata is grouped as key-value pairs.

type Field

type Field struct {
	Name string
	// contains filtered or unexported fields
}

Field is a column for a query.

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

	// IncludeTime sets whether the selected period should contain the time (hour, minute, second).
	IncludeTime bool

	// Period sets the period to group results.
	// This is only used by Analyzer.ByPeriod, Analyzer.AvgSessionDuration, and Analyzer.AvgTimeOnPage.
	// Using it for other queries leads to wrong results and might return an error.
	// This can either be PeriodDay (default), PeriodWeek, or PeriodYear.
	Period pirsch.Period

	// Path filters for the path.
	// Note that if this and PathPattern are both set, Path will be preferred.
	Path []string

	// EntryPath filters for the entry page.
	EntryPath []string

	// ExitPath filters for the exit page.
	ExitPath []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

	// City filters for the city name.
	City []string

	// Referrer filters for the full referrer.
	Referrer []string

	// ReferrerName filters for the referrer name.
	ReferrerName []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

	// ScreenWidth filters for the screen width.
	ScreenWidth []string

	// ScreenHeight filters for the screen width.
	ScreenHeight []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

	// EventMeta filters for event metadata.
	EventMeta map[string]string

	// Search searches the results for given fields and inputs.
	Search []Search

	// Sort sorts the results.
	// This will overwrite the default order provided by the Analyzer.
	Sort []Sort

	// Offset limits the number of results. Less or equal to zero means no offset.
	Offset int

	// Limit limits the number of results. Less or equal to zero means no limit.
	Limit int

	// IncludeTitle indicates that the Analyzer.ByPath, Analyzer.Entry, and Analyzer.Exit should contain the page title.
	IncludeTitle bool

	// IncludeTimeOnPage indicates that the Analyzer.ByPath and Analyzer.Entry should contain the average time on page.
	IncludeTimeOnPage 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
	// contains filtered or unexported fields
}

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. To compare to none/unknown/empty, set the value to "null" (case-insensitive).

func NewFilter

func NewFilter(clientID int64) *Filter

NewFilter creates a new filter for given client ID.

type FilterOptions

type FilterOptions struct {
	// contains filtered or unexported fields
}

FilterOptions returns options that can be used to filter results. This includes distinct pages, referrers, ... for a given period. Common options, like the operating system or browser, are not read from the database.

func (*FilterOptions) Cities

func (options *FilterOptions) Cities(filter *Filter) ([]string, error)

Cities returns all cities.

func (*FilterOptions) Countries

func (options *FilterOptions) Countries(filter *Filter) ([]string, error)

Countries returns all countries.

func (*FilterOptions) Events

func (options *FilterOptions) Events(filter *Filter) ([]string, error)

Events returns all event names.

func (*FilterOptions) Languages

func (options *FilterOptions) Languages(filter *Filter) ([]string, error)

Languages returns all languages.

func (*FilterOptions) Pages

func (options *FilterOptions) Pages(filter *Filter) ([]string, error)

Pages returns all paths. This can also be used for the entry and exit pages.

func (*FilterOptions) Referrer

func (options *FilterOptions) Referrer(filter *Filter) ([]string, error)

Referrer returns all referrers.

func (*FilterOptions) ReferrerName

func (options *FilterOptions) ReferrerName(filter *Filter) ([]string, error)

ReferrerName returns all referrer names.

func (*FilterOptions) UTMCampaign

func (options *FilterOptions) UTMCampaign(filter *Filter) ([]string, error)

UTMCampaign returns all UTM campaigns.

func (*FilterOptions) UTMContent

func (options *FilterOptions) UTMContent(filter *Filter) ([]string, error)

UTMContent returns all UTM contents.

func (*FilterOptions) UTMMedium

func (options *FilterOptions) UTMMedium(filter *Filter) ([]string, error)

UTMMedium returns all UTM media.

func (*FilterOptions) UTMSource

func (options *FilterOptions) UTMSource(filter *Filter) ([]string, error)

UTMSource returns all UTM sources.

func (*FilterOptions) UTMTerm

func (options *FilterOptions) UTMTerm(filter *Filter) ([]string, error)

UTMTerm returns all UTM terms.

type Pages

type Pages struct {
	// contains filtered or unexported fields
}

Pages aggregates statistics regarding pages.

func (*Pages) ByPath

func (pages *Pages) ByPath(filter *Filter) ([]model.PageStats, error)

ByPath returns the visitor count, session count, bounce rate, views, and average time on page grouped by path and (optional) page title.

func (*Pages) Conversions

func (pages *Pages) Conversions(filter *Filter) (*model.PageConversionsStats, error)

Conversions 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 (*Pages) Entry

func (pages *Pages) Entry(filter *Filter) ([]model.EntryStats, error)

Entry returns the visitor count and time on page grouped by path and (optional) page title for the first page visited.

func (*Pages) Exit

func (pages *Pages) Exit(filter *Filter) ([]model.ExitStats, error)

Exit returns the visitor count and time on page grouped by path and (optional) page title for the last page visited.

type Search struct {
	Field Field
	Input string
}

Search filters results by searching for the given input for given field. The field needs to contain the search string and is performed case-insensitively.

type Sort

type Sort struct {
	Field     Field
	Direction pirsch.Direction
}

Sort sorts results by a field and direction.

type Time

type Time struct {
	// contains filtered or unexported fields
}

Time aggregates statistics regarding the time on page and session duration.

func (*Time) AvgSessionDuration

func (t *Time) AvgSessionDuration(filter *Filter) ([]model.TimeSpentStats, error)

AvgSessionDuration returns the average session duration grouped by day, week, month, or year.

func (*Time) AvgTimeOnPage

func (t *Time) AvgTimeOnPage(filter *Filter) ([]model.TimeSpentStats, error)

AvgTimeOnPage returns the average time on page grouped by day, week, month, or year.

type UTM

type UTM struct {
	// contains filtered or unexported fields
}

UTM aggregates UTM campaign statistics.

func (*UTM) Campaign

func (utm *UTM) Campaign(filter *Filter) ([]model.UTMCampaignStats, error)

Campaign returns the visitor count grouped by utm source.

func (*UTM) Content

func (utm *UTM) Content(filter *Filter) ([]model.UTMContentStats, error)

Content returns the visitor count grouped by utm source.

func (*UTM) Medium

func (utm *UTM) Medium(filter *Filter) ([]model.UTMMediumStats, error)

Medium returns the visitor count grouped by utm medium.

func (*UTM) Source

func (utm *UTM) Source(filter *Filter) ([]model.UTMSourceStats, error)

Source returns the visitor count grouped by utm source.

func (*UTM) Term

func (utm *UTM) Term(filter *Filter) ([]model.UTMTermStats, error)

Term returns the visitor count grouped by utm source.

type Visitors

type Visitors struct {
	// contains filtered or unexported fields
}

Visitors aggregates statistics regarding visitors.

func (*Visitors) Active

func (visitors *Visitors) Active(filter *Filter, duration time.Duration) ([]model.ActiveVisitorStats, int, error)

Active 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 (*Visitors) ByHour

func (visitors *Visitors) ByHour(filter *Filter) ([]model.VisitorHourStats, error)

ByHour returns the visitor count grouped by time of day.

func (*Visitors) ByPeriod

func (visitors *Visitors) ByPeriod(filter *Filter) ([]model.VisitorStats, error)

ByPeriod returns the visitor count, session count, bounce rate, and views grouped by day, week, month, or year.

func (*Visitors) Growth

func (visitors *Visitors) Growth(filter *Filter) (*model.Growth, error)

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 (*Visitors) Referrer

func (visitors *Visitors) Referrer(filter *Filter) ([]model.ReferrerStats, error)

Referrer returns the visitor count and bounce rate grouped by referrer.

func (*Visitors) Total

func (visitors *Visitors) Total(filter *Filter) (*model.TotalVisitorStats, error)

Total returns the total visitor count, session count, bounce rate, and views.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL