tracker

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TRACKER_VERSION = "golang-3.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 (
	DEFAULT_PLATFORM = "srv"
	DEFAULT_BASE_64  = true
)

Variables

This section is empty.

Functions

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 OptionHttpClient

func OptionHttpClient(client *http.Client) func(e *Emitter)

OptionHttpClient sets a custom client for HTTP connections.

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 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 RequireStorage

func RequireStorage(storage storageiface.Storage) func(e *Emitter)

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

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
	Subject       *Subject                        // Optional
}

func (EcommerceTransactionEvent) Get

Get returns the event payload.

func (*EcommerceTransactionEvent) Init

func (e *EcommerceTransactionEvent) Init()

Init checks and validates the struct.

func (*EcommerceTransactionEvent) SetSubjectIfNil

func (e *EcommerceTransactionEvent) SetSubjectIfNil(subject *Subject)

SetSubjectIfNil will set the event level subject if a Subject isn't already set

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
	Subject  *Subject             // Optional
}

func (EcommerceTransactionItemEvent) Get

Get returns the event payload.

func (*EcommerceTransactionItemEvent) Init

Init checks and validates the struct.

func (*EcommerceTransactionItemEvent) SetSubjectIfNil

func (e *EcommerceTransactionItemEvent) SetSubjectIfNil(subject *Subject)

SetSubjectIfNil will set the event level subject if a Subject isn't already set

type Emitter

type Emitter struct {
	CollectorUri  string
	CollectorUrl  url.URL
	RequestType   string
	Protocol      string
	SendLimit     int
	ByteLimitGet  int
	ByteLimitPost int
	Storage       storageiface.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.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 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
	Subject       *Subject             // Optional
}

func (PageViewEvent) Get

func (e PageViewEvent) Get() payload.Payload

Get returns the event payload.

func (*PageViewEvent) Init

func (e *PageViewEvent) Init()

Init checks and validates the struct.

func (*PageViewEvent) SetSubjectIfNil

func (e *PageViewEvent) SetSubjectIfNil(subject *Subject)

SetSubjectIfNil will set the event level subject if a Subject isn't already set

type ScreenViewEvent

type ScreenViewEvent struct {
	Name          *string              // Optional
	Id            *string              // Optional
	Timestamp     *int64               // Optional
	EventId       *string              // Optional
	TrueTimestamp *int64               // Optional
	Contexts      []SelfDescribingJson // Optional
	Subject       *Subject             // 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
	Subject       *Subject             // Optional
}

func (SelfDescribingEvent) Get

func (e SelfDescribingEvent) Get(base64Encode bool) payload.Payload

Get returns the event payload.

func (*SelfDescribingEvent) Init

func (e *SelfDescribingEvent) Init()

Init checks and validates the struct.

func (*SelfDescribingEvent) SetSubjectIfNil

func (e *SelfDescribingEvent) SetSubjectIfNil(subject *Subject)

SetSubjectIfNil will set the event level subject if a Subject isn't already set

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.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 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
	Subject       *Subject             // Optional
}

func (StructuredEvent) Get

Get returns the event payload.

func (*StructuredEvent) Init

func (e *StructuredEvent) Init()

Init checks and validates the struct.

func (*StructuredEvent) SetSubjectIfNil

func (e *StructuredEvent) SetSubjectIfNil(subject *Subject)

SetSubjectIfNil will set the event level subject if a Subject isn't already set

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
	Subject       *Subject             // 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) BlockingFlush

func (t *Tracker) BlockingFlush(flushAttempts int, flushSleepTimeMs int) int

BlockingFlush will block the executing thread until the tracker has fired all events from the queue. Useful for short-lived applications that have to wait for events to be fired.

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