1.1.1 • Published 1 year ago

as-event-tracker v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Introduction

The Alphastream event tracker is a package which helps track different events on your website along with its data, time, urls, etc.


Getting Started

To use the application, simply run npm i as-event-tracker and import it into the app.


Set Up

All methods and classes mentioned in this guide can be accessed through the global EventCapture class, for example EventCapture.create({}), so that keyword will be omitted from the remainder of the guide.

Initialisation

Before any events can be logged, you'll first need to initialise the app. To do this you'll need to call the create method as shown below:

create({
    storeInCookies: false,
    apiKey: <insert api key>,
    logEvents: true, //if you'd like to log events for debugging
    captureUrl: 'https://collect.alphastream.io/v1/collect',
    clientChannelMeta: <ClientChannelMeta object> // this is a nullable value and does not need to be passed in.
});

A list of the options that will be except are as follows:

OptionTypeDefaultRoleOptional
apiKeystringThe api key used to identify clients.
storeInCookiesbooleantrueSpecifies if VisitorId and/or Session ids will be held in cookie storage.☑️
captureUrlstringThe capture url to use, there is currently only https://collect.alphastream.io/v1/collect.
logEventsbooleanfalseWill log out to the console on every event request and response. Note that errors will still be logged even if this feature is turned off.☑️
clientChannelMetaClientChannelMetaThis allows for the channel meta, that is passed on each call to be predifined, if not set then this values in the channel meta will be determined based on global values provided by the device/browser.☑️
dataSourcestringtaken from [global].window.location.hostnameThe data source identifier for the client app, this can be an app name, url or whatever you use to identify your app on a domain or environemt level.☑️
loggerLoggeran instance of the Logger object that uses the console.logThe logger used for debugging errors and calls to and from the collection api.☑️

ClientChannelMeta

This object represents pre set channel meta default values that are passed through the create method:

NameTypeDefaultNotesRequired
timezone_offsetstringIntl.DateTimeFormat() api provided.
device_typestringProvided by the navigator api
device_platformstringProvided by the navigator api
screen_widthnumberProvided by the global api
screen_heightnumberProvided by the global api
culture_codestringProvided by the navigator api
osstringProvided by the navigator api
browserstringProvided by the navigator api

Custom Logging

Clients can define a custom Logger to be used in place of the default Logger which uses console.log. The Logger is an abstract class that can be extanded to create a custon logger, as shown below:

npm package 'custom logger' example:

import { LogLevel, Logger } from 'as-event-tracker';

export default class ConsoleLogger extends Logger {
    executeLog(
        message: string,
        level: LogLevel,
        content?: any
    ) : void {
        if(level !== LogLevel.Error)
            return;
    
        if(content)
            console.error(`WBC Event - ${message}: `, content);
        else
            console.error(`WBC Event - ${message}`);
    }
}

Logger

This object is an abstract class that can be implemented, to create your own custom logger:

NameParamsNotesAbstract
logmessage: { type: string }, content?: {type: any | nullable}Fired on events that are LogLevel.Debug
infomessage: { type: string }, content?: {type: any | nullable}Fired on events that are LogLevel.Information
warnmessage: { type: string }, content?: {type: any | nullable}Fired on events that are LogLevel.Warning
errormessage: { type: string }, content?: {type: any | nullable}Fired on events that are LogLevel.Error
executeLogmessage: { type: string }, content?: {type: any | nullable}, level: { type: LogLevel }An abstract method to be defined by the client when implmenting the abstract Logger class☑️

LogLevel

An enum used to specify the level of the log message being called. | Name | Value | |--------------|-----------| | Debug | "log" | | Information | "info" | | Warning | "warn" | | Error | "error" |

User Set Up

In order to associate an event to a given clients application user, the client ref will need to be provided using the following code:

setClientRef(<local client>);

This can be any identify used to identify users on a clients application.


Request Entities

Component

The Components class is created to represent the component associated with the event being called. This is an optional parameter on all event requests and is made of the following properties:

NameTypeDefaultNotesRequired
typestringUsed to specify the element type.☑️
idstringThe elements id attribute.☑️
elementTreestringThis is best represented as a / delimited string the represents a list of parent dom tree element ids.☑️

Example use case:

new EventCapture.Component({
    type: "button",
    id: "btnOne",
    elementTree: "mainWrapper/sectionRight/btnOne"
});

MetaData

This class is used to store associated event meta data such as search terms or content ids:

NameTypeDefaultNotesRequired
keyMetaDataKeyThe key that specifies what the data relates to.☑️
typestringnullAn additional identifier for the the meta data value, for example when the key is MetaDataKey.SearchTerm, this value can specify what type of data was being searched, ie users or companies.
valuestring☑️

MetaDataKey

An enum used to specify the type of meta data being stored. | Name | Value | |--------------|-----------| | EntityId | "entity_id" | | ContentId | "content_id" | | Topic | "topic" | | SearchTerm | "term" | | UserEmail | "user_email" | | UserId | "user_id" | | PageNumber | "page_number" | | PageSize | "page_size" | | SearchResults | "results" | | Tab | "active_tab" | | RelatedEntity | "related_entity" | | ContentType | "content_type" | | SortField | "sort_field" |

Note: Any meta data entities with a key of RelatedEntity will not be stored in the database as an event_meta item and instead will be stored as a seperate property under related_entities.

RelatedEntityMetaDataType

An enum used to specify the type of the type field in meta data that uses related entities, these are suggested values and aren't validate on, any string value can be passed through here. | Name | Value | |--------------|-----------| | MT4 | "MT4" | | GT13 | "GT13" | | ADSSAlias | "ADSSAlias" | | EODSymbol | "EODSymbol" | | NetDania | "NetDania" | | deeplink | "deeplink" | | ASID | "ASID" |

Example use case:

new EventCapture.Component({
    type: "button",
    id: "btnOne",
    elementTree: "mainWrapper/sectionRight/btnOne"
});

EventDetail

An enum used in the ResearchEventRequest and ReactionEventRequest models. This property is supplementary to the provided action type.

NameValue
Add"add"
Remove"remove"
Create"create"
Delete"delete"
Modify"modify"
Ascending"ascending"
Descending"descending"
Open"open"
Close"close"

EventType

An enum used to specify the type of custom event. | Name | Value | |--------------|-----------| | Load | "pageload" | | Click | "click" | | Recommendation | "recommendation" | | Notification | "notification" | | Entity | "entity" | | Topic | "topic" | | Content | "content" | | Search | "search" | | Filter | "filter" | | Research | "research" | | Authentication | "authentication" | | Transaction | "transaction" | | Trade | "trade" | | Reaction | "reaction" |

Events Requests

All event request models will be listed below followed by the event action enums.

Request Models

AuthenticationEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionAuthenticationAction
metaDataArray<MetaData>

ClickEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionClickAction or string☑️
componentComponent
metaDataArray<MetaData>

ContentEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionContentAction or string☑️
componentComponent
metaDataArray<MetaData>

CustomEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.
eventTypeEventType
eventActionany
eventDetailEventDetail
componentComponent
metaDataArray<MetaData>

EntityEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionContentAction or string☑️
componentComponent
metaDataArray<MetaData>

FilterEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionFilterAction☑️
componentComponent
metaDataArray<MetaData>

LoadEventRequest

NameTypeDefaultNotesRequired
urlstringPage url of the load event.☑️
eventActionLoadAction
metaDataArray<MetaData>

NotifictionEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
componentComponent
metaDataArray<MetaData>

ReactionEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventDetailEventDetail☑️
componentComponent
metaDataArray<MetaData>

RecomendationEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
componentComponent
metaDataArray<MetaData>

ResearchEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionResearchAction☑️
eventDetailEventDetail☑️
componentComponent
metaDataArray<MetaData>

SearchEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionSearchAction☑️
componentComponent
metaDataArray<MetaData>

TopicEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
componentComponent
metaDataArray<MetaData>

TradeEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionTradeAction☑️
eventDetailEventDetail
componentComponent
metaDataArray<MetaData>

TransactionEventRequest

NameTypeDefaultNotesRequired
eventanyThe javascript Event object that fired the event.☑️
eventActionTransactionAction☑️
componentComponent
metaDataArray<MetaData>

Event Actions

AuthenticationAction

NameValue
SignIn"sign_in"
SignOut"sign_out"
SignUp"sign_up"

ClickAction

NameValue
Entity"entity"

ContentAction

NameValue
Expand"expand"
Shrink"shrink"
FollowUrl"follow_url"
EnteredView"entered_view"
SeeMore"see_more"
SeeLess"see_less"
Select"select"

FilterAction

NameValue
Applied"applied"

LoadAction

NameValue
Load"load"
Paged"paged"
TabSelected"tab_selected"

ReactionAction

NameValue
Like"like"
Favourite"favourite"
Comment"comment"
Basket"basket"
Watchlist"watchlist"

ResearchAction

NameValue
Indicator"indicator"
AdjustView"adjust_view"
Filter"filter"
DateSelect"date_select"
SortView"sort_view"

SearchAction

NameValue
Applied"applied"
Result"result"
Filter"filter"
Sort"sort"
Selected"selected"
FocusOn"focus_on"
FocusAway"focus_away"
Close"close"

TradeAction

NameValue
BuyMarket"buy_market"
BuyLimit"buy_limit"
BuyStop"buy_stop"
SellMarket"sell_market"
SellLimit"sell_limit"
SellStop"sell_stop"

TransactionAction

NameValue
Withdraw"withdraw"
Deposit"deposit"
Buy"buy"
Sell"sell"

Firing Events

All of the available events that can be fired, are listed as follows

FunctionRequest ModelNotes
authenticationAuthenticationEventRequestPassing the eventAction as AuthenticationAction.SignOut will set the clientRef as null
basketReactionEventRequest
clickClickEventRequest
commentReactionEventRequest
contentContentEventRequest
customCustomEventRequest
entityEntityEventRequest
favouriteReactionEventRequest
filterFilterEventRequest
likeReactionEventRequest
loadLoadEventRequest
notificationNotifictionEventRequest
recommendationRecomendationEventRequest
researchResearchEventRequest
searchSearchEventRequest
topicTopicEventRequest
tradeTradeEventRequest
transactionTransactionEventRequest
watchlistReactionEventRequest

An example click event:

click(new EventCapture.ClickEventRequest{
    event: new PointerEvent(),
    eventAction: EventCapture.ClickAction.Entity,
    component: new EventCapture.Component({
        type: "button",
        id: "btnOne",
        elementTree: "mainWrapper/btnOne"
    }),
    metaData: [
        new EventCapture.MetaData({
            key: MetaDataKey.RelatedEntity,
            type: 'entity',
            value: "678901"
        }),
        new EventCapture.MetaData({
            key: MetaDataKey.EntityId,
            value: "123456"
        });
    ]
});
1.1.1

1 year ago

1.1.0

1 year ago

1.0.17

1 year ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago