Module bauplan.tracker

Track an event

  • optionally time how long it took
  • optionally pass further parameters

To load

var Tracker = require("bauplan.tracker");

or as part of the Bauplan bundle

var Bauplan = require("bauplan");
var Tracker = Bauplan.Tracker;

To track an event named "foo"

Tracker.track("foo");

To time an event, call the start method

Tracker.start("foo");

If the timer is stil running when track is called, it will be stopped automatically

The timer can be stopped manually (but usually stopping automatically should suffice)

Tracker.stop("foo");

Three convenience methods exist:

Tracker.completed("foo");
Tracker.aborted("foo");
Tracker.unload("foo");

These all call the track method, setting the result parameter to be the name of the method called

eg. Tracker.completed => {result: "completed"}

All the above methods can be passed an object of optional parameters which will be sent as a JSONified string

Tracker.track("foo", {bar: "baz"});

Parameters can be stored at any time before track is called (even before start is called)

Tracker.store("foo", {bar:"baz"});

Events can have subevents

Tracker.startSubEvent("foo", "foosub");
Tracker.stopSubEvent("foo", "foosub");

Unstopped subevents will be stopped automatically when the stop or track methods are called

A key-value pair of the the subevents name and the time elapsed are sent as part of the parameters

If the subevent is called more than once during the event, the times are concatenated

Additionally, a key-value pair of the order the subevents were triggered in is also sent

Automatic tracking of events

The following events are tracked:

  • start of visit
  • end of visit
  • all blurs and refocuses of the app window
  • all clicks
  • mouseovers on links, inputs of type submit and buttons
  • unload

Automatic tracking of untrapped errors

Any untrapped errors will be tracked.

NB. this cannot track errors that occur before bauplan.tracker is loaded.

Returns

Tracker

Type
instance
Source:

Members

(private, inner) tracking :object

Type:
  • object
Properties:
Name Type Description
timer object

Object to store event timers

data string

Object to store event data

Source:

Methods

aborted(name, paramsopt)

Send aborted ui event along any parameters passed or previously stored

Parameters
Name Type Attributes Description
name string

Name of the event for tracking service to use as key

params object <optional>

Parameters to be passed to tracking service

Source:

completed(name, paramsopt)

Send completed ui event along any parameters passed or previously stored

Parameters
Name Type Attributes Description
name string

Name of the event for tracking service to use as key

params object <optional>

Parameters to be passed to tracking service

Source:

error(error)

Send error ui event

Parameters
Name Type Description
error object

Error object

Source:

notfound(urlopt, referreropt)

Send page not found ui event

Parameters
Name Type Attributes Description
url string <optional>

The URL that does not exist

referrer string <optional>

The referrer URL

Source:

pageview(urlopt)

Send pageview ui event

Parameters
Name Type Attributes Description
url string <optional>

URL - if not provided uses the current URL

Source:

start(name, paramsopt, reportStartedopt)

Start timer for an event

Parameters
Name Type Attributes Default Description
name string

Name of the event to start timer for

params object <optional>

Parameters to be passed to tracking service

reportStarted boolean <optional>
false

Whether to report event has started to tracking service

Source:

startSubEvent(eventName, subEventName)

Start timer for a subevent to be tracked

Parameters
Name Type Description
eventName string

Name of the event subevent belongs to

subEventName string

Name of the event to start timer for

Source:

stop(name, paramsopt)

Stop timer for an event

Parameters
Name Type Attributes Description
name string

Name of the event to stop timer for

params object <optional>

Parameters to be passed to tracking service

Source:

stopSubEvent(eventName, subEventName)

Stop timer for a subevent

Parameters
Name Type Description
eventName string

Name of the event subevent belongs to

subEventName string

Name of the event to start timer for

Source:

store(name, paramsopt)

Store parameters for an event

Parameters
Name Type Attributes Description
name string

Name of the event to start timer for

params object <optional>

Parameters to be passed to tracking service

Source:

track(name, paramsopt, asyncopt)

Send ui event with any parameters passed or previously stored

Request is sent to {apiRoot}{baseurl}/{name} Data is an object of key-value pairs serialised as JSON

Parameters
Name Type Attributes Default Description
name string

Name of the event for tracking service to use as key

params object <optional>

Parameters to be passed to tracking service

async boolean <optional>
true

Whether tracking call should be asynchronous

Source:

transaction(t)

Send transaction ui event

Parameters
Name Type Description
t object

Transaction details

This calls bauplan.analytics#transaction

Source:

unload(nameopt, paramsopt)

Send ui event interrupted by unload event along any parameters passed or previously stored

NB. because of unload event, such events are sent synchronously

Parameters
Name Type Attributes Description
name string <optional>

Name of the event for tracking service to use as key

params object <optional>

Parameters to be passed to tracking service

If called without name, any running events are stopped and any stored data is sent to the tracking endpoint along with a generic unload tracking event

Source:

view(view, appendopt)

Send view ui event

Parameters
Name Type Attributes Description
view string

View name

append boolean <optional>

Alternative tracker URL

Source:

(private, inner) createSelectorPath(node)

Get string representing node's CSS selector path

Parameters
Name Type Description
node domnode

DOM node

Source:

(private, inner) dispatch(options)

Disptaches Ajax call with sensible defaults

Parameters
Name Type Description
options object
Properties
Name Type Attributes Default Description
url string
data object | string <optional>
contentType string <optional>
application/json; charset=utf-8
type string <optional>
PUT
async boolean <optional>
true
error function <optional>
Source:

(inner) get(name, clearopt)

Get parameters for an event

Parameters
Name Type Attributes Description
name string

Name of the event to start timer for

clear boolean <optional>

Whether to clear the stored parameters

Source:

(private, inner) getNodeSelector(node)

Get string representing node's CSS selector

Parameters
Name Type Description
node domnode

DOM node

Source:

(inner) useragent()

Return details of useragent (viewport dimensions, scroll position, screen, agent, platform)

Source:
Returns

object