snowplow-golang-tracker.v1: gopkg.in/snowplow/snowplow-golang-tracker.v1/tracker Index | Files

package tracker

import "gopkg.in/snowplow/snowplow-golang-tracker.v1/tracker"

Index

Package Files

constants.go emitter.go events.go payload.go self_describing_json.go storage.go subject.go tracker.go utils.go

Constants

const (
    TRACKER_VERSION = "golang-1.1.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
)

func CountBytesInString Uses

func CountBytesInString(str string) int

CountBytesInString takes a string and gets a byte count.

func DeserializeMap Uses

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

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

func Float64ToString Uses

func Float64ToString(value *float64, places int) string

Float64ToString does conversion of floats to string values.

func GetTimestamp Uses

func GetTimestamp() int64

GetTimestamp returns the current unix timestamp in milliseconds

func GetTimestampString Uses

func GetTimestampString() string

GetTimestampString returns the current unix timestamp in milliseconds

func GetUUID Uses

func GetUUID() string

GetUUID generates a Version 4 UUID string.

func Int64ToString Uses

func Int64ToString(value *int64) string

Int64ToString converts an Integer of 64 bits to a String.

func IntArrayToString Uses

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 Uses

func IntToString(value int) string

IntToString converts an Integer to a String.

func MapToJson Uses

func MapToJson(m interface{}) string

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

func MapToQueryParams Uses

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 Uses

func NewFloat64(val float64) *float64

NewFloat64 returns a pointer to a float64.

func NewInt64 Uses

func NewInt64(val int64) *int64

NewInt64 returns a pointer to an int64.

func NewString Uses

func NewString(val string) *string

NewString returns a pointer to a string.

func OptionAppId Uses

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

OptionAppId sets the Tracker Application ID

func OptionBase64Encode Uses

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

OptionBase64Encode sets the Tracker base64encode

func OptionByteLimitGet Uses

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

OptionByteLimitGet sets the byte limit for GET requests.

func OptionByteLimitPost Uses

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

OptionByteLimitPost sets the byte limit for POST requests.

func OptionCallback Uses

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

OptionCallback sets a custom callback for the emitter loop.

func OptionDbName Uses

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

OptionDbName sets the name of the storage database.

func OptionNamespace Uses

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

OptionNamespace sets the Tracker Namespace

func OptionPlatform Uses

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

OptionPlatform sets the Tracker Platform

func OptionProtocol Uses

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

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

func OptionRequestType Uses

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

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

func OptionSendLimit Uses

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

OptionSendLimit sets the send limit for the emitter.

func OptionSubject Uses

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

OptionSubject sets the Tracker Subject

func RequireCollectorUri Uses

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

RequireCollectorUri sets the Emitters collector URI.

func RequireEmitter Uses

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

RequireEmitter sets the Tracker Emitter

func SerializeMap Uses

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

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

type CallbackResult Uses

type CallbackResult struct {
    Count  int
    Status int
}

type EcommerceTransactionEvent Uses

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 Uses

func (e EcommerceTransactionEvent) Get() Payload

Get returns the event payload.

func (*EcommerceTransactionEvent) Init Uses

func (e *EcommerceTransactionEvent) Init()

Init checks and validates the struct.

type EcommerceTransactionItemEvent Uses

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 Uses

func (e EcommerceTransactionItemEvent) Get() Payload

Get returns the event payload.

func (*EcommerceTransactionItemEvent) Init Uses

func (e *EcommerceTransactionItemEvent) Init()

Init checks and validates the struct.

type Emitter Uses

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 Uses

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

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

func (*Emitter) Add Uses

func (e *Emitter) Add(payload Payload)

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

func (*Emitter) Flush Uses

func (e *Emitter) Flush()

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

func (Emitter) GetCollectorUrl Uses

func (e Emitter) GetCollectorUrl() string

GetCollectorUrl returns the stringified collector URL.

func (Emitter) IsSending Uses

func (e Emitter) IsSending() bool

IsSending checks whether the send channel has finished.

func (*Emitter) SetCollectorUri Uses

func (e *Emitter) SetCollectorUri(collectorUri string)

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

func (*Emitter) SetProtocol Uses

func (e *Emitter) SetProtocol(protocol string)

SetProtocol sets a new Protocol and updates the Collector URL.

func (*Emitter) SetRequestType Uses

func (e *Emitter) SetRequestType(requestType string)

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

func (*Emitter) Stop Uses

func (e *Emitter) Stop()

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

type EventRow Uses

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

type PageViewEvent Uses

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 Uses

func (e PageViewEvent) Get() Payload

Get returns the event payload.

func (*PageViewEvent) Init Uses

func (e *PageViewEvent) Init()

Init checks and validates the struct.

type Payload Uses

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

func InitPayload Uses

func InitPayload() *Payload

InitPayload returns a new payload object.

func (Payload) Add Uses

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

Add pushes a key value pair to the payload.

func (Payload) AddDict Uses

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

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

func (Payload) AddJson Uses

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 Uses

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

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

func (Payload) String Uses

func (p Payload) String() string

String returns a JSON representation of the internal Map.

type RawEventRow Uses

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

type ScreenViewEvent Uses

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

func (ScreenViewEvent) Get Uses

func (e ScreenViewEvent) Get() SelfDescribingEvent

Get returns the event payload.

func (*ScreenViewEvent) Init Uses

func (e *ScreenViewEvent) Init()

Init checks and validates the struct.

type SelfDescribingEvent Uses

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

func (SelfDescribingEvent) Get Uses

func (e SelfDescribingEvent) Get(base64Encode bool) Payload

Get returns the event payload.

func (*SelfDescribingEvent) Init Uses

func (e *SelfDescribingEvent) Init()

Init checks and validates the struct.

type SelfDescribingJson Uses

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

func InitSelfDescribingJson Uses

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

InitSelfDescribingJson creates a new SelfDescribingJson object.

func (SelfDescribingJson) Get Uses

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

Get wraps the schema and data into a JSON.

func (*SelfDescribingJson) SetDataWithMap Uses

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

SetDataWithMap updates the structs data to a new map.

func (*SelfDescribingJson) SetDataWithPayload Uses

func (s *SelfDescribingJson) SetDataWithPayload(data Payload)

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

func (*SelfDescribingJson) SetDataWithSelfDescribingJson Uses

func (s *SelfDescribingJson) SetDataWithSelfDescribingJson(data SelfDescribingJson)

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

func (SelfDescribingJson) String Uses

func (s SelfDescribingJson) String() string

String returns the JSON as a String.

type SendResult Uses

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

type Storage Uses

type Storage struct {
    DbName  string
    DbConn  *sql.DB
    AddStmt *sql.Stmt
}

func InitStorage Uses

func InitStorage(dbName string) *Storage

func (Storage) AddEventRow Uses

func (s Storage) AddEventRow(payload Payload) bool

Add stores an event payload in the database.

func (Storage) DeleteAllEventRows Uses

func (s Storage) DeleteAllEventRows() int64

DeleteAllEventRows removes all events from the database.

func (Storage) DeleteEventRows Uses

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

DeleteEventRows removes a range of ids from the database.

func (Storage) GetAllEventRows Uses

func (s Storage) GetAllEventRows() []EventRow

GetAllEventRows returns all events in the database.

func (Storage) GetEventRowsWithinRange Uses

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

GetEventRowsWithinRange returns a specified range of events from the database.

type StructuredEvent Uses

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 Uses

func (e StructuredEvent) Get() Payload

Get returns the event payload.

func (*StructuredEvent) Init Uses

func (e *StructuredEvent) Init()

Init checks and validates the struct.

type Subject Uses

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

func InitSubject Uses

func InitSubject() *Subject

InitSubject returns a new subject object.

func (Subject) Get Uses

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

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

func (Subject) SetColorDepth Uses

func (s Subject) SetColorDepth(depth int)

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

func (Subject) SetDomainUserId Uses

func (s Subject) SetDomainUserId(domainUserId string)

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

func (Subject) SetIpAddress Uses

func (s Subject) SetIpAddress(ipAddress string)

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

func (Subject) SetLanguage Uses

func (s Subject) SetLanguage(language string)

SetLanguage adds a language to the key-value store.

func (Subject) SetNetworkUserId Uses

func (s Subject) SetNetworkUserId(networkUserId string)

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

func (Subject) SetScreenResolution Uses

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

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

func (Subject) SetTimeZone Uses

func (s Subject) SetTimeZone(timezone string)

SetTimeZone adds a timezone to the key-value store.

func (Subject) SetUserId Uses

func (s Subject) SetUserId(userId string)

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

func (Subject) SetUseragent Uses

func (s Subject) SetUseragent(useragent string)

SetUseragent adds a useragent to the key-value store.

func (Subject) SetViewPort Uses

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

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

type TimingEvent Uses

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 Uses

func (e TimingEvent) Get() SelfDescribingEvent

Get returns the event payload.

func (*TimingEvent) Init Uses

func (e *TimingEvent) Init()

Init checks and validates the struct.

type Tracker Uses

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

func InitTracker Uses

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 Uses

func (t Tracker) FlushEmitter()

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

func (*Tracker) SetAppId Uses

func (t *Tracker) SetAppId(appId string)

SetAppId updates the Tracker application id.

func (*Tracker) SetBase64Encode Uses

func (t *Tracker) SetBase64Encode(base64Encode bool)

SetBase64Encode updates whether to base64 encode contexts and unstructured events.

func (*Tracker) SetEmitter Uses

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

SetEmitter updates the tracker with a new emitter.

func (*Tracker) SetNamespace Uses

func (t *Tracker) SetNamespace(namespace string)

SetNamespace updates the Tracker namespace value.

func (*Tracker) SetPlatform Uses

func (t *Tracker) SetPlatform(platform string)

SetPlatform updates the platform from which the event is fired.

func (*Tracker) SetSubject Uses

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

SetSubject updates the tracker with a new subject.

func (Tracker) TrackEcommerceTransaction Uses

func (t Tracker) TrackEcommerceTransaction(e EcommerceTransactionEvent)

TrackEcommerceTransaction sends an ecommerce transaction event.

func (Tracker) TrackPageView Uses

func (t Tracker) TrackPageView(e PageViewEvent)

TrackPageView sends a page view event.

func (Tracker) TrackScreenView Uses

func (t Tracker) TrackScreenView(e ScreenViewEvent)

TrackScreenView sends a screen view event.

func (Tracker) TrackSelfDescribingEvent Uses

func (t Tracker) TrackSelfDescribingEvent(e SelfDescribingEvent)

TrackSelfDescribingEvent sends a self-described event.

func (Tracker) TrackStructEvent Uses

func (t Tracker) TrackStructEvent(e StructuredEvent)

TrackStructEvent sends a structured event.

func (Tracker) TrackTiming Uses

func (t Tracker) TrackTiming(e TimingEvent)

TrackTiming sends a timing event.

Package tracker imports 13 packages (graph). Updated 2018-03-05. Refresh now. Tools for package owners.