version

Global Property

Type

  • string

The version of the tracking module.

Links

source

Global Property

Type

  • string

The source of this event.

Links

api_key

Global Property

Type

  • string

The API key.

Links

initialised

Global Property

Type

  • boolean

The initialised state of the object.

Links

queue

Global Property

Type

  • Array

Queue data.

Links

storage

Global Property

Type

  • Object

The storage method to use. Determines best storage method.

Links

domain

Global Property

Default collection server.

Links

queue

Global Property

Type

  • Queue

Queue queue.

Links

data

Global Property

Store data.

Links

storageKey

Global Property

The key/name of this store.

Links

storage

Global Property

Type

  • Object

The storage method to use. Determines best storage method.

Links

cuid

Global Property

CUID Generator

Links

page_callbacks

Global Property

Record of callbacks to call when a page is tracked.

Links

new Tracking

Methods

  • developer(level) - (instance) Turn on/off developer mode. (Can also be activated on init.)
  • destroy - (instance) Clean up the tracking module.
  • toString - (instance) Overload toString method to show the version.
  • init(...) - (instance) Initialises the Tracking object. All options are optional, if a configuration option is missing, the module will try to initialise using any configuration found in the DOM using the script config tag.
  • updateConfig(newConfig) - (instance) Update the tracking configuration with any state changes. The supplied config is merged with any existing config; to unset a value, set it as null or undefined.

Links

new Queue(name)

Class for handling a queue backed up by a store.

parameter type default description
name String The name of the queue.

Methods

  • all - (instance) Gets the contents of the store.
  • first - (instance) Gets the first item in the store.
  • last - (instance) Gets the last item in the store.
  • add(item) - (instance) Add data to the store.
  • replace(items) - (instance) Overwrite the store with something completely new.
  • shift - (instance) Pop the first item from the queue.
  • save - (instance) Save the current store to localStorage so that old requests can still be sent after a page refresh.

Links

new Store(name, config)

Class for storing data Will choose the 'best' storage method available. Can also specify a type of storage.

parameter type default description
name string The name of the store
config Object Optional, config object for extra configuration

Methods

  • read - (instance) Get/Read the current data.
  • write(data) - (instance) Write the supplied data to the store.
  • destroy - (instance) Delete the current data.

Properties

  • keyPrefix - Internal Storage key prefix.
  • loadStore - Temporary var containing data from a previously saved store.

Links

should_use_sendBeacon

Global Function

Consistent check to see if we should use sendBeacon or not.

Returns

  • boolean - Should we use sendBeacon?

Links

sendRequest(request, callback)

Global Function

Attempts to send a tracking request.

parameter type default description
request Object The request to be sent.
callback function Callback to fire the next item in the queue.

Returns

  • undefined

Links

add(request)

Global Function

Adds a new request to the list of pending requests

parameter type default description
request Tracking The request to queue

Returns

  • undefined

Links

run(callback)

Global Function

If there are any requests queued, attempts to send the next one Otherwise, does nothing

parameter type default description
callback function Optional callback

Returns

  • undefined

Links

addAndRun(request)

Global Function

Convenience function to add and run a request all in one go.

parameter type default description
request Object The request to queue and run.

Returns

  • undefined

Links

init

Global Function

Init the queue and send any leftover events.

Returns

  • undefined

Links

setSession(session)

Global Function

Set the session in the store.

parameter type default description
session String The session to be stored.

Returns

  • undefined

Links

getSession

Global Function

Get the session from the store. Expiry and gen of a new session are handled here.

Returns

  • Object - the current session

Links

init(config)

Global Function

Init

parameter type default description
config String | Object The name used to store the session or configuration object.

Returns

  • Session - - The session

Links

setValue(key, value)

Global Function

Saves a value. Stores a copy rather than a reference, to avoid mutations leaking.

parameter type default description
key string The key to use to store the object
value * The value

Returns

  • undefined

Links

getValue(key)

Global Function

Retrieves a value from the settings object. Returns a copy rather than reference, to avoid mutations leaking.

parameter type default description
key string The key to get

Returns

  • * - - The setting.

Links

destroy(key)

Global Function

Deletes a value

parameter type default description
key string The key to delete

Returns

  • undefined

Links

init(value, cookieDomain)

Global Function

Init

parameter type default description
value String The value of a userID to use if one is not stored
cookieDomain String The domain that should be used to cookie te user

Returns

  • String - - The user ID if present, or a generated UID if not

Links

setUser(id)

Global Function

setUser

parameter type default description
id String The userID to set.

Returns

  • String - - The user ID if present, or a generated UID if not

Links

destroy

Global Function

Delete the current user data.

Returns

  • void

Links

setRootID

Global Function

Generate and store a new rootID, used to mark a new root event that subsequent events will be linked to.

Returns

  • string | * - The rootID.

Links

getRootID

Global Function

Get the current rootID.

Returns

  • string | * - The rootID.

Links

track(config, callback)

Global Function

Make a tracking request.

parameter type default description
config Object Should be passed an object containing a format and the values for that format
callback function Fired when the request has been made.

Returns

  • Object - request

Links

defaultEventConfig

Global Function

Default properties for events.

Returns

  • Object - - Default configuration for events

Links

event(trackingEvent, callback)

Global Function

Track an event.

parameter type default description
trackingEvent Event The event, which could the following properties in its 'detail' key: [category] - The category, for example: video [action] - The action performed, for example: play [component_id] - Optional. The ID for the component instance.
callback function Optional, Callback function. Called when request completed.

Returns

  • undefined

Links

getOrigamiEventTarget(event)

Global Function

Helper function that gets the target of an event if it's an Origami component

parameter type default description
event Event The event triggered.

Returns

  • HTMLElement | undefined - - Returns the HTML element if an Origami component, else undefined.

Links

getComponentId(element)

Global Function

Helper function that generates a component id based on its xpath

parameter type default description
element HTMLElement The HTML Element to gen an ID for.

Returns

  • string - hash

Links

defaultPageConfig

Global Function

Default properties for page tracking requests.

Returns

  • Object - - The default properties for pages.

Links

page(config, callback)

Global Function

Make the page tracking request.

parameter type default description
config Object Configuration object. If omitted, will use the defaults.
callback function Callback function. Called when request completed.

Returns

  • undefined

Links

log(List)

Global Function

Log messages to the browser console. Requires 'log' to be set on init.

parameter type default description
List * of objects to log

Returns

  • undefined

Links

is(variable, type)

Global Function

Tests if variable is a certain type. Defaults to check for undefined if no type specified.

parameter type default description
variable * The variable to check.
type string The type to test for. Defaults to undefined.

Returns

  • boolean - - The answer for if the variable is of type.

Links

merge(target, options)

Global Function

Merge objects together. Will remove undefined and null values.

parameter type default description
target Object The original object to merge in to.
options Object The object to merge into the target. If omitted, will merge target into a new empty Object.

Returns

  • Object - The merged object.

Links

encode(str)

Global Function

URL encode a string.

parameter type default description
str string The string to be encoded.

Returns

  • string - The encoded string.

Links

decode(str)

Global Function

URL decode a string.

parameter type default description
str string The string to be decoded.

Returns

  • string - The decoded string.

Links

onPage(cb)

Global Function

Listen for page tracking requests.

parameter type default description
cb function The callback to be called whenever a page is tracked.

Returns

  • undefined

Links

triggerPage

Global Function

Trigger the 'page' listeners.

Returns

  • undefined

Links

getValueFromCookie(matcher)

Global Function

Get a value from document.cookie matching the first match of the regexp you supply

parameter type default description
matcher RegExp The Regex to match with

Returns

  • String - - The vale from the cookie

Links

getValueFromUrl(matcher)

Global Function

Get a value from the url, used for uuid or querystring parameters

parameter type default description
matcher RegExp The Regex to match with

Returns

  • String - - The value from the URL

Links

getValueFromJsVariable(str)

Global Function

Get a value from a specified JavaScript variable.

parameter type default description
str String The name of variable, in dot syntax.

Returns

  • String - The value from the JS variable.

Links

Tracking#developer(level)

Instance Method

Turn on/off developer mode. (Can also be activated on init.)

parameter type default description
level boolean Turn on or off, defaults to false if omitted.

Returns

  • undefined

Links

Tracking#destroy

Instance Method

Clean up the tracking module.

Returns

  • undefined

Links

Tracking#toString

Instance Method

Overload toString method to show the version.

Returns

  • string - The module's version.

Links

Tracking#init(...)

Instance Method

Initialises the Tracking object.

All options are optional, if a configuration option is missing, the module will try to initialise using any configuration found in the DOM using the script config tag.

parameter type default description
config Object See {@link Tracking} for the configuration options.
config.developer boolean Optional, if `true`, logs certain actions.
config.noSend boolean Optional, if `true`, won't send events.
config.configId string Optional
config.session string Optional

Returns

  • Tracking - - Returns the tracking object

Example

<!-- DOM configuration settings -->
<script type='application/json' data-o-tracking-config>
page: {
	 product: 'desktop'
},
user: {
  user_id: '023ur9jfokwenvcklwnfiwhfoi324'
}
</script>

Links

Tracking#updateConfig(newConfig)

Instance Method

Update the tracking configuration with any state changes. The supplied config is merged with any existing config; to unset a value, set it as null or undefined.

parameter type default description
newConfig Object The configuration object to merge in - see init()

Returns

  • void

Links

module.exports

Static Property

Type

  • Tracking

A constructed object, this module is a Singleton as we only want one instance sending events. See [Tracking](#Tracking) for the publicly available interface.

Links

Queue#all

Instance Method

Gets the contents of the store.

Returns

  • Array - The array of items.

Links

Queue#first

Instance Method

Gets the first item in the store.

Returns

  • Object - Returns the item.

Links

Queue#last

Instance Method

Gets the last item in the store.

Returns

  • Object - Returns the item.

Links

Queue#add(item)

Instance Method

Add data to the store.

parameter type default description
item Object An item or an array of items.

Returns

  • Queue - - Returns the instance of the queue.

Links

Queue#replace(items)

Instance Method

Overwrite the store with something completely new.

parameter type default description
items Array The new array of data.

Returns

  • Queue - - Returns the instance of the queue.

Links

Queue#shift

Instance Method

Pop the first item from the queue.

Returns

  • Object - The item.

Links

Queue#save

Instance Method

Save the current store to localStorage so that old requests can still be sent after a page refresh.

Returns

  • Queue - - Returns the instance of the queue.

Links

Store~keyPrefix

Inner Property

Internal Storage key prefix.

Links

Store~loadStore

Inner Property

Temporary var containing data from a previously saved store.

Links

Store#read

Instance Method

Get/Read the current data.

Returns

  • Object - Returns the data from the store.

Links

Store#write(data)

Instance Method

Write the supplied data to the store.

parameter type default description
data String The data to write.

Returns

  • Store - - The instance of the store

Links

Store#destroy

Instance Method

Delete the current data.

Returns

  • Store - - The instance of the store

Links