model

package
v0.0.0-...-efb7428 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryCommerce = "commerce"
	TableCommerce    = "commerce"
)

Exported constants for services writing to EventStorage indirectly (e.g. Kafka).

View Source
const (
	CategoryPageview        = "pageview"
	ActionPageviewLoad      = "load"
	ActionPageviewTimespent = "timespent"
	ActionPageviewProgress  = "progress"
	UniqueCountBrowsers     = "browsers"
	UniqueCountUsers        = "users"
	TablePageviews          = "pageviews"
	TableTimespent          = "pageviews_time_spent"
	TableProgress           = "pageviews_progress"
	FlagArticle             = "_article"
)

Exported constants for services writing to EventStorage indirectly (e.g. Kafka) and reading from enumerated values.

View Source
const (
	TableConcurrents = "concurrents_by_browser"
)

Exported constants

View Source
const (
	TableEntities = "entities"
)

Exported constants for services writing to EventStorage indirectly (e.g. Kafka).

View Source
const (
	TableEvents = "events_v2"
)

Exported constants for services writing to EventStorage indirectly (e.g. Kafka).

Variables

This section is empty.

Functions

func Webalize

func Webalize(s string) (string, error)

Webalize replaces all spaces with dash and removes all non-alphanumerical characters.

Types

type AggregateOptions

type AggregateOptions struct {
	Category       string
	Action         string
	Step           string
	FilterBy       []*FilterBy
	GroupBy        []string
	TimeAfter      time.Time
	TimeBefore     time.Time
	TimeHistogram  *TimeHistogram
	CountHistogram *CountHistogram
}

AggregateOptions represent filter options for aggregate-related calls.

type AvgRow

type AvgRow struct {
	Tags          map[string]string
	Avg           float64
	TimeHistogram []TimeHistogramItem
}

AvgRow represents one row of grouped sum.

type AvgRowCollection

type AvgRowCollection []AvgRow

AvgRowCollection represents collection of rows of grouped sum.

type BrowserSet

type BrowserSet map[string]bool

BrowserSet is set of Browser keyed by browserID.

type Commerce

type Commerce struct {
	ID          string
	Step        string
	Token       string
	Time        time.Time
	Host        string
	IP          string
	UserID      string  `json:"user_id"`
	URL         string  `json:"url"`
	UserAgent   string  `json:"user_agent"`
	FunnelID    string  `json:"funnel_id"`
	ProductIDs  string  `json:"product_ids"`
	Revenue     float64 `json:"revenue"`
	Currency    string  `json:"currency"`
	UtmCampaign string  `json:"utm_campaign"`
	UtmContent  string  `json:"utm_content"`
	UtmMedium   string  `json:"utm_medium"`
	UtmSource   string  `json:"utm_source"`
}

Commerce represents commerce event data.

type CommerceElastic

type CommerceElastic struct {
	DB *ElasticDB
}

CommerceElastic is ElasticDB implementation of CommerceStorage.

func (*CommerceElastic) Actions

func (cDB *CommerceElastic) Actions(category string) ([]string, error)

Actions lists all available actions under the given category.

func (*CommerceElastic) Categories

func (cDB *CommerceElastic) Categories() ([]string, error)

Categories lists all available categories.

func (*CommerceElastic) Count

Count returns count of events based on the provided filter options.

func (*CommerceElastic) Flags

func (cDB *CommerceElastic) Flags() []string

Flags lists all available flags.

func (*CommerceElastic) List

List returns list of all events based on given CommerceOptions.

func (*CommerceElastic) Sum

Sum returns sum of events based on the provided filter options.

type CommerceOptions

type CommerceOptions struct {
	IDs        []string
	FilterBy   FilterType
	Group      bool
	Step       string
	TimeAfter  time.Time
	TimeBefore time.Time
}

CommerceOptions represent filter options for commerce-related calls.

type CommerceRow

type CommerceRow struct {
	Commerces []*Commerce
	Tags      map[string]string
}

CommerceRow represents one row of grouped list.

type CommerceRowCollection

type CommerceRowCollection []*CommerceRow

CommerceRowCollection represents collection of rows of grouped list.

type CommerceStorage

type CommerceStorage interface {
	// Count returns count of events based on the provided filter options.
	Count(o AggregateOptions) (CountRowCollection, bool, error)
	// Sum returns sum of events based on the provided filter options.
	Sum(o AggregateOptions) (SumRowCollection, bool, error)
	// List returns list of all events based on given CommerceOptions.
	List(o ListOptions) (CommerceRowCollection, error)
	// Categories lists all available categories.
	Categories() ([]string, error)
	// Flags lists all available flags.
	Flags() []string
	// Actions lists all available actions under the given category.
	Actions(category string) ([]string, error)
}

CommerceStorage is an interface to get commerce event related data.

type ConcurrentElastic

type ConcurrentElastic struct {
	DB *ElasticDB
	// contains filtered or unexported fields
}

ConcurrentElastic is ElasticDB implementation of ConcurrentStorage.

func (*ConcurrentElastic) Count

Count returns number of Concurrents matching the filter defined by AggregateOptions.

type ConcurrentsStorage

type ConcurrentsStorage interface {
	// Count returns count of concurrents based on the provided filter options.
	Count(o AggregateOptions) (CountRowCollection, bool, error)
}

ConcurrentsStorage is an interface to get data about last concurrent connections.

type CountHistogram

type CountHistogram struct {
	Field    string
	Interval float64
}

CountHistogram is used to split count of matched results based on provided Field within specified Interval.

type CountHistogramItem

type CountHistogramItem struct {
	BucketKey float64
	Value     float64
}

CountHistogramItem represents one row of count-based histogram results.

type CountRow

type CountRow struct {
	Tags           map[string]string
	Count          int
	TimeHistogram  []TimeHistogramItem
	CountHistogram []CountHistogramItem
}

CountRow represents one row of grouped count.

type CountRowCollection

type CountRowCollection []CountRow

CountRowCollection represents collection of rows of grouped count.

type ElasticDB

type ElasticDB struct {
	Client  *elastic.Client
	Debug   bool
	Context context.Context
	// contains filtered or unexported fields
}

ElasticDB represents data layer based on ElasticSearch.

func NewElasticDB

func NewElasticDB(ctx context.Context, client *elastic.Client, debug bool) *ElasticDB

NewElasticDB returns new instance of ElasticSearch DB implementation

func (*ElasticDB) UnwrapAggregation

func (eDB *ElasticDB) UnwrapAggregation(docCount int64, aggregations elastic.Aggregations, groupBy []string, tags map[string]string, cb UnwrapCallback) error

UnwrapAggregation traverses through all the aggregations and calls the provided callback on the lowest level providing tags of the fields and resulting count.

func (*ElasticDB) WrapAggregation

func (eDB *ElasticDB) WrapAggregation(index string, groupBy []string, search *elastic.SearchService,
	extras map[string]elastic.Aggregation, dateHistogramAgg *elastic.DateHistogramAggregation, agg *elastic.TermsAggregation) (*elastic.SearchService, *elastic.TermsAggregation, error)

WrapAggregation recursivelly wraps aggregations based on provided groupBy fields.

It includes any extra aggregations on the lowest level.

Initially the implementation used ElasticDB::addCompositeGroupBy(), but it was a beta feature and elastic didn't allow us to link sum aggregation to the results.

Following is a standard wrapping via SubAggregation() endorsed by official docs.

type EntitySchema

type EntitySchema struct {
	ID        int            `db:"id"`
	ParentID  sql.NullInt64  `db:"parent_id"`
	Name      string         `db:"name"`
	CreatedAt time.Time      `db:"created_at"`
	UpdatedAt mysql.NullTime `db:"updated_at"`
	DeletedAt mysql.NullTime `db:"deleted_at"`

	Params map[string]*EntitySchemaParam
}

EntitySchema represents definition of Entity.

type EntitySchemaCollection

type EntitySchemaCollection []*EntitySchema

EntitySchemaCollection is list of EntitySchemas.

type EntitySchemaDB

type EntitySchemaDB struct {
	MySQL    *sqlx.DB
	Entities map[string]*EntitySchema
}

EntitySchemaDB represents EntitySchemaStorage MySQL implementation.

func (*EntitySchemaDB) Cache

func (eDB *EntitySchemaDB) Cache() error

Cache caches entity definitions.

func (*EntitySchemaDB) Get

func (eDB *EntitySchemaDB) Get(name string) (*EntitySchema, bool, error)

Get returns EntitySchema based on provided EntityName.

type EntitySchemaParam

type EntitySchemaParam struct {
	Name string
	Type string
}

EntitySchemaParam represents single parameter of EntitySchema.

type EntitySchemaParamsCollection

type EntitySchemaParamsCollection []*EntitySchemaParam

EntitySchemaParamsCollection is list of EntitySchemaParams.

type EntitySchemaStorage

type EntitySchemaStorage interface {
	// Get returns EntitySchema based on provided EntityName.
	Get(name string) (*EntitySchema, bool, error)
	// Cache caches entity definitions.
	Cache() error
}

EntitySchemaStorage represents schemas storage interaface.

type Event

type Event struct {
	ID        string
	Category  string    `json:"category"`
	Action    string    `json:"action"`
	Token     string    `json:"token"`
	Time      time.Time `json:"time"`
	Host      string    `json:"host"`
	IP        string    `json:"ip"`
	UserID    string    `json:"user_id"`
	URL       string    `json:"url"`
	UserAgent string    `json:"user_agent"`
	ArticleID string    `json:"article_id"`

	UtmSource   string `json:"utm_source"`
	UtmCampaign string `json:"utm_campaign"`
	UtmContent  string `json:"utm_content"`
	UtmMedium   string `json:"utm_medium"`
}

Event represents event data.

type EventElastic

type EventElastic struct {
	DB *ElasticDB
	// contains filtered or unexported fields
}

EventElastic is ElasticDB implementation of EventStorage.

func (*EventElastic) Actions

func (eDB *EventElastic) Actions(category string) ([]string, error)

Actions lists all tracked actions under the given category.

func (*EventElastic) Cache

func (eDB *EventElastic) Cache() error

Cache stores event categories and activities in memory.

func (*EventElastic) Categories

func (eDB *EventElastic) Categories() ([]string, error)

Categories lists all tracked categories.

func (*EventElastic) Count

func (eDB *EventElastic) Count(options AggregateOptions) (CountRowCollection, bool, error)

Count returns number of events matching the filter defined by EventOptions.

func (*EventElastic) Flags

func (eDB *EventElastic) Flags() []string

Flags lists all available flags.

func (*EventElastic) List

func (eDB *EventElastic) List(options ListOptions) (EventRowCollection, error)

List returns list of all events based on given EventOptions.

func (*EventElastic) Users

func (eDB *EventElastic) Users() ([]string, error)

Users lists all tracked users.

type EventOptions

type EventOptions struct {
	UserID     string
	Action     string
	Category   string
	TimeAfter  time.Time
	TimeBefore time.Time
}

EventOptions represent filter options for event-related calls.

type EventRow

type EventRow struct {
	Tags   map[string]string
	Events []*Event
}

EventRow represents one row of grouped list.

type EventRowCollection

type EventRowCollection []*EventRow

EventRowCollection represents collection of rows of grouped list.

type EventRules

type EventRules map[string][]int

EventRules represent map of rules with given "category/event" assigned

type EventStorage

type EventStorage interface {
	// Count returns number of events matching the filter defined by EventOptions.
	Count(o AggregateOptions) (CountRowCollection, bool, error)
	// List returns list of all events based on given EventOptions.
	List(o ListOptions) (EventRowCollection, error)
	// Categories lists all tracked categories.
	Categories() ([]string, error)
	// Flags lists all available flags.
	Flags() []string
	// Actions lists all tracked actions under the given category.
	Actions(category string) ([]string, error)
	// Users lists all tracked users.
	Users() ([]string, error)
	// Cache creates internal cache of available categories and actions so they're not polled repeatedly.
	Cache() error
}

EventStorage is an interface to get generic event related data.

type FilterBy

type FilterBy struct {
	Tag     string
	Values  []string
	Inverse bool
}

FilterBy represents tag and values used to filter results of count-related calls.

type FilterType

type FilterType string

FilterType represents special enum layer for data filtering.

func NewFilterType

func NewFilterType(t string) (FilterType, error)

NewFilterType validates support for provided type and returns FilterType instance.

type Flags

type Flags map[int]map[string]string

Flags represent array of flags keyed by Rule ID.

type Intersector

type Intersector func(userID string) bool

Intersector responds to ability to intersect provided userID with some other collection structure.

type JSONMap

type JSONMap []map[string]string

JSONMap represents key-value string pairs stored as string JSON [{"key": "foo", "value": "bar"}].

func (*JSONMap) Scan

func (jm *JSONMap) Scan(src interface{}) error

Scan populates JSONMap based on scanned value.

func (JSONMap) Value

func (jm JSONMap) Value() (driver.Value, error)

Value returns JSON-encoded value of JSONMap.

type ListOptions

type ListOptions struct {
	AggregateOptions
	SelectFields []string
}

ListOptions represent select and filter options for listing-related calls.

type ListPageviewsOptions

type ListPageviewsOptions struct {
	AggregateOptions
	SelectFields  []string
	LoadTimespent bool
}

ListPageviewsOptions represents select and filter options for listing of pageviews

type OverridableFields

type OverridableFields map[int][]string

OverridableFields represent array of fields (key-value pairs) keyed by Rule ID.

type PCEStorage

type PCEStorage interface {
	// Categories lists all tracked categories.
	Categories() ([]string, error)
	// Actions lists all tracked actions under the given category.
	Actions(category string) ([]string, error)
}

PCEStorage is interface which ensures provided storage (Pageview/Commerce/Event) can return categories and actions of given category.

type Pageview

type Pageview struct {
	ID            string
	ArticleID     string `json:"article_id"`
	ArticleLocked bool   `json:"locked"`
	TitleVariant  string `json:"title_variant"`
	ImageVariant  string `json:"image_variant"`
	AuthorID      string `json:"author_id"`
	UTMSource     string `json:"utm_source"`
	UTMCampaign   string `json:"utm_campaign"`
	UTMMedium     string `json:"utm_medium"`
	UTMContent    string `json:"utm_content"`

	Token        string    `json:"token"`
	Time         time.Time `json:"time"`
	IP           string    `json:"ip"`
	UserID       string    `json:"user_id"`
	URL          string    `json:"url"`
	UserAgent    string    `json:"user_agent"`
	BrowserID    string    `json:"browser_id"`
	SessionID    string    `json:"remp_session_id"`
	Referer      string    `json:"referer"`
	Cookies      bool      `json:"cookies"`
	SignedIn     bool      `json:"signed_in"`
	Subscriber   bool      `json:"subscriber"`
	WindowWidth  int       `json:"window_width"`
	WindowHeight int       `json:"window_height"`
	Timespent    int       `json:"timespent"`
}

Pageview represents pageview data.

type PageviewElastic

type PageviewElastic struct {
	DB *ElasticDB
	// contains filtered or unexported fields
}

PageviewElastic is ElasticDB implementation of PageviewStorage.

func (*PageviewElastic) Actions

func (pDB *PageviewElastic) Actions(category string) ([]string, error)

Actions lists all tracked actions under the given category.

func (*PageviewElastic) Avg

Avg returns average count of Pageviews/Timespent records matching the filter defined by AggregateOptions.

func (*PageviewElastic) Categories

func (pDB *PageviewElastic) Categories() ([]string, error)

Categories lists all tracked categories.

func (*PageviewElastic) Count

Count returns number of Pageviews matching the filter defined by PageviewOptions.

func (*PageviewElastic) Flags

func (pDB *PageviewElastic) Flags() []string

Flags lists all available flags.

func (*PageviewElastic) List

List returns list of all Pageviews based on given PageviewOptions.

func (*PageviewElastic) Sum

Sum returns number of Pageviews matching the filter defined by AggregateOptions.

func (*PageviewElastic) Unique

func (pDB *PageviewElastic) Unique(options AggregateOptions, item string) (CountRowCollection, bool, error)

Unique returns unique count of Pageviews records matching the filter defined by AggregateOptions.

func (*PageviewElastic) Users

func (pDB *PageviewElastic) Users() ([]string, error)

Users lists all tracked users.

type PageviewOptions

type PageviewOptions struct {
	Action     string
	IDs        []string
	FilterBy   string
	GroupBy    []string
	TimeAfter  time.Time
	TimeBefore time.Time
}

PageviewOptions represent filter options for pageview-related calls.

type PageviewRow

type PageviewRow struct {
	Tags      map[string]string
	Pageviews []*Pageview
}

PageviewRow represents one row of grouped list.

type PageviewRowCollection

type PageviewRowCollection []*PageviewRow

PageviewRowCollection represents collection of rows of grouped list.

type PageviewStorage

type PageviewStorage interface {
	// Count returns count of pageviews based on the provided filter options.
	Count(o AggregateOptions) (CountRowCollection, bool, error)
	// Sum returns sum of pageviews based on the provided filter options.
	Sum(o AggregateOptions) (SumRowCollection, bool, error)
	// Avg returns average of pageviews based on the provided filter options.
	Avg(o AggregateOptions) (AvgRowCollection, bool, error)
	// Unique returns unique count of given item based on the provided filter options.
	Unique(o AggregateOptions, item string) (CountRowCollection, bool, error)
	// List returns list of all pageviews based on given PageviewOptions.
	List(o ListPageviewsOptions) (PageviewRowCollection, error)
	// Categories lists all tracked categories.
	Categories() ([]string, error)
	// Flags lists all available flags.
	Flags() []string
	// Actions lists all tracked actions under the given category.
	Actions(category string) ([]string, error)
}

PageviewStorage is an interface to get pageview events related data.

type Property

type Property struct {
	ID        int
	UUID      string
	Name      string
	AccountID int       `db:"account_id"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

Property structure.

type PropertyCollection

type PropertyCollection []*Property

PropertyCollection is list of Properties.

type PropertyDB

type PropertyDB struct {
	MySQL      *sqlx.DB
	Properties map[string]*Property
}

PropertyDB represents Property's storage MySQL implementation.

func (*PropertyDB) Cache

func (pDB *PropertyDB) Cache() error

Cache stores the properties in memory.

func (*PropertyDB) Get

func (pDB *PropertyDB) Get(UUID string) (*Property, bool, error)

Get returns instance of Property based on the given UUID.

type PropertyStorage

type PropertyStorage interface {
	// Get returns instance of Property based on the given UUID.
	Get(UUID string) (*Property, bool, error)
}

PropertyStorage represents property's storage interface.

type RuleOverrides

type RuleOverrides struct {
	Fields map[string]string
}

RuleOverrides represent key-value string pairs for overriding stored tags in segment rules.

type Segment

type Segment struct {
	ID int
	SegmentData

	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`

	Group SegmentGroup  `db:"segment_group"`
	Rules []SegmentRule `db:"segment_rules"`
}

Segment structure.

type SegmentBlueprintDB

type SegmentBlueprintDB struct {
	EventStorage    EventStorage
	PageviewStorage PageviewStorage
	CommerceStorage CommerceStorage
}

SegmentBlueprintDB represents SegmentBlueprintStorage implementation.

func (*SegmentBlueprintDB) Get

Get returns all criteria / blueprint for creating new or editing segment.

type SegmentBlueprintStorage

type SegmentBlueprintStorage interface {
	// Get returns SegmentBlueprintTableCollection.
	Get() (SegmentBlueprintTableCollection, error)
}

SegmentBlueprintStorage represents interface for segment blueprint related interactions.

type SegmentBlueprintTable

type SegmentBlueprintTable struct {
	Table    string
	Fields   []string
	Criteria SegmentBlueprintTableCriterionCollection
}

SegmentBlueprintTable represents blueprint for one segment field (table).

type SegmentBlueprintTableCollection

type SegmentBlueprintTableCollection []*SegmentBlueprintTable

SegmentBlueprintTableCollection is list of SegmentBlueprintTable.

type SegmentBlueprintTableCriterion

type SegmentBlueprintTableCriterion struct {
	Key    string
	Label  string
	Params map[string]SegmentBlueprintTableCriterionParam
	Fields []string
}

SegmentBlueprintTableCriterion represents one criterion of segment blueprint.

type SegmentBlueprintTableCriterionCollection

type SegmentBlueprintTableCriterionCollection []*SegmentBlueprintTableCriterion

SegmentBlueprintTableCriterionCollection is list of SegmentBlueprintTableCriterion.

type SegmentBlueprintTableCriterionParam

type SegmentBlueprintTableCriterionParam struct {
	Type      string   `json:"type"`
	Required  bool     `json:"required"`
	Default   *string  `json:"default"`
	Help      string   `json:"help"`
	Label     string   `json:"label"`
	Group     *string  `json:"group"`
	Available []string `json:"available"`
}

SegmentBlueprintTableCriterionParam represents one parameter of Segment Criterion.

type SegmentCache

type SegmentCache map[int]*SegmentRuleCache

SegmentCache represents event count information for SegmentRules indexed by SegmentRule ID.

type SegmentCollection

type SegmentCollection []*Segment

SegmentCollection is list of Segments.

type SegmentCriteria

type SegmentCriteria struct {
	Version string
	Nodes   SegmentCriteriaOperatorNodeCollection
}

SegmentCriteria represents segment's criteria.

func (*SegmentCriteria) Scan

func (sc *SegmentCriteria) Scan(criteria string) error

Scan scans provided input to SegmentCriteria.

type SegmentCriteriaNode

type SegmentCriteriaNode struct {
	Type     string
	Key      string
	Negation bool
	Values   map[string]interface{}
}

SegmentCriteriaNode represents one node of segment's criteria.

type SegmentCriteriaNodeCollection

type SegmentCriteriaNodeCollection []SegmentCriteriaNode

SegmentCriteriaNodeCollection represents collection of SegmentCriteriaNode.

type SegmentCriteriaOperatorNode

type SegmentCriteriaOperatorNode struct {
	Type     string
	Operator string
	Nodes    SegmentCriteriaNodeCollection
}

SegmentCriteriaOperatorNode represents one operator node of criteria. TODO: merge SegmentCriteriaOperatorNode and SegmentCriteriaNode into one type?

type SegmentCriteriaOperatorNodeCollection

type SegmentCriteriaOperatorNodeCollection []SegmentCriteriaOperatorNode

SegmentCriteriaOperatorNodeCollection represents collection of SegmentCriteriaOperatorNode.

type SegmentCriteriaValuesDatetime

type SegmentCriteriaValuesDatetime struct {
	Type     string
	Absolute *SegmentCriteriaValuesDatetimeAbsolute
	Interval *SegmentCriteriaValuesDatetimeInterval
}

SegmentCriteriaValuesDatetime represents datetime type of criteria values.

func (*SegmentCriteriaValuesDatetime) Scan

func (scvd *SegmentCriteriaValuesDatetime) Scan(datetime interface{}) error

Scan scans datetime from values to SegmentCriteriaValuesDatetime type.

type SegmentCriteriaValuesDatetimeAbsolute

type SegmentCriteriaValuesDatetimeAbsolute map[string]string

SegmentCriteriaValuesDatetimeAbsolute represents absolute datetime type of criteria values.

type SegmentCriteriaValuesDatetimeInterval

type SegmentCriteriaValuesDatetimeInterval map[string]struct {
	Value int
	Unit  string
}

SegmentCriteriaValuesDatetimeInterval represents interval datetime type of criteria values.

type SegmentDB

type SegmentDB struct {
	MySQL                    *sqlx.DB
	CountCache               *cache.Cache
	EventStorage             EventStorage
	PageviewStorage          PageviewStorage
	CommerceStorage          CommerceStorage
	Segments                 map[string]*Segment
	ExplicitSegmentsUsers    map[string]UserSet
	ExplicitSegmentsBrowsers map[string]BrowserSet
}

SegmentDB represents Segment's storage implementation.

func (*SegmentDB) BuildRules

func (sDB *SegmentDB) BuildRules(s *Segment) ([]SegmentRule, bool, error)

BuildRules builds segment rules from segment criteria.

func (*SegmentDB) Cache

func (sDB *SegmentDB) Cache() error

Cache stores the segments in memory.

func (*SegmentDB) CacheExplicitSegments

func (sDB *SegmentDB) CacheExplicitSegments() error

CacheExplicitSegments caches segments data in memory

func (*SegmentDB) CheckBrowser

func (sDB *SegmentDB) CheckBrowser(segment *Segment, browserID string, now time.Time, cache SegmentCache, ro RuleOverrides) (SegmentCache, bool, error)

CheckBrowser verifies presence of browser within provided segment.

func (*SegmentDB) CheckUser

func (sDB *SegmentDB) CheckUser(segment *Segment, userID string, now time.Time, cache SegmentCache, ro RuleOverrides) (SegmentCache, bool, error)

CheckUser verifies presence of user within provided segment.

func (*SegmentDB) CountAll

func (sDB *SegmentDB) CountAll() (int, error)

CountAll returns count of unique tracked users.

func (*SegmentDB) Create

func (sDB *SegmentDB) Create(sd SegmentData) (*Segment, error)

Create creates new Segment from provided data and returns it.

func (*SegmentDB) EventRules

func (sDB *SegmentDB) EventRules() EventRules

EventRules returns map of rules assigned to given "category/event" key

func (*SegmentDB) Flags

func (sDB *SegmentDB) Flags() Flags

Flags returns array of flags available for rules.

func (*SegmentDB) Get

func (sDB *SegmentDB) Get(code string) (*Segment, bool, error)

Get returns instance of Segment based on the given code.

func (*SegmentDB) GetByID

func (sDB *SegmentDB) GetByID(id int) (*Segment, bool, error)

GetByID returns instance of Segment based on the given segment ID. TODO: how to get segment from sDB.Segments?

func (*SegmentDB) Groups

func (sDB *SegmentDB) Groups() (SegmentGroupCollection, error)

Groups returns all available segment groups configured via Beam admin.

func (*SegmentDB) List

func (sDB *SegmentDB) List() (SegmentCollection, error)

List returns all available segments configured via Beam admin.

func (*SegmentDB) OverridableFields

func (sDB *SegmentDB) OverridableFields() OverridableFields

OverridableFields returns array of fields that expect to be overriden when rule is checked.

func (*SegmentDB) Related

func (sDB *SegmentDB) Related(criteria SegmentCriteria) (SegmentCollection, error)

Related compares provided criteria to existing segments and returns segments with same criteria.

func (*SegmentDB) Update

func (sDB *SegmentDB) Update(id int, sd SegmentData) (*Segment, bool, error)

Update updates existing Segment from provided data and returns it.

func (*SegmentDB) Users

func (sDB *SegmentDB) Users(segment *Segment, now time.Time, ro RuleOverrides) ([]string, error)

Users return list of all users within segment.

type SegmentData

type SegmentData struct {
	Name           string
	Code           string
	Active         bool
	SegmentGroupID int `db:"segment_group_id"`
	Criteria       sql.NullString
}

SegmentData contains data of segment

type SegmentGroup

type SegmentGroup struct {
	ID        int
	Name      string
	Code      string
	Type      string
	Sorting   int
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

SegmentGroup represents metadata about group, in which Segments can be placed in.

type SegmentGroupCollection

type SegmentGroupCollection []*SegmentGroup

SegmentGroupCollection is list of SegmentGroups.

type SegmentRule

type SegmentRule struct {
	ID            int
	ParentID      sql.NullInt64 `db:"parent_id"`
	SegmentID     int           `db:"segment_id"`
	EventCategory string        `db:"event_category"`
	EventAction   string        `db:"event_action"`
	Timespan      sql.NullInt64
	Operator      string
	Operator2     *string
	Count         int
	Count2        *int
	CreatedAt     time.Time `db:"created_at"`
	UpdatedAt     time.Time `db:"updated_at"`
	Fields        JSONMap
	Flags         JSONMap

	Segment *Segment `db:"segment"`
	// contains filtered or unexported fields
}

SegmentRule represent single rule of a Segment

func (*SegmentRule) CacheDuration

func (sr *SegmentRule) CacheDuration(count int) (time.Duration, bool)

CacheDuration returns duration to cache the item for and whether the item should be cached at all.

func (*SegmentRule) Evaluate

func (sr *SegmentRule) Evaluate(count int) (bool, error)

Evaluate evaluates segment rule condition against provided count.

type SegmentRuleCache

type SegmentRuleCache struct {
	SyncedAt time.Time `json:"s"`
	Count    int       `json:"c"`
}

SegmentRuleCache represents event count information for single SegmentRule.

type SegmentStorage

type SegmentStorage interface {
	// Create creates new Segment from provided data and returns it.
	Create(sd SegmentData) (*Segment, error)
	// Update updates existing Segment from provided data and returns it.
	Update(id int, sd SegmentData) (*Segment, bool, error)
	// Get returns instance of Segment based on the given code.
	Get(code string) (*Segment, bool, error)
	// GetByID returns instance of Segment based on the given segment ID.
	GetByID(id int) (*Segment, bool, error)
	// List returns all available segments configured via Beam admin.
	List() (SegmentCollection, error)
	// Groups returns all available segment groups.
	Groups() (SegmentGroupCollection, error)
	// CheckUser verifies presence of user within provided segment.
	CheckUser(segment *Segment, userID string, now time.Time, cache SegmentCache, ro RuleOverrides) (SegmentCache, bool, error)
	// CheckBrowser verifies presence of browser within provided segment.
	CheckBrowser(segment *Segment, browserID string, now time.Time, cache SegmentCache, ro RuleOverrides) (SegmentCache, bool, error)
	// Users return list of all users within segment.
	Users(segment *Segment, now time.Time, ro RuleOverrides) ([]string, error)
	// CountAll returns count of unique tracked users.
	CountAll() (int, error)
	// EventRules returns map of rules assigned to given "category/event" key.
	EventRules() EventRules
	// OverridableFields returns array of fields that expect to be overriden when rule is checked.
	OverridableFields() OverridableFields
	// Flags returns array of flags available for rules.
	Flags() Flags
	// Related compares provided criteria to existing segments and returns segments with same criteria.
	Related(SegmentCriteria) (SegmentCollection, error)
	// BuildRules builds segment rules from segment criteria.
	BuildRules(segment *Segment) ([]SegmentRule, bool, error)
}

SegmentStorage represents interface to get segment related data.

type SumRow

type SumRow struct {
	Tags          map[string]string
	Sum           float64
	TimeHistogram []TimeHistogramItem
}

SumRow represents one row of grouped sum.

type SumRowCollection

type SumRowCollection []SumRow

SumRowCollection represents collection of rows of grouped sum.

type TimeHistogram

type TimeHistogram struct {
	Interval string
	Offset   string
	TimeZone *time.Location
}

TimeHistogram is used to split response to time-based buckets.

type TimeHistogramItem

type TimeHistogramItem struct {
	Time  time.Time
	Value float64
}

TimeHistogramItem represents one row of time-based histogram results.

type UnwrapCallback

type UnwrapCallback func(tags map[string]string, docCount int64, aggregations elastic.Aggregations) error

UnwrapCallback represents final callback that should be called when all aggregations are unwrapped and the final set of tags and count can be provided

type User

type User struct {
	ID    string
	Email string
}

User represents information about User in Segment.

type UserCollection

type UserCollection []*User

UserCollection is list of Users.

type UserSet

type UserSet map[string]bool

UserSet is set of Users keyed by userID.

Jump to

Keyboard shortcuts

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