Documentation ¶
Index ¶
- Constants
- func CountBytesInString(str string) int
- func DeserializeMap(b []byte) (map[string]string, error)
- func Float64ToString(value *float64, places int) string
- func GetTimestamp() int64
- func GetTimestampString() string
- func GetUUID() string
- func Int64ToString(value *int64) string
- func IntArrayToString(values []int, delimiter string) string
- func IntToString(value int) string
- func MapToJson(m interface{}) string
- func MapToQueryParams(m map[string]string) url.Values
- func NewFloat64(val float64) *float64
- func NewInt64(val int64) *int64
- func NewString(val string) *string
- func OptionAppId(appId string) func(t *Tracker)
- func OptionBase64Encode(base64Encode bool) func(t *Tracker)
- func OptionByteLimitGet(byteLimitGet int) func(e *Emitter)
- func OptionByteLimitPost(byteLimitPost int) func(e *Emitter)
- func OptionCallback(callback func(successCount []CallbackResult, failureCount []CallbackResult)) func(e *Emitter)
- func OptionDbName(dbName string) func(e *Emitter)
- func OptionNamespace(namespace string) func(t *Tracker)
- func OptionPlatform(platform string) func(t *Tracker)
- func OptionProtocol(protocol string) func(e *Emitter)
- func OptionRequestType(requestType string) func(e *Emitter)
- func OptionSendLimit(sendLimit int) func(e *Emitter)
- func OptionStorage(storage Storage) func(e *Emitter)
- func OptionSubject(subject *Subject) func(t *Tracker)
- func RequireCollectorUri(collectorUri string) func(e *Emitter)
- func RequireEmitter(emitter *Emitter) func(t *Tracker)
- func SerializeMap(m map[string]string) []byte
- type CallbackResult
- type EcommerceTransactionEvent
- type EcommerceTransactionItemEvent
- type Emitter
- func (e *Emitter) Add(payload Payload)
- func (e *Emitter) Flush()
- func (e Emitter) GetCollectorUrl() string
- func (e Emitter) IsSending() bool
- func (e *Emitter) SetCollectorUri(collectorUri string)
- func (e *Emitter) SetProtocol(protocol string)
- func (e *Emitter) SetRequestType(requestType string)
- func (e *Emitter) Stop()
- type EventRow
- type PageViewEvent
- type Payload
- type RawEventRow
- type RawEventRowUint
- type ScreenViewEvent
- type SelfDescribingEvent
- type SelfDescribingJson
- func (s SelfDescribingJson) Get() map[string]interface{}
- func (s *SelfDescribingJson) SetDataWithMap(data map[string]interface{})
- func (s *SelfDescribingJson) SetDataWithPayload(data Payload)
- func (s *SelfDescribingJson) SetDataWithSelfDescribingJson(data SelfDescribingJson)
- func (s SelfDescribingJson) String() string
- type SendResult
- type Storage
- type StorageMemory
- type StorageSQLite3
- type StructuredEvent
- type Subject
- func (s Subject) Get() map[string]string
- func (s Subject) SetColorDepth(depth int)
- func (s Subject) SetDomainUserId(domainUserId string)
- func (s Subject) SetIpAddress(ipAddress string)
- func (s Subject) SetLanguage(language string)
- func (s Subject) SetNetworkUserId(networkUserId string)
- func (s Subject) SetScreenResolution(width int, height int)
- func (s Subject) SetTimeZone(timezone string)
- func (s Subject) SetUserId(userId string)
- func (s Subject) SetUseragent(useragent string)
- func (s Subject) SetViewPort(width int, height int)
- type TimingEvent
- type Tracker
- func (t Tracker) FlushEmitter()
- func (t *Tracker) SetAppId(appId string)
- func (t *Tracker) SetBase64Encode(base64Encode bool)
- func (t *Tracker) SetEmitter(emitter *Emitter)
- func (t *Tracker) SetNamespace(namespace string)
- func (t *Tracker) SetPlatform(platform string)
- func (t *Tracker) SetSubject(subject *Subject)
- func (t Tracker) TrackEcommerceTransaction(e EcommerceTransactionEvent)
- func (t Tracker) TrackPageView(e PageViewEvent)
- func (t Tracker) TrackScreenView(e ScreenViewEvent)
- func (t Tracker) TrackSelfDescribingEvent(e SelfDescribingEvent)
- func (t Tracker) TrackStructEvent(e StructuredEvent)
- func (t Tracker) TrackTiming(e TimingEvent)
Constants ¶
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" )
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" )
const ( DB_DRIVER = "sqlite3" DB_TABLE_NAME = "events" DB_COLUMN_ID = "id" DB_COLUMN_EVENT = "event" )
const ( DEFAULT_PLATFORM = "srv" DEFAULT_BASE_64 = true )
Variables ¶
This section is empty.
Functions ¶
func CountBytesInString ¶
CountBytesInString takes a string and gets a byte count.
func DeserializeMap ¶
DeserializeMap takes a byte buffer and attempts to convert it back to a map.
func Float64ToString ¶
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 Int64ToString ¶
Int64ToString converts an Integer of 64 bits to a String.
func IntArrayToString ¶
IntArrayToString converts an array of integers to a string delimited by a string of your choice.
func MapToJson ¶
func MapToJson(m interface{}) string
MapToString takes a generic and converts it to a JSON representation.
func MapToQueryParams ¶
MapToQueryParams takes a map of string keys and values and builds an encoded query string.
func OptionAppId ¶
OptionAppId sets the Tracker Application ID
func OptionBase64Encode ¶
OptionBase64Encode sets the Tracker base64encode
func OptionByteLimitGet ¶
OptionByteLimitGet sets the byte limit for GET requests.
func OptionByteLimitPost ¶
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 ¶
OptionDbName overrides the default name of the storage database.
func OptionNamespace ¶
OptionNamespace sets the Tracker Namespace
func OptionPlatform ¶
OptionPlatform sets the Tracker Platform
func OptionProtocol ¶
OptionProtocol sets the protocol type to use (http or https).
func OptionRequestType ¶
OptionRequestType sets the request type to use (GET or POST).
func OptionSendLimit ¶
OptionSendLimit sets the send limit for the emitter.
func OptionStorage ¶
OptionStorage sets a custom event Storage target which implements the Storage interface
Note: If this option is used OptionDbName will be ignored
func OptionSubject ¶
OptionSubject sets the Tracker Subject
func RequireCollectorUri ¶
RequireCollectorUri sets the Emitters collector URI.
func RequireEmitter ¶
RequireEmitter sets the Tracker Emitter
func SerializeMap ¶
SerializeMap takes a map and attempts to convert it to a byte buffer.
Types ¶
type CallbackResult ¶
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 ¶
func (e EcommerceTransactionEvent) Get() Payload
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 ¶
func (e EcommerceTransactionItemEvent) Get() Payload
Get returns the event payload.
func (*EcommerceTransactionItemEvent) Init ¶
func (e *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 ¶
InitEmitter creates a new Emitter object which handles storing and sending Snowplow Events.
func (*Emitter) Flush ¶
func (e *Emitter) Flush()
Flush will attempt to start the send loop regardless of an event coming in.
func (Emitter) GetCollectorUrl ¶
GetCollectorUrl returns the stringified collector URL.
func (*Emitter) SetCollectorUri ¶
SetCollectorUri sets a new Collector URI and updates the Collector URL.
func (*Emitter) SetProtocol ¶
SetProtocol sets a new Protocol and updates the Collector URL.
func (*Emitter) SetRequestType ¶
SetRequestType sets a new Request Type and updates the Collector URL.
type PageViewEvent ¶
type Payload ¶
type Payload struct {
// contains filtered or unexported fields
}
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.
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 ¶
func (e ScreenViewEvent) Get() SelfDescribingEvent
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 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) Init ¶
func (e *StructuredEvent) Init()
Init checks and validates the struct.
type Subject ¶
type Subject struct {
// contains filtered or unexported fields
}
func (Subject) SetColorDepth ¶
SetColorDepth adds the color-depth measurement to the key-value store.
func (Subject) SetDomainUserId ¶
SetDomainUserId adds a domain user id to the key-value store.
func (Subject) SetIpAddress ¶
SetIpAddress adds an ip address to the key-value store.
func (Subject) SetLanguage ¶
SetLanguage adds a language to the key-value store.
func (Subject) SetNetworkUserId ¶
SetNetworkUserId adds a network user id to the key-value store.
func (Subject) SetScreenResolution ¶
SetScreenResolution adds the screen-resolution mesaurement to the key-value store.
func (Subject) SetTimeZone ¶
SetTimeZone adds a timezone to the key-value store.
func (Subject) SetUseragent ¶
SetUseragent adds a useragent to the key-value store.
func (Subject) SetViewPort ¶
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 ¶
func (e TimingEvent) Get() SelfDescribingEvent
Get returns the event payload.
type Tracker ¶
type Tracker struct { Emitter *Emitter Subject *Subject Namespace string AppId string Platform string Base64Encode bool }
func InitTracker ¶
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) SetBase64Encode ¶
SetBase64Encode updates whether to base64 encode contexts and unstructured events.
func (*Tracker) SetEmitter ¶
SetEmitter updates the tracker with a new emitter.
func (*Tracker) SetNamespace ¶
SetNamespace updates the Tracker namespace value.
func (*Tracker) SetPlatform ¶
SetPlatform updates the platform from which the event is fired.
func (*Tracker) SetSubject ¶
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.