@financial-times/o-tracking
Advanced tools
Comparing version 1.7.2 to 1.7.3
/*global require, module */ | ||
'use strict'; // eslint-disable-line strict | ||
const settings = require("./dist/javascript/core/settings"); | ||
var settings = require("./dist/javascript/core/settings"); | ||
const user = require("./dist/javascript/core/user"); | ||
var user = require("./dist/javascript/core/user"); | ||
const session = require("./dist/javascript/core/session"); | ||
var session = require("./dist/javascript/core/session"); | ||
const send = require("./dist/javascript/core/send"); | ||
var send = require("./dist/javascript/core/send"); | ||
const core = require("./dist/javascript/core"); | ||
var core = require("./dist/javascript/core"); | ||
/** | ||
@@ -19,3 +19,3 @@ * The version of the tracking module. | ||
const version = '1.4.2'; | ||
var version = '1.4.2'; | ||
/** | ||
@@ -26,3 +26,3 @@ * The source of this event. | ||
const source = 'o-tracking'; | ||
var source = 'o-tracking'; | ||
/** | ||
@@ -33,3 +33,3 @@ * The API key. | ||
const api_key = 'qUb9maKfKbtpRsdp0p2J7uWxRPGJEP'; | ||
var api_key = 'qUb9maKfKbtpRsdp0p2J7uWxRPGJEP'; | ||
/** | ||
@@ -164,3 +164,3 @@ * @class Tracking | ||
const hasDeclarativeConfig = Boolean(this._getDeclarativeConfigElement()); | ||
var hasDeclarativeConfig = Boolean(this._getDeclarativeConfigElement()); | ||
config = config || {}; | ||
@@ -182,3 +182,3 @@ | ||
settings.set('page_sent', false); | ||
const cookieDomain = config ? config.cookieDomain : false; // Set up the user from stored - may later be updated by config | ||
var cookieDomain = config ? config.cookieDomain : false; // Set up the user from stored - may later be updated by config | ||
@@ -207,3 +207,3 @@ user.init(false, cookieDomain); | ||
Tracking.prototype.updateConfig = function (newConfig) { | ||
let config = settings.get('config') || {}; | ||
var config = settings.get('config') || {}; | ||
config = this.utils.merge(config, newConfig); | ||
@@ -247,5 +247,5 @@ settings.set('config', config); // Developer mode | ||
Tracking.prototype._getDeclarativeConfig = function (options) { | ||
const configEl = this._getDeclarativeConfigElement(); | ||
var configEl = this._getDeclarativeConfigElement(); | ||
let declarativeConfigString; | ||
var declarativeConfigString; | ||
@@ -258,3 +258,3 @@ if (configEl) { | ||
let declarativeOptions; | ||
var declarativeOptions; | ||
@@ -264,3 +264,3 @@ try { | ||
} catch (e) { | ||
const configError = new Error('Invalid JSON configuration syntax, check validity for o-tracking configuration: "' + e.message + '"'); | ||
var configError = new Error('Invalid JSON configuration syntax, check validity for o-tracking configuration: "' + e.message + '"'); | ||
this.utils.broadcast('oErrors', 'log', { | ||
@@ -275,3 +275,3 @@ error: configError.message, | ||
for (const property in declarativeOptions) { | ||
for (var property in declarativeOptions) { | ||
if (declarativeOptions.hasOwnProperty(property)) { | ||
@@ -285,3 +285,3 @@ options[property] = options[property] || declarativeOptions[property]; | ||
const tracking = new Tracking(); | ||
var tracking = new Tracking(); | ||
@@ -288,0 +288,0 @@ function initialise() { |
@@ -7,13 +7,13 @@ /*global module, require */ | ||
const Send = require("./core/send"); | ||
var Send = require("./core/send"); | ||
const User = require("./core/user"); | ||
var User = require("./core/user"); | ||
const Session = require("./core/session"); | ||
var Session = require("./core/session"); | ||
const settings = require("./core/settings"); | ||
var settings = require("./core/settings"); | ||
const utils = require("./utils"); | ||
var utils = require("./utils"); | ||
let rootID; | ||
var rootID; | ||
/** | ||
@@ -57,5 +57,5 @@ * Generate and store a new rootID, used to mark a new root event that | ||
const session = Session.session(); // Set up the base request object with some values which should always be sent. | ||
var session = Session.session(); // Set up the base request object with some values which should always be sent. | ||
const request = { | ||
var request = { | ||
async: true, | ||
@@ -80,3 +80,3 @@ callback: callback || function () {}, | ||
const settingsConfig = settings.get('config') || {}; | ||
var settingsConfig = settings.get('config') || {}; | ||
@@ -83,0 +83,0 @@ if (settingsConfig.context) { |
@@ -7,5 +7,5 @@ /*global module, require */ | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
const Store = require("./store"); | ||
var Store = require("./store"); | ||
/** | ||
@@ -20,5 +20,5 @@ * Class for handling a queue backed up by a store. | ||
const Queue = function Queue(name) { | ||
var Queue = function Queue(name) { | ||
if (utils.isUndefined(name)) { | ||
const undefinedName = new Error('You must specify a name for the queue.'); | ||
var undefinedName = new Error('You must specify a name for the queue.'); | ||
utils.broadcast('oErrors', 'log', { | ||
@@ -64,5 +64,5 @@ error: undefinedName.message, | ||
const items = []; | ||
var items = []; | ||
for (let i = 0; i < this.queue.length; i = i + 1) { | ||
for (var i = 0; i < this.queue.length; i = i + 1) { | ||
items.push(this.queue[i].item); | ||
@@ -112,4 +112,4 @@ } | ||
// I was trying to turn this whole add function into a little module, to stop doAdd function being created everytime, but couldn't work out how to get to 'this' from within the module. | ||
const self = this; | ||
let i; | ||
var self = this; | ||
var i; | ||
@@ -149,3 +149,3 @@ function doAdd(item) { | ||
const invalidArg = new Error('Argument invalid, must be an array.'); | ||
var invalidArg = new Error('Argument invalid, must be an array.'); | ||
utils.broadcast('oErrors', 'log', { | ||
@@ -171,3 +171,3 @@ error: invalidArg.message, | ||
const item = this.queue.shift().item; | ||
var item = this.queue.shift().item; | ||
this.save(); | ||
@@ -174,0 +174,0 @@ return item; |
@@ -7,11 +7,11 @@ /*global module, require, window */ | ||
const settings = require("./settings"); | ||
var settings = require("./settings"); | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
const Queue = require("./queue"); | ||
var Queue = require("./queue"); | ||
const transports = require("./transports"); | ||
var transports = require("./transports"); | ||
const isIe11 = function isIe11() { | ||
var isIe11 = function isIe11() { | ||
return !!window.MSInputMethodContext && !!document.documentMode; | ||
@@ -24,3 +24,3 @@ }; | ||
let domain = 'https://spoor-api.ft.com/px.gif'; | ||
var domain = 'https://spoor-api.ft.com/px.gif'; | ||
/** | ||
@@ -32,3 +32,3 @@ * Queue queue. | ||
let queue; | ||
var queue; | ||
/** | ||
@@ -53,8 +53,8 @@ * Consistent check to see if we should use sendBeacon or not. | ||
function sendRequest(request, callback) { | ||
const queueTime = request.queueTime; | ||
const offlineLag = new Date().getTime() - queueTime; | ||
const transport = should_use_sendBeacon() ? transports.get('sendBeacon')() : window.XMLHttpRequest && 'withCredentials' in new window.XMLHttpRequest() ? transports.get('xhr')() : transports.get('image')(); | ||
const user_callback = request.callback; | ||
const core_system = settings.get('config') && settings.get('config').system || {}; | ||
const system = utils.merge(core_system, { | ||
var queueTime = request.queueTime; | ||
var offlineLag = new Date().getTime() - queueTime; | ||
var transport = should_use_sendBeacon() ? transports.get('sendBeacon')() : window.XMLHttpRequest && 'withCredentials' in new window.XMLHttpRequest() ? transports.get('xhr')() : transports.get('image')(); | ||
var user_callback = request.callback; | ||
var core_system = settings.get('config') && settings.get('config').system || {}; | ||
var system = utils.merge(core_system, { | ||
api_key: settings.get('api_key'), | ||
@@ -84,3 +84,3 @@ // String - API key - Make sure the request is from a valid client (idea nicked from Keen.io) useful if a page gets copied onto a Russian website and creates noise | ||
utils.log('PreSend', request); | ||
const stringifiedData = JSON.stringify(request); | ||
var stringifiedData = JSON.stringify(request); | ||
transport.complete(function (error) { | ||
@@ -95,3 +95,3 @@ if (utils.is(user_callback, 'function')) { | ||
if (isIe11() && transport.name === 'xhr') { | ||
let image_method = transports.get('image')(); // Append image label to transport value so that we know it tried xhr first | ||
var image_method = transports.get('image')(); // Append image label to transport value so that we know it tried xhr first | ||
@@ -121,6 +121,6 @@ request.system.transport = [request.system.transport, image_method.name].join('-'); | ||
}); | ||
let url = domain; | ||
var url = domain; | ||
if (request && request.category && request.action) { | ||
const type = "type=".concat(request.category, ":").concat(request.action); | ||
var type = "type=".concat(request.category, ":").concat(request.action); | ||
url = url.indexOf('?') > -1 ? "".concat(url, "&").concat(type) : "".concat(url, "?").concat(type); | ||
@@ -168,8 +168,8 @@ } // Both developer and noSend flags have to be set to stop the request sending. | ||
const all_events = queue.all(); | ||
var all_events = queue.all(); | ||
if (all_events.length > 200) { | ||
const counts = {}; | ||
var counts = {}; | ||
all_events.forEach(function (event) { | ||
const label = [event.category, event.action].join(':'); | ||
var label = [event.category, event.action].join(':'); | ||
@@ -195,3 +195,3 @@ if (!counts.hasOwnProperty(label)) { | ||
const next = function next() { | ||
var next = function next() { | ||
run(); | ||
@@ -201,3 +201,3 @@ callback(); | ||
const nextRequest = queue.shift(); // Cancel if we've run out of requests. | ||
var nextRequest = queue.shift(); // Cancel if we've run out of requests. | ||
@@ -204,0 +204,0 @@ if (!nextRequest) { |
@@ -7,4 +7,4 @@ /*global module, require */ | ||
let store; | ||
const defaultSessionConfig = { | ||
var store; | ||
var defaultSessionConfig = { | ||
storage: 'best', | ||
@@ -16,5 +16,5 @@ name: 'session', | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
const Store = require("./store"); | ||
var Store = require("./store"); | ||
/** | ||
@@ -29,3 +29,3 @@ * Set the session in the store. | ||
function setSession(session) { | ||
const d = new Date(); | ||
var d = new Date(); | ||
d.setTime(d.getTime() + store.config.expires); | ||
@@ -45,9 +45,9 @@ store.write({ | ||
function getSession() { | ||
const s = store.read(); | ||
let session; | ||
let isNew = false; | ||
var s = store.read(); | ||
var session; | ||
var isNew = false; | ||
if (s) { | ||
const d = new Date().valueOf(); | ||
const exp = parseInt(s.expiry, 10); // If current session is active. | ||
var d = new Date().valueOf(); | ||
var exp = parseInt(s.expiry, 10); // If current session is active. | ||
@@ -91,3 +91,3 @@ if (exp >= d) { | ||
const c = utils.merge(defaultSessionConfig, config); // config.name is important here, means the user has specifically asked for a cookie name. | ||
var c = utils.merge(defaultSessionConfig, config); // config.name is important here, means the user has specifically asked for a cookie name. | ||
@@ -94,0 +94,0 @@ if (c.storage === 'cookie' && config.name) { |
@@ -7,3 +7,3 @@ /*global module */ | ||
const settings = {}; | ||
var settings = {}; | ||
/** | ||
@@ -10,0 +10,0 @@ * Very basic implementation of deep clone, and only supports simple POJO objects and |
@@ -16,7 +16,7 @@ /*global module, require, window */ | ||
const Store = function Store(name, config) { | ||
var Store = function Store(name, config) { | ||
/** | ||
* Internal Storage key prefix. | ||
*/ | ||
const keyPrefix = 'o-tracking'; | ||
var keyPrefix = 'o-tracking'; | ||
/** | ||
@@ -27,8 +27,8 @@ * Temporary var containing data from a previously saved store. | ||
let loadStore; | ||
var loadStore; | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
if (utils.isUndefined(name)) { | ||
const undefinedName = new Error('You must specify a name for the store.'); | ||
var undefinedName = new Error('You must specify a name for the store.'); | ||
utils.broadcast('oErrors', 'log', { | ||
@@ -64,3 +64,3 @@ error: undefinedName.message, | ||
this.storage = function (config, window) { | ||
const test_key = keyPrefix + '_InternalTest'; // If cookie has been manually specified, don't bother with local storage. | ||
var test_key = keyPrefix + '_InternalTest'; // If cookie has been manually specified, don't bother with local storage. | ||
@@ -100,5 +100,5 @@ if (config.storage !== 'cookie') { | ||
name = name + '='; | ||
const cookies = window.document.cookie.split(';'); | ||
let i; | ||
let cookie; | ||
var cookies = window.document.cookie.split(';'); | ||
var i; | ||
var cookie; | ||
@@ -117,5 +117,5 @@ for (i = 0; i < cookies.length; i = i + 1) { | ||
function cookieSave(name, value, expiry) { | ||
let d; | ||
let expires = ''; | ||
let cookie; | ||
var d; | ||
var expires = ''; | ||
var cookie; | ||
@@ -122,0 +122,0 @@ if (utils.is(expiry, 'number')) { |
"use strict"; | ||
const utils = require("../../utils"); | ||
var utils = require("../../utils"); | ||
module.exports = function () { | ||
const image = new Image(1, 1); | ||
var image = new Image(1, 1); | ||
return { | ||
@@ -8,0 +8,0 @@ name: 'image', |
"use strict"; | ||
module.exports = function () { | ||
let resolver; | ||
let rejecter; | ||
const p = new Promise((resolve, reject) => { | ||
var resolver; | ||
var rejecter; | ||
var p = new Promise((resolve, reject) => { | ||
resolver = resolve; | ||
@@ -8,0 +8,0 @@ rejecter = reject; |
"use strict"; | ||
module.exports = function () { | ||
const xhr = new window.XMLHttpRequest(); | ||
var xhr = new window.XMLHttpRequest(); | ||
return { | ||
@@ -6,0 +6,0 @@ name: 'xhr', |
@@ -7,9 +7,9 @@ /*global module, require */ | ||
let _userID; | ||
var _userID; | ||
let store; | ||
var store; | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
const Store = require("./store"); | ||
var Store = require("./store"); | ||
/** | ||
@@ -25,3 +25,3 @@ * Init | ||
function init(value, cookieDomain) { | ||
const defaultUserConfig = { | ||
var defaultUserConfig = { | ||
storage: 'cookie', | ||
@@ -40,3 +40,3 @@ name: 'spoor-id', | ||
store = new Store(defaultUserConfig.name, defaultUserConfig); | ||
let id = store.read(); | ||
var id = store.read(); | ||
@@ -43,0 +43,0 @@ if (!id) { |
/*global module, require */ | ||
'use strict'; // eslint-disable-line strict | ||
const Delegate = require("ftdomdelegate"); | ||
var Delegate = require("ftdomdelegate"); | ||
const Queue = require("../core/queue"); | ||
var Queue = require("../core/queue"); | ||
const Core = require("../core"); | ||
var Core = require("../core"); | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
const settings = require("../core/settings"); | ||
var settings = require("../core/settings"); | ||
const getTrace = require("../../libs/get-trace"); | ||
var getTrace = require("../../libs/get-trace"); | ||
let internalQueue; | ||
const eventPropertiesToCollect = ["ctrlKey", "altKey", "shiftKey", "metaKey"]; // Trigger the event tracking | ||
var internalQueue; | ||
var eventPropertiesToCollect = ["ctrlKey", "altKey", "shiftKey", "metaKey"]; // Trigger the event tracking | ||
const track = eventData => { | ||
const firstDomPathToken = eventData.context.domPathTokens[0]; | ||
const href = firstDomPathToken.href || null; | ||
const oTrackingSkipQueueAttr = firstDomPathToken['data-o-tracking-skip-queue']; | ||
const skipQueue = oTrackingSkipQueueAttr && oTrackingSkipQueueAttr.toLowerCase() === 'true' || false; | ||
const isInternal = href && href.indexOf(window.document.location.hostname) > -1; | ||
var track = eventData => { | ||
var firstDomPathToken = eventData.context.domPathTokens[0]; | ||
var href = firstDomPathToken.href || null; | ||
var oTrackingSkipQueueAttr = firstDomPathToken['data-o-tracking-skip-queue']; | ||
var skipQueue = oTrackingSkipQueueAttr && oTrackingSkipQueueAttr.toLowerCase() === 'true' || false; | ||
var isInternal = href && href.indexOf(window.document.location.hostname) > -1; | ||
@@ -39,4 +39,4 @@ if (isInternal && !skipQueue) { | ||
const getEventProperties = event => { | ||
const eventProperties = eventPropertiesToCollect.reduce((returnObject, property) => { | ||
var getEventProperties = event => { | ||
var eventProperties = eventPropertiesToCollect.reduce((returnObject, property) => { | ||
try { | ||
@@ -56,3 +56,3 @@ if (event[property]) { | ||
const handleClickEvent = eventData => (clickEvent, clickElement) => { | ||
var handleClickEvent = eventData => (clickEvent, clickElement) => { | ||
//we don't want to track clicks to anonymous services like securedrop | ||
@@ -63,8 +63,7 @@ if (clickElement.getAttribute("data-o-tracking-do-not-track") === "true") { | ||
const context = getEventProperties(clickEvent); | ||
const _getTrace = getTrace(clickElement), | ||
trace = _getTrace.trace, | ||
customContext = _getTrace.customContext; | ||
var context = getEventProperties(clickEvent); | ||
var { | ||
trace, | ||
customContext | ||
} = getTrace(clickElement); | ||
context.domPathTokens = trace; | ||
@@ -75,3 +74,3 @@ context.url = window.document.location.href || null; | ||
const config = utils.merge(settings.get('config'), eventData); | ||
var config = utils.merge(settings.get('config'), eventData); | ||
track(config); | ||
@@ -88,8 +87,8 @@ }; | ||
const runQueue = _ => { | ||
const next = _ => { | ||
var runQueue = _ => { | ||
var next = _ => { | ||
runQueue(); | ||
}; | ||
const nextLink = internalQueue.shift(); | ||
var nextLink = internalQueue.shift(); | ||
@@ -112,7 +111,7 @@ if (nextLink) { | ||
const init = (category, elementsToTrack) => { | ||
var init = (category, elementsToTrack) => { | ||
elementsToTrack = elementsToTrack || 'a, button, input, [role="button"]'; // See https://github.com/ftlabs/ftdomdelegate#selector-string | ||
// Note: `context` is the term o-tracking uses for the data that is sent to spoor | ||
const eventData = { | ||
var eventData = { | ||
action: 'click', | ||
@@ -122,3 +121,3 @@ category: category || 'o-tracking' | ||
const delegate = new Delegate(document.body); | ||
var delegate = new Delegate(document.body); | ||
delegate.on('click', elementsToTrack, handleClickEvent(eventData), true); // Track any queued events | ||
@@ -125,0 +124,0 @@ |
/*global module, require */ | ||
'use strict'; // eslint-disable-line strict | ||
const Core = require("../core"); | ||
var Core = require("../core"); | ||
const getTrace = require("../../libs/get-trace"); | ||
var getTrace = require("../../libs/get-trace"); | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
const TRACKING_ATTRIBUTES = ['componentContentId', 'type', 'subtype', 'component']; | ||
var TRACKING_ATTRIBUTES = ['componentContentId', 'type', 'subtype', 'component']; | ||
const decorateEventData = (eventData, viewedEl, opts) => { | ||
const _getTrace = getTrace(viewedEl), | ||
trace = _getTrace.trace, | ||
customContext = _getTrace.customContext; | ||
var decorateEventData = (eventData, viewedEl, opts) => { | ||
var { | ||
trace, | ||
customContext | ||
} = getTrace(viewedEl); | ||
var context; | ||
let context; | ||
if (opts.getContextData) { | ||
@@ -24,3 +24,3 @@ if (typeof opts.getContextData !== 'function') { | ||
const dataBeforeWhitelist = opts.getContextData(viewedEl); | ||
var dataBeforeWhitelist = opts.getContextData(viewedEl); | ||
@@ -50,4 +50,4 @@ if (typeof dataBeforeWhitelist !== 'object') { | ||
const init = function init() { | ||
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var init = function init() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -59,4 +59,4 @@ if (!window.IntersectionObserver) { | ||
const selector = opts.selector || '[data-o-tracking-view]'; | ||
const elementsToTrack = [...document.querySelectorAll(selector)]; | ||
var selector = opts.selector || '[data-o-tracking-view]'; | ||
var elementsToTrack = [...document.querySelectorAll(selector)]; | ||
@@ -70,7 +70,7 @@ if (!elementsToTrack.length) { | ||
if (change.isIntersecting || change.intersectionRatio > 0) { | ||
const eventData = { | ||
action: 'view', | ||
var eventData = { | ||
action: opts.action || 'view', | ||
category: opts.category || 'component' | ||
}; | ||
const viewedEl = change.target; | ||
var viewedEl = change.target; | ||
decorateEventData(eventData, viewedEl, opts); | ||
@@ -83,3 +83,3 @@ Core.track(eventData); | ||
const observer = new IntersectionObserver(onChange, { | ||
var observer = new IntersectionObserver(onChange, { | ||
threshold: [1.0] | ||
@@ -86,0 +86,0 @@ }); |
@@ -7,5 +7,5 @@ /*global module, require */ | ||
const Core = require("../core"); | ||
var Core = require("../core"); | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
/** | ||
@@ -19,3 +19,3 @@ * Default properties for events. | ||
const defaultEventConfig = function defaultEventConfig() { | ||
var defaultEventConfig = function defaultEventConfig() { | ||
return { | ||
@@ -42,3 +42,3 @@ category: 'event', | ||
if (utils.is(trackingEvent.detail.category) || utils.is(trackingEvent.detail.action)) { | ||
const noCategoryActionVals = 'Missing category or action values'; | ||
var noCategoryActionVals = 'Missing category or action values'; | ||
utils.broadcast('oErrors', 'log', { | ||
@@ -53,3 +53,3 @@ error: noCategoryActionVals, | ||
const config = utils.merge(defaultEventConfig(), { | ||
var config = utils.merge(defaultEventConfig(), { | ||
category: trackingEvent.detail.category, | ||
@@ -61,3 +61,3 @@ action: trackingEvent.detail.action, | ||
delete config.context.action; | ||
const origamiElement = getOrigamiEventTarget(trackingEvent); | ||
var origamiElement = getOrigamiEventTarget(trackingEvent); | ||
@@ -84,3 +84,3 @@ if (origamiElement) { | ||
// `event.target` | ||
const element = event.target || event.srcElement; | ||
var element = event.target || event.srcElement; | ||
@@ -101,3 +101,3 @@ if (element && element.getAttribute('data-o-component')) { | ||
function getComponentId(element) { | ||
const path = _getElementPath(element); | ||
var path = _getElementPath(element); | ||
@@ -109,3 +109,3 @@ if (typeof path === 'undefined') { | ||
const srcElement = path[0]; // Because, you could have two identical elements in the DOM as siblings, | ||
var srcElement = path[0]; // Because, you could have two identical elements in the DOM as siblings, | ||
// we need to determine the 'sibling index': the order they're sitting within a DOM node. | ||
@@ -115,7 +115,7 @@ // Although in reality this is unlikely to always be the same, it's just a | ||
const siblingIndex = function getSiblingIndex(element) { | ||
const srcParent = element.parentElement; | ||
var siblingIndex = function getSiblingIndex(element) { | ||
var srcParent = element.parentElement; | ||
if (srcParent) { | ||
for (let i = 0; i < srcParent.childNodes.length; i++) { | ||
for (var i = 0; i < srcParent.childNodes.length; i++) { | ||
if (srcParent.childNodes[i] === srcElement) { | ||
@@ -133,3 +133,3 @@ return i; | ||
const normalisedStringPath = path.reduceRight(function (builder, el) { | ||
var normalisedStringPath = path.reduceRight(function (builder, el) { | ||
if (!el.nodeName) { | ||
@@ -139,3 +139,3 @@ return builder + ' - ' + el.constructor.name + '\n'; | ||
const nodeName = el.nodeName.toLowerCase(); // In some browsers, document is prepended with a '#' | ||
var nodeName = el.nodeName.toLowerCase(); // In some browsers, document is prepended with a '#' | ||
@@ -164,3 +164,3 @@ if (nodeName.indexOf('#') === 0) { | ||
function _getElementPath(element) { | ||
const path = []; | ||
var path = []; | ||
@@ -198,6 +198,6 @@ while (element) { | ||
function _generateHash(str) { | ||
let l = str.length; | ||
let h = 1 ^ l; | ||
let i = 0; | ||
let k; | ||
var l = str.length; | ||
var h = 1 ^ l; | ||
var i = 0; | ||
var k; | ||
@@ -204,0 +204,0 @@ while (l >= 4) { |
@@ -7,7 +7,7 @@ /*global module, require */ | ||
const Core = require("../core"); | ||
var Core = require("../core"); | ||
const utils = require("../utils"); | ||
var utils = require("../utils"); | ||
const settings = require("../core/settings"); | ||
var settings = require("../core/settings"); | ||
@@ -21,3 +21,3 @@ settings.set('page_viewed', false); | ||
const defaultPageConfig = function defaultPageConfig() { | ||
var defaultPageConfig = function defaultPageConfig() { | ||
return { | ||
@@ -24,0 +24,0 @@ category: 'page', |
@@ -12,3 +12,3 @@ /*global module, require, window */ | ||
const settings = require("./core/settings"); | ||
var settings = require("./core/settings"); | ||
/** | ||
@@ -19,3 +19,3 @@ * CUID Generator | ||
const cuid = require("../libs/browser-cuid"); | ||
var cuid = require("../libs/browser-cuid"); | ||
/** | ||
@@ -26,3 +26,3 @@ * Record of callbacks to call when a page is tracked. | ||
const page_callbacks = []; | ||
var page_callbacks = []; | ||
/** | ||
@@ -37,3 +37,3 @@ * Log messages to the browser console. Requires 'log' to be set on init. | ||
if (settings.get('developer') && window.console) { | ||
for (let i = 0; i < arguments.length; i++) { | ||
for (var i = 0; i < arguments.length; i++) { | ||
window.console.log(arguments[i]); | ||
@@ -76,5 +76,5 @@ } | ||
let name; | ||
let src; | ||
let copy; | ||
var name; | ||
var src; | ||
var copy; | ||
/* jshint -W089 */ | ||
@@ -189,3 +189,3 @@ | ||
function triggerPage() { | ||
for (let i = 0; i < page_callbacks.length; i++) { | ||
for (var i = 0; i < page_callbacks.length; i++) { | ||
page_callbacks[i](); | ||
@@ -226,5 +226,5 @@ } | ||
let i; | ||
const namespaces = str.split('.'); | ||
let test = window; | ||
var i; | ||
var namespaces = str.split('.'); | ||
var test = window; | ||
@@ -260,3 +260,3 @@ for (i = 0; i < namespaces.length; i = i + 1) { | ||
function assignIfUndefined(subject, target) { | ||
for (const prop in subject) { | ||
for (var prop in subject) { | ||
if (!target[prop]) { | ||
@@ -263,0 +263,0 @@ target[prop] = subject[prop]; |
"use strict"; | ||
// Trace the element and all of its parents, collecting properties as we go | ||
const utils = require("../javascript/utils"); | ||
var utils = require("../javascript/utils"); | ||
const elementPropertiesToCollect = ["nodeName", "className", "id", "href", "text", "role"]; // For a given container element, get the number of elements that match the | ||
var elementPropertiesToCollect = ["nodeName", "className", "id", "href", "text", "role"]; // For a given container element, get the number of elements that match the | ||
// original element (siblings); and the index of the original element (position). | ||
const getSiblingsAndPosition = (el, originalEl, selector) => { | ||
const siblings = Array.from(el.querySelectorAll(selector)); | ||
const position = siblings.findIndex(item => item === originalEl); | ||
var getSiblingsAndPosition = (el, originalEl, selector) => { | ||
var siblings = Array.from(el.querySelectorAll(selector)); | ||
var position = siblings.findIndex(item => item === originalEl); | ||
@@ -24,3 +24,3 @@ if (position === -1) { | ||
const getAllElementProperties = el => { | ||
var getAllElementProperties = el => { | ||
return elementPropertiesToCollect.reduce((returnObject, property) => { | ||
@@ -40,3 +40,3 @@ if (el[property]) { | ||
const getDomPathProps = (attrs, props) => { | ||
var getDomPathProps = (attrs, props) => { | ||
// Collect any attribute that matches given strings. | ||
@@ -50,4 +50,4 @@ attrs.filter(attribute => attribute.name.match(/^data-trackable|^data-o-|^aria-/i)).forEach(attribute => { | ||
const getContextProps = (attrs, props, isOriginalEl) => { | ||
const customProps = {}; // for the original element collect properties like className, nodeName | ||
var getContextProps = (attrs, props, isOriginalEl) => { | ||
var customProps = {}; // for the original element collect properties like className, nodeName | ||
@@ -70,12 +70,12 @@ if (isOriginalEl) { | ||
function getTrace(el) { | ||
const rootEl = document; | ||
const originalEl = el; | ||
const selector = originalEl.getAttribute('data-trackable') ? "[data-trackable=\"".concat(originalEl.getAttribute('data-trackable'), "\"]") : originalEl.nodeName; | ||
const trace = []; | ||
const customContext = {}; | ||
var rootEl = document; | ||
var originalEl = el; | ||
var selector = originalEl.getAttribute('data-trackable') ? "[data-trackable=\"".concat(originalEl.getAttribute('data-trackable'), "\"]") : originalEl.nodeName; | ||
var trace = []; | ||
var customContext = {}; | ||
while (el && el !== rootEl) { | ||
const props = getAllElementProperties(el); | ||
const attrs = Array.from(el.attributes); | ||
let domPathProps = getDomPathProps(attrs, props); // If the element happens to have a data-trackable attribute, get the siblings | ||
var props = getAllElementProperties(el); | ||
var attrs = Array.from(el.attributes); | ||
var domPathProps = getDomPathProps(attrs, props); // If the element happens to have a data-trackable attribute, get the siblings | ||
// and position of the element (relative to the current element). | ||
@@ -88,3 +88,3 @@ | ||
trace.push(domPathProps); | ||
const contextProps = getContextProps(attrs, props, el === originalEl); | ||
var contextProps = getContextProps(attrs, props, el === originalEl); | ||
utils.assignIfUndefined(contextProps, customContext); | ||
@@ -91,0 +91,0 @@ el = el.parentNode; |
@@ -12,2 +12,4 @@ { | ||
"*.json", | ||
"*.js", | ||
"!main.js", | ||
"scss", | ||
@@ -27,3 +29,3 @@ "!bower.json", | ||
"name": "@financial-times/o-tracking", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"description": "Origami module for FT tracking.", | ||
@@ -36,4 +38,5 @@ "dependencies": { | ||
"devDependencies": { | ||
"origami-build-tools": "^7.2.0" | ||
"origami-build-tools": "^7.2.0", | ||
"origami-ci-tools": "^1.0.0" | ||
} | ||
} |
@@ -8,2 +8,4 @@ # Origami Tracking component [![CircleCI](https://circleci.com/gh/Financial-Times/o-tracking.svg?style=svg&circle-token=bac74d66190dbd699381ab25baab148fb3bb010c)](https://circleci.com/gh/Financial-Times/o-tracking) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](#licence) | ||
[Spoor API docs](https://spoor-docs.herokuapp.com/) | ||
## Usage | ||
@@ -10,0 +12,0 @@ |
119771
40
3672
285
2