tracker

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TRACKER_VERSION = "golang-2.0.0"

	// POST Requests
	POST_PROTOCOL_VENDOR  = "com.snowplowanalytics.snowplow"
	POST_PROTOCOL_VERSION = "tp2"
	POST_CONTENT_TYPE     = "application/json; charset=utf-8"

	// GET Requests
	GET_PROTOCOL_PATH = "i"

	// Schema Versions
	SCHEMA_PAYLOAD_DATA   = "iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4"
	SCHEMA_CONTEXTS       = "iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-1"
	SCHEMA_UNSTRUCT_EVENT = "iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0"
	SCHEMA_SCREEN_VIEW    = "iglu:com.snowplowanalytics.snowplow/screen_view/jsonschema/1-0-0"
	SCHEMA_USER_TIMINGS   = "iglu:com.snowplowanalytics.snowplow/timing/jsonschema/1-0-0"

	// Event Types
	EVENT_PAGE_VIEW    = "pv"
	EVENT_STRUCTURED   = "se"
	EVENT_UNSTRUCTURED = "ue"
	EVENT_ECOMM        = "tr"
	EVENT_ECOMM_ITEM   = "ti"

	// General
	SCHEMA         = "schema"
	DATA           = "data"
	EVENT          = "e"
	EID            = "eid"
	TIMESTAMP      = "dtm"
	SENT_TIMESTAMP = "stm"
	TRUE_TIMESTAMP = "ttm"
	T_VERSION      = "tv"
	APP_ID         = "aid"
	NAMESPACE      = "tna"
	PLATFORM       = "p"

	CONTEXT              = "co"
	CONTEXT_ENCODED      = "cx"
	UNSTRUCTURED         = "ue_pr"
	UNSTRUCTURED_ENCODED = "ue_px"

	// Subject class
	UID         = "uid"
	RESOLUTION  = "res"
	VIEWPORT    = "vp"
	COLOR_DEPTH = "cd"
	TIMEZONE    = "tz"
	LANGUAGE    = "lang"
	IP_ADDRESS  = "ip"
	USERAGENT   = "ua"
	DOMAIN_UID  = "duid"
	NETWORK_UID = "tnuid"

	// Page View
	PAGE_URL   = "url"
	PAGE_TITLE = "page"
	PAGE_REFR  = "refr"

	// Structured Event
	SE_CATEGORY = "se_ca"
	SE_ACTION   = "se_ac"
	SE_LABEL    = "se_la"
	SE_PROPERTY = "se_pr"
	SE_VALUE    = "se_va"

	// Ecomm Transaction
	TR_ID          = "tr_id"
	TR_TOTAL       = "tr_tt"
	TR_AFFILIATION = "tr_af"
	TR_TAX         = "tr_tx"
	TR_SHIPPING    = "tr_sh"
	TR_CITY        = "tr_ci"
	TR_STATE       = "tr_st"
	TR_COUNTRY     = "tr_co"
	TR_CURRENCY    = "tr_cu"

	// Transaction Item
	TI_ITEM_ID       = "ti_id"
	TI_ITEM_SKU      = "ti_sk"
	TI_ITEM_NAME     = "ti_nm"
	TI_ITEM_CATEGORY = "ti_ca"
	TI_ITEM_PRICE    = "ti_pr"
	TI_ITEM_QUANTITY = "ti_qu"
	TI_ITEM_CURRENCY = "ti_cu"

	// Screen View
	SV_ID   = "id"
	SV_NAME = "name"

	// User Timing
	UT_CATEGORY = "category"
	UT_VARIABLE = "variable"
	UT_TIMING   = "timing"
	UT_LABEL    = "label"
)
View Source
const (
	DEFAULT_REQ_TYPE        = "POST"
	DEFAULT_PROTOCOL        = "http"
	DEFAULT_SEND_LIMIT      = 500
	DEFAULT_BYTE_LIMIT_GET  = 40000
	DEFAULT_BYTE_LIMIT_POST = 40000
	DEFAULT_DB_NAME         = "events.db"
	POST_WRAPPER_BYTES      = 88 // "schema":"iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-3","data":[]
	POST_STM_BYTES          = 22 // "stm":"1443452851000"
)
View Source
const (
	DB_DRIVER       = "sqlite3"
	DB_TABLE_NAME   = "events"
	DB_COLUMN_ID    = "id"
	DB_COLUMN_EVENT = "event"
)
View Source
const (
	DEFAULT_PLATFORM = "srv"
	DEFAULT_BASE_64  = true
)

Variables

This section is empty.

Functions

func CountBytesInString

func CountBytesInString(str string) int

CountBytesInString takes a string and gets a byte count.

func DeserializeMap

func DeserializeMap(b []byte) (map[string]string, error)

DeserializeMap takes a byte buffer and attempts to convert it back to a map.

func Float64ToString

func Float64ToString(value *float64, places int) string

Float64ToString does conversion of floats to string values.

func GetTimestamp

func GetTimestamp() int64

GetTimestamp returns the current unix timestamp in milliseconds

func GetTimestampString

func GetTimestampString() string

GetTimestampString returns the current unix timestamp in milliseconds

func GetUUID

func GetUUID() string

GetUUID generates a Version 4 UUID string.

func Int64ToString

func Int64ToString(value *int64) string

Int64ToString converts an Integer of 64 bits to a String.

func IntArrayToString

func IntArrayToString(values []int, delimiter string) string

IntArrayToString converts an array of integers to a string delimited by a string of your choice.

func IntToString

func IntToString(value int) string

IntToString converts an Integer to a String.

func MapToJson

func MapToJson(m interface{}) string

MapToString takes a generic and converts it to a JSON representation.

func MapToQueryParams

func MapToQueryParams(m map[string]string) url.Values

MapToQueryParams takes a map of string keys and values and builds an encoded query string.

func NewFloat64

func NewFloat64(val float64) *float64

NewFloat64 returns a pointer to a float64.

func NewInt64

func NewInt64(val int64) *int64

NewInt64 returns a pointer to an int64.

func NewString

func NewString(val string) *string

NewString returns a pointer to a string.

func OptionAppId

func OptionAppId(appId string) func(t *Tracker)

OptionAppId sets the Tracker Application ID

func OptionBase64Encode

func OptionBase64Encode(base64Encode bool) func(t *Tracker)

OptionBase64Encode sets the Tracker base64encode

func OptionByteLimitGet

func OptionByteLimitGet(byteLimitGet int) func(e *Emitter)

OptionByteLimitGet sets the byte limit for GET requests.

func OptionByteLimitPost

func OptionByteLimitPost(byteLimitPost int) func(e *Emitter)

OptionByteLimitPost sets the byte limit for POST requests.

func OptionCallback

func OptionCallback(callback func(successCount []CallbackResult, failureCount []CallbackResult)) func(e *Emitter)

OptionCallback sets a custom callback for the emitter loop.

func OptionDbName

func OptionDbName(dbName string) func(e *Emitter)

OptionDbName overrides the default name of the storage database.

func OptionNamespace

func OptionNamespace(namespace string) func(t *Tracker)

OptionNamespace sets the Tracker Namespace

func OptionPlatform

func OptionPlatform(platform string) func(t *Tracker)

OptionPlatform sets the Tracker Platform

func OptionProtocol

func OptionProtocol(protocol string) func(e *Emitter)

OptionProtocol sets the protocol type to use (http or https).

func OptionRequestType

func OptionRequestType(requestType string) func(e *Emitter)

OptionRequestType sets the request type to use (GET or POST).

func OptionSendLimit

func OptionSendLimit(sendLimit int) func(e *Emitter)

OptionSendLimit sets the send limit for the emitter.

func OptionStorage

func OptionStorage(storage Storage) func(e *Emitter)

OptionStorage sets a custom event Storage target which implements the Storage interface

Note: If this option is used OptionDbName will be ignored

func OptionSubject

func OptionSubject(subject *Subject) func(t *Tracker)

OptionSubject sets the Tracker Subject

func RequireCollectorUri

func RequireCollectorUri(collectorUri string) func(e *Emitter)

RequireCollectorUri sets the Emitters collector URI.

func RequireEmitter

func RequireEmitter(emitter *Emitter) func(t *Tracker)

RequireEmitter sets the Tracker Emitter

func SerializeMap

func SerializeMap(m map[string]string) []byte

SerializeMap takes a map and attempts to convert it to a byte buffer.

Types

type CallbackResult

type CallbackResult struct {
	Count  int
	Status int
}

type EcommerceTransactionEvent

type EcommerceTransactionEvent struct {
	OrderId       *string                         // Required
	TotalValue    *float64                        // Required
	Affiliation   *string                         // Optional
	TaxValue      *float64                        // Optional
	Shipping      *float64                        // Optional
	City          *string                         // Optional
	State         *string                         // Optional
	Country       *string                         // Optional
	Currency      *string                         // Optional
	Items         []EcommerceTransactionItemEvent // Optional
	Timestamp     *int64                          // Optional
	EventId       *string                         // Optional
	TrueTimestamp *int64                          // Optional
	Contexts      []SelfDescribingJson            // Optional
}

func (EcommerceTransactionEvent) Get

Get returns the event payload.

func (*EcommerceTransactionEvent) Init

func (e *EcommerceTransactionEvent) Init()

Init checks and validates the struct.

type EcommerceTransactionItemEvent

type EcommerceTransactionItemEvent struct {
	Sku      *string              // Required
	Price    *float64             // Required
	Quantity *int64               // Required
	Name     *string              // Optional
	Category *string              // Optional
	EventId  *string              // Optional
	Contexts []SelfDescribingJson // Optional
}

func (EcommerceTransactionItemEvent) Get

Get returns the event payload.

func (*EcommerceTransactionItemEvent) Init

Init checks and validates the struct.

type Emitter

type Emitter struct {
	CollectorUri  string
	CollectorUrl  url.URL
	RequestType   string
	Protocol      string
	SendLimit     int
	ByteLimitGet  int
	ByteLimitPost int
	DbName        string
	Storage       Storage
	SendChannel   chan bool
	Callback      func(successCount []CallbackResult, failureCount []CallbackResult)
	HttpClient    http.Client
}

func InitEmitter

func InitEmitter(options ...func(*Emitter)) *Emitter

InitEmitter creates a new Emitter object which handles storing and sending Snowplow Events.

func (*Emitter) Add

func (e *Emitter) Add(payload Payload)

Add will push an event to the database and will then initiate a sending loop.

func (*Emitter) Flush

func (e *Emitter) Flush()

Flush will attempt to start the send loop regardless of an event coming in.

func (Emitter) GetCollectorUrl

func (e Emitter) GetCollectorUrl() string

GetCollectorUrl returns the stringified collector URL.

func (Emitter) IsSending

func (e Emitter) IsSending() bool

IsSending checks whether the send channel has finished.

func (*Emitter) SetCollectorUri

func (e *Emitter) SetCollectorUri(collectorUri string)

SetCollectorUri sets a new Collector URI and updates the Collector URL.

func (*Emitter) SetProtocol

func (e *Emitter) SetProtocol(protocol string)

SetProtocol sets a new Protocol and updates the Collector URL.

func (*Emitter) SetRequestType

func (e *Emitter) SetRequestType(requestType string)

SetRequestType sets a new Request Type and updates the Collector URL.

func (*Emitter) Stop

func (e *Emitter) Stop()

Stop waits for the send channel to have a value and then resets it to nil.

type EventRow

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

type PageViewEvent

type PageViewEvent struct {
	PageUrl       *string              // Required
	PageTitle     *string              // Optional
	Referrer      *string              // Optional
	Timestamp     *int64               // Optional
	EventId       *string              // Optional
	TrueTimestamp *int64               // Optional
	Contexts      []SelfDescribingJson // Optional
}

func (PageViewEvent) Get

func (e PageViewEvent) Get() Payload

Get returns the event payload.

func (*PageViewEvent) Init

func (e *PageViewEvent) Init()

Init checks and validates the struct.

type Payload

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

func InitPayload

func InitPayload() *Payload

InitPayload returns a new payload object.

func (Payload) Add

func (p Payload) Add(key string, value *string)

Add pushes a key value pair to the payload.

func (Payload) AddDict

func (p Payload) AddDict(dict map[string]string)

AddDict pushes an array of key-value pairs to the payload.

func (Payload) AddJson

func (p Payload) AddJson(instance map[string]interface{}, isBase64 bool, keyEncoded string, keyNotEncoded string)

AddJson pushes a JSON formatted array to the payload. Json encodes the array first (turns it into a string) and then will encode (or not) the string in base64.

func (Payload) Get

func (p Payload) Get() map[string]string

Get returns the payload as a map[string]string.

func (Payload) String

func (p Payload) String() string

String returns a JSON representation of the internal Map.

type RawEventRow

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

type RawEventRowUint

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

type ScreenViewEvent

type ScreenViewEvent struct {
	Name          *string              // Optional
	Id            *string              // Optional
	Timestamp     *int64               // Optional
	EventId       *string              // Optional
	TrueTimestamp *int64               // Optional
	Contexts      []SelfDescribingJson // Optional
}

func (ScreenViewEvent) Get

Get returns the event payload.

func (*ScreenViewEvent) Init

func (e *ScreenViewEvent) Init()

Init checks and validates the struct.

type SelfDescribingEvent

type SelfDescribingEvent struct {
	Event         *SelfDescribingJson  // Required
	Timestamp     *int64               // Optional
	EventId       *string              // Optional
	TrueTimestamp *int64               // Optional
	Contexts      []SelfDescribingJson // Optional
}

func (SelfDescribingEvent) Get

func (e SelfDescribingEvent) Get(base64Encode bool) Payload

Get returns the event payload.

func (*SelfDescribingEvent) Init

func (e *SelfDescribingEvent) Init()

Init checks and validates the struct.

type SelfDescribingJson

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

func InitSelfDescribingJson

func InitSelfDescribingJson(schema string, data interface{}) *SelfDescribingJson

InitSelfDescribingJson creates a new SelfDescribingJson object.

func (SelfDescribingJson) Get

func (s SelfDescribingJson) Get() map[string]interface{}

Get wraps the schema and data into a JSON.

func (*SelfDescribingJson) SetDataWithMap

func (s *SelfDescribingJson) SetDataWithMap(data map[string]interface{})

SetDataWithMap updates the structs data to a new map.

func (*SelfDescribingJson) SetDataWithPayload

func (s *SelfDescribingJson) SetDataWithPayload(data Payload)

SetDataWithPayload updates the structs data to the contents of a Payload object.

func (*SelfDescribingJson) SetDataWithSelfDescribingJson

func (s *SelfDescribingJson) SetDataWithSelfDescribingJson(data SelfDescribingJson)

SetDataWithSelfDescribingJson updates the structs data to a JSON. Used for nesting SelfDescribingJsons.

func (SelfDescribingJson) String

func (s SelfDescribingJson) String() string

String returns the JSON as a String.

type SendResult

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

type Storage

type Storage interface {
	AddEventRow(payload Payload) bool
	DeleteAllEventRows() int64
	DeleteEventRows(ids []int) int64
	GetAllEventRows() []EventRow
	GetEventRowsWithinRange(eventRange int) []EventRow
}

type StorageMemory

type StorageMemory struct {
	Db    *memdb.MemDB
	Index *uint32
}

func InitStorageMemory

func InitStorageMemory() *StorageMemory

func (StorageMemory) AddEventRow

func (s StorageMemory) AddEventRow(payload Payload) bool

AddEventRow adds a new event to the database

NOTE: As entries are not auto-incremeneting the id is incremented manually which

limits inserts to 4,294,967,295 in single session

func (StorageMemory) DeleteAllEventRows

func (s StorageMemory) DeleteAllEventRows() int64

DeleteAllEventRows removes all rows within the memory store

func (StorageMemory) DeleteEventRows

func (s StorageMemory) DeleteEventRows(ids []int) int64

DeleteEventRows removes all rows with matching identifiers

func (StorageMemory) GetAllEventRows

func (s StorageMemory) GetAllEventRows() []EventRow

GetAllEventRows returns all rows within the memory store

func (StorageMemory) GetEventRowsWithinRange

func (s StorageMemory) GetEventRowsWithinRange(eventRange int) []EventRow

GetEventRowsWithinRange returns all available events or a maximal slice

type StorageSQLite3

type StorageSQLite3 struct {
	DbName string
}

func InitStorageSQLite3

func InitStorageSQLite3(dbName string) *StorageSQLite3

func (StorageSQLite3) AddEventRow

func (s StorageSQLite3) AddEventRow(payload Payload) bool

Add stores an event payload in the database.

func (StorageSQLite3) DeleteAllEventRows

func (s StorageSQLite3) DeleteAllEventRows() int64

DeleteAllEventRows removes all events from the database.

func (StorageSQLite3) DeleteEventRows

func (s StorageSQLite3) DeleteEventRows(ids []int) int64

DeleteEventRows removes a range of ids from the database.

func (StorageSQLite3) GetAllEventRows

func (s StorageSQLite3) GetAllEventRows() []EventRow

GetAllEventRows returns all events in the database.

func (StorageSQLite3) GetEventRowsWithinRange

func (s StorageSQLite3) GetEventRowsWithinRange(eventRange int) []EventRow

GetEventRowsWithinRange returns a specified range of events from the database.

type StructuredEvent

type StructuredEvent struct {
	Category      *string              // Required
	Action        *string              // Required
	Label         *string              // Optional
	Property      *string              // Optional
	Value         *float64             // Optional
	Timestamp     *int64               // Optional
	EventId       *string              // Optional
	TrueTimestamp *int64               // Optional
	Contexts      []SelfDescribingJson // Optional
}

func (StructuredEvent) Get

func (e StructuredEvent) Get() Payload

Get returns the event payload.

func (*StructuredEvent) Init

func (e *StructuredEvent) Init()

Init checks and validates the struct.

type Subject

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

func InitSubject

func InitSubject() *Subject

InitSubject returns a new subject object.

func (Subject) Get

func (s Subject) Get() map[string]string

Get returns the key-value store as a map[string]string.

func (Subject) SetColorDepth

func (s Subject) SetColorDepth(depth int)

SetColorDepth adds the color-depth measurement to the key-value store.

func (Subject) SetDomainUserId

func (s Subject) SetDomainUserId(domainUserId string)

SetDomainUserId adds a domain user id to the key-value store.

func (Subject) SetIpAddress

func (s Subject) SetIpAddress(ipAddress string)

SetIpAddress adds an ip address to the key-value store.

func (Subject) SetLanguage

func (s Subject) SetLanguage(language string)

SetLanguage adds a language to the key-value store.

func (Subject) SetNetworkUserId

func (s Subject) SetNetworkUserId(networkUserId string)

SetNetworkUserId adds a network user id to the key-value store.

func (Subject) SetScreenResolution

func (s Subject) SetScreenResolution(width int, height int)

SetScreenResolution adds the screen-resolution mesaurement to the key-value store.

func (Subject) SetTimeZone

func (s Subject) SetTimeZone(timezone string)

SetTimeZone adds a timezone to the key-value store.

func (Subject) SetUserId

func (s Subject) SetUserId(userId string)

SetUserId adds a user id to teh key-value store.

func (Subject) SetUseragent

func (s Subject) SetUseragent(useragent string)

SetUseragent adds a useragent to the key-value store.

func (Subject) SetViewPort

func (s Subject) SetViewPort(width int, height int)

SetViewPort adds the view-port measurement to the key-value store.

type TimingEvent

type TimingEvent struct {
	Category      *string              // Required
	Variable      *string              // Required
	Timing        *int64               // Required
	Label         *string              // Optional
	Timestamp     *int64               // Optional
	EventId       *string              // Optional
	TrueTimestamp *int64               // Optional
	Contexts      []SelfDescribingJson // Optional
}

func (TimingEvent) Get

Get returns the event payload.

func (*TimingEvent) Init

func (e *TimingEvent) Init()

Init checks and validates the struct.

type Tracker

type Tracker struct {
	Emitter      *Emitter
	Subject      *Subject
	Namespace    string
	AppId        string
	Platform     string
	Base64Encode bool
}

func InitTracker

func InitTracker(options ...func(*Tracker)) *Tracker

InitTracker creates a new tracker instance linked to an emitter and subject. Will assert that the Emitter is valid and not nil.

func (Tracker) FlushEmitter

func (t Tracker) FlushEmitter()

FlushEmitter will force-send all events in the emitter buffer.

func (*Tracker) SetAppId

func (t *Tracker) SetAppId(appId string)

SetAppId updates the Tracker application id.

func (*Tracker) SetBase64Encode

func (t *Tracker) SetBase64Encode(base64Encode bool)

SetBase64Encode updates whether to base64 encode contexts and unstructured events.

func (*Tracker) SetEmitter

func (t *Tracker) SetEmitter(emitter *Emitter)

SetEmitter updates the tracker with a new emitter.

func (*Tracker) SetNamespace

func (t *Tracker) SetNamespace(namespace string)

SetNamespace updates the Tracker namespace value.

func (*Tracker) SetPlatform

func (t *Tracker) SetPlatform(platform string)

SetPlatform updates the platform from which the event is fired.

func (*Tracker) SetSubject

func (t *Tracker) SetSubject(subject *Subject)

SetSubject updates the tracker with a new subject.

func (Tracker) TrackEcommerceTransaction

func (t Tracker) TrackEcommerceTransaction(e EcommerceTransactionEvent)

TrackEcommerceTransaction sends an ecommerce transaction event.

func (Tracker) TrackPageView

func (t Tracker) TrackPageView(e PageViewEvent)

TrackPageView sends a page view event.

func (Tracker) TrackScreenView

func (t Tracker) TrackScreenView(e ScreenViewEvent)

TrackScreenView sends a screen view event.

func (Tracker) TrackSelfDescribingEvent

func (t Tracker) TrackSelfDescribingEvent(e SelfDescribingEvent)

TrackSelfDescribingEvent sends a self-described event.

func (Tracker) TrackStructEvent

func (t Tracker) TrackStructEvent(e StructuredEvent)

TrackStructEvent sends a structured event.

func (Tracker) TrackTiming

func (t Tracker) TrackTiming(e TimingEvent)

TrackTiming sends a timing event.

Jump to

Keyboard shortcuts

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