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

settings

Global Property

Type

  • Object

Shared 'internal' scope.

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.

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

createTransport

Global Function

Create the transport mechanism.

  • Works out the best transprot mechanism for the browser and returns it. One of:
  • Cross domain Ajax POST with json content type
  • GET url

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

migrate_across_domains(store, user_id)

Global Function

migrateacrossdomains Clean up after forgetting to write cookies to the 'root' ft.com domain.

  • Check local storage for the 'proper' value.
  • If it exists, use it.
  • If not, set current user id as the 'proper' value.
  • If this value and the cookie match, then we've already fixed it.
  • If not, drop the cookie and it will be reset it on the root domain.
parameter type default description
store Store The storage instance used for storing the ID.
user_id String The user ID to check against storage.

Returns

  • String - - The real user ID.

Links

init(value)

Global Function

Init

parameter type default description
value String | Object The value of a userID to use or configuration object.

Returns

  • String - - The user ID.

Links

defaultConfig

Global Function

Default properties for sending a tracking request.

Returns

  • Object - - The default settings for the component.

Links

setRootID(new_id)

Global Function

Generate and store a new rootID.

parameter type default description
new_id string Optional rootID, if you want to use your own. Otherwise we'll create one for you.

Returns

  • string | * - The rootID.

Links

getRootID

Global Function

Get rootID.

Returns

  • string | * - The rootID.

Links

requestID(request_id)

Global Function

Create a requestID (unique identifier) for the page impression.

parameter type default description
request_id string Optional RequestID, if you want to use your own. Otherwise will create one for you.

Returns

  • string | * - The RequestID.

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

defaultLinkConfig

Global Function

Default properties for events.

Returns

  • Object - The default link configuration.

Links

track(element)

Global Function

Track the link.

parameter type default description
element Element The element being tracked.

Returns

  • Object | boolean - - If synscronous, returns when the tracking event is sent, if async, returns true immediately.

Links

onClick(cb)

Global Function

Set the callback called on every link tracking event.

parameter type default description
cb function The callback.

Returns

  • undefined

Links

runQueue

Global Function

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

Returns

  • undefined

Links

init(...)

Global Function

Setup and initialise link tracking.

parameter type default description
config Object Initial configuration
config.root Element Optional. The root element to search for links. Defaults to window.document - useful if trying to track links from an iframe.
config.selector string Optional. The selector to use to search for links. Defaults to 'a'.
config.event string Optional. The event to listen on. Defaults to 'click'.
config.links array Optional. If you've already worked out the links to track, then this is used to pass them over. Must be an array with elements that accept events.

Returns

  • array - The links setup in this init.

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 'falsy' 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

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

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