@financial-times/o-tracking
Advanced tools
Comparing version 1.7.3 to 2.0.0-beta.1
@@ -1,13 +0,30 @@ | ||
/*global require, module */ | ||
'use strict'; // eslint-disable-line strict | ||
"use strict"; | ||
var settings = require("./dist/javascript/core/settings"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.tracking = exports.default = void 0; | ||
var user = require("./dist/javascript/core/user"); | ||
var _settings = _interopRequireDefault(require("./dist/javascript/core/settings")); | ||
var session = require("./dist/javascript/core/session"); | ||
var _user = _interopRequireDefault(require("./dist/javascript/core/user")); | ||
var send = require("./dist/javascript/core/send"); | ||
var _session = _interopRequireDefault(require("./dist/javascript/core/session")); | ||
var core = require("./dist/javascript/core"); | ||
var _send = _interopRequireDefault(require("./dist/javascript/core/send")); | ||
var _custom = _interopRequireDefault(require("./dist/javascript/events/custom")); | ||
var _pageView = _interopRequireDefault(require("./dist/javascript/events/page-view")); | ||
var _click = _interopRequireDefault(require("./dist/javascript/events/click")); | ||
var _utils = _interopRequireDefault(require("./dist/javascript/utils")); | ||
var _core = _interopRequireDefault(require("./dist/javascript/core")); | ||
var _componentView = _interopRequireDefault(require("./dist/javascript/events/component-view")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -17,5 +34,3 @@ * The version of the tracking module. | ||
*/ | ||
var version = '1.4.2'; | ||
var version = '2.0.0'; | ||
/** | ||
@@ -57,6 +72,7 @@ * The source of this event. | ||
if (level) { | ||
settings.set('developer', true); | ||
_settings.default.set('developer', true); | ||
} else { | ||
settings.destroy('developer', null); | ||
settings.destroy('no_send', null); | ||
_settings.default.destroy('developer', null); | ||
_settings.default.destroy('no_send', null); | ||
} | ||
@@ -73,4 +89,6 @@ }; | ||
this.initialised = false; | ||
settings.destroy('config'); | ||
settings.destroy('page_sent'); | ||
_settings.default.destroy('config'); | ||
_settings.default.destroy('page_sent'); | ||
}; | ||
@@ -92,3 +110,3 @@ /** | ||
Tracking.prototype.event = require("./dist/javascript/events/custom"); | ||
Tracking.prototype.event = _custom.default; | ||
/** | ||
@@ -99,3 +117,3 @@ * Make the page tracking request. | ||
Tracking.prototype.page = require("./dist/javascript/events/page-view"); | ||
Tracking.prototype.page = _pageView.default; | ||
/** | ||
@@ -106,3 +124,3 @@ * To initalise view events for components/elements. | ||
Tracking.prototype.view = require("./dist/javascript/events/component-view"); | ||
Tracking.prototype.view = _componentView.default; | ||
/** | ||
@@ -113,3 +131,3 @@ * To initalise click events. | ||
Tracking.prototype.click = require("./dist/javascript/events/click"); | ||
Tracking.prototype.click = _click.default; | ||
/** | ||
@@ -129,3 +147,3 @@ * Previously, the click handler was initialised as "link". | ||
Tracking.prototype.utils = require("./dist/javascript/utils"); | ||
Tracking.prototype.utils = _utils.default; | ||
/** | ||
@@ -136,3 +154,3 @@ * Get the rootID. | ||
Tracking.prototype.getRootID = core.getRootID; | ||
Tracking.prototype.getRootID = _core.default.getRootID; | ||
/** | ||
@@ -183,14 +201,21 @@ * Initialises the Tracking object. | ||
settings.set('version', this.version); | ||
settings.set('source', this.source); | ||
settings.set('api_key', this.api_key); | ||
settings.set('page_sent', false); | ||
_settings.default.set('version', this.version); | ||
_settings.default.set('source', this.source); | ||
_settings.default.set('api_key', this.api_key); | ||
_settings.default.set('page_sent', false); | ||
var cookieDomain = config ? config.cookieDomain : false; // Set up the user from stored - may later be updated by config | ||
user.init(false, cookieDomain); | ||
_user.default.init(false, cookieDomain); | ||
this.updateConfig(config); // Session | ||
session.init(config.session); // Initialize the sending queue. | ||
_session.default.init(config.session); // Initialize the sending queue. | ||
send.init(); | ||
_send.default.init(); | ||
this.event.init(); | ||
@@ -212,6 +237,8 @@ this.page.init(); | ||
Tracking.prototype.updateConfig = function (newConfig) { | ||
var config = settings.get('config') || {}; | ||
var config = _settings.default.get('config') || {}; | ||
config = this.utils.merge(config, newConfig); | ||
settings.set('config', config); // Developer mode | ||
_settings.default.set('config', config); // Developer mode | ||
if (config.developer) { | ||
@@ -221,3 +248,3 @@ this.developer(config.developer); | ||
if (config.noSend) { | ||
settings.set('no_send', true); | ||
_settings.default.set('no_send', true); | ||
} | ||
@@ -227,6 +254,6 @@ } | ||
if (config.user && config.user.user_id) { | ||
user.setUser(config.user.user_id); | ||
_user.default.setUser(config.user.user_id); | ||
} | ||
send.setDomain(); | ||
_send.default.setDomain(); | ||
}; | ||
@@ -289,2 +316,3 @@ /** | ||
var tracking = new Tracking(); | ||
exports.tracking = tracking; | ||
@@ -306,2 +334,3 @@ function initialise() { | ||
module.exports = tracking; | ||
var _default = tracking; | ||
exports.default = _default; |
@@ -1,17 +0,23 @@ | ||
/*global module, require */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.setRootID = setRootID; | ||
exports.getRootID = getRootID; | ||
exports.track = track; | ||
exports.default = void 0; | ||
var Send = require("./core/send"); | ||
var _send = _interopRequireDefault(require("./core/send")); | ||
var User = require("./core/user"); | ||
var _user = _interopRequireDefault(require("./core/user")); | ||
var Session = require("./core/session"); | ||
var _session = _interopRequireDefault(require("./core/session")); | ||
var settings = require("./core/settings"); | ||
var _settings = _interopRequireDefault(require("./core/settings")); | ||
var utils = require("./utils"); | ||
var _utils = _interopRequireDefault(require("./utils")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var rootID; | ||
@@ -25,3 +31,3 @@ /** | ||
function setRootID() { | ||
rootID = utils.guid(); | ||
rootID = _utils.default.guid(); | ||
return rootID; | ||
@@ -53,8 +59,9 @@ } | ||
function track(config, callback) { | ||
if (utils.isUndefined(callback)) { | ||
if (_utils.default.isUndefined(callback)) { | ||
callback = function callback() {}; | ||
} | ||
var session = Session.session(); // Set up the base request object with some values which should always be sent. | ||
var session = _session.default.session(); // Set up the base request object with some values which should always be sent. | ||
var request = { | ||
@@ -64,3 +71,3 @@ async: true, | ||
context: { | ||
id: config.id || utils.guid(), | ||
id: config.id || _utils.default.guid(), | ||
// Use a supplied id or generate one for this request | ||
@@ -70,5 +77,5 @@ root_id: getRootID() | ||
user: { | ||
passport_id: utils.getValueFromCookie(/USERID=([0-9]+):/) || utils.getValueFromCookie(/PID=([0-9]+)\_/), | ||
ft_session: utils.getValueFromCookie(/FTSession=([^;]+)/), | ||
ft_session_s: utils.getValueFromCookie(/FTSession_s=([^;]+)/) | ||
passport_id: _utils.default.getValueFromCookie(/USERID=([0-9]+):/) || _utils.default.getValueFromCookie(/PID=([0-9]+)\_/), | ||
ft_session: _utils.default.getValueFromCookie(/FTSession=([^;]+)/), | ||
ft_session_s: _utils.default.getValueFromCookie(/FTSession_s=([^;]+)/) | ||
}, | ||
@@ -78,32 +85,36 @@ device: { | ||
spoor_session_is_new: session.isNew, | ||
spoor_id: User.userID() | ||
spoor_id: _user.default.userID() | ||
} | ||
}; // Override any context, user, and device values with object-wide settings | ||
var settingsConfig = settings.get('config') || {}; | ||
var settingsConfig = _settings.default.get('config') || {}; | ||
if (settingsConfig.context) { | ||
utils.merge(request.context, settingsConfig.context); | ||
_utils.default.merge(request.context, settingsConfig.context); | ||
} | ||
if (settingsConfig.user) { | ||
utils.merge(request.user, settingsConfig.user); | ||
_utils.default.merge(request.user, settingsConfig.user); | ||
} | ||
if (settingsConfig.device) { | ||
utils.merge(request.device, settingsConfig.device); | ||
_utils.default.merge(request.device, settingsConfig.device); | ||
} // Update the base config with the parameter-supplied config | ||
utils.merge(request, config); | ||
utils.log('Core.Track', request); // Send it. | ||
_utils.default.merge(request, config); | ||
Send.addAndRun(request); | ||
_utils.default.log('Core.Track', request); // Send it. | ||
_send.default.addAndRun(request); | ||
return request; | ||
} | ||
module.exports = { | ||
setRootID: setRootID, | ||
getRootID: getRootID, | ||
track: track | ||
}; | ||
var _default = { | ||
setRootID, | ||
getRootID, | ||
track | ||
}; | ||
exports.default = _default; |
@@ -1,10 +0,14 @@ | ||
/*global module, require */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Queue = exports.default = void 0; | ||
var utils = require("../utils"); | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
var Store = require("./store"); | ||
var _store = _interopRequireDefault(require("./store")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -17,8 +21,7 @@ * Class for handling a queue backed up by a store. | ||
*/ | ||
var Queue = function Queue(name) { | ||
if (utils.isUndefined(name)) { | ||
if (_utils.default.isUndefined(name)) { | ||
var undefinedName = new Error('You must specify a name for the queue.'); | ||
utils.broadcast('oErrors', 'log', { | ||
_utils.default.broadcast('oErrors', 'log', { | ||
error: undefinedName.message, | ||
@@ -29,2 +32,3 @@ info: { | ||
}); | ||
throw undefinedName; | ||
@@ -44,3 +48,3 @@ } | ||
this.storage = new Store(name); // Retrieve any previous store with the same name. | ||
this.storage = new _store.default(name); // Retrieve any previous store with the same name. | ||
@@ -60,2 +64,4 @@ if (this.storage.read()) { | ||
exports.Queue = Queue; | ||
Queue.prototype.all = function () { | ||
@@ -123,3 +129,3 @@ if (this.queue.length === 0) { | ||
if (utils.is(item, 'object') && item.constructor.toString().match(/array/i)) { | ||
if (_utils.default.is(item, 'object') && item.constructor.toString().match(/array/i)) { | ||
for (i = 0; i < item.length; i = i + 1) { | ||
@@ -144,3 +150,3 @@ doAdd(item[i]); | ||
Queue.prototype.replace = function (items) { | ||
if (utils.is(items, 'object') && items.constructor.toString().match(/array/i)) { | ||
if (_utils.default.is(items, 'object') && items.constructor.toString().match(/array/i)) { | ||
this.queue = []; | ||
@@ -152,3 +158,4 @@ this.add(items).save(); | ||
var invalidArg = new Error('Argument invalid, must be an array.'); | ||
utils.broadcast('oErrors', 'log', { | ||
_utils.default.broadcast('oErrors', 'log', { | ||
error: invalidArg.message, | ||
@@ -159,2 +166,3 @@ info: { | ||
}); | ||
throw invalidArg; | ||
@@ -190,2 +198,3 @@ }; | ||
module.exports = Queue; | ||
var _default = Queue; | ||
exports.default = _default; |
@@ -1,15 +0,24 @@ | ||
/*global module, require, window */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.init = init; | ||
exports.setDomain = setDomain; | ||
exports.getDomain = getDomain; | ||
exports.add = add; | ||
exports.run = run; | ||
exports.addAndRun = addAndRun; | ||
exports.default = void 0; | ||
var settings = require("./settings"); | ||
var _settings = _interopRequireDefault(require("./settings")); | ||
var utils = require("../utils"); | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
var Queue = require("./queue"); | ||
var _queue = _interopRequireDefault(require("./queue")); | ||
var transports = require("./transports"); | ||
var _transports = _interopRequireDefault(require("./transports")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var isIe11 = function isIe11() { | ||
@@ -38,3 +47,3 @@ return !!window.MSInputMethodContext && !!document.documentMode; | ||
function should_use_sendBeacon() { | ||
return navigator.sendBeacon && Promise && (settings.get('config') || {}).useSendBeacon; | ||
return navigator.sendBeacon && Promise && (_settings.default.get('config') || {}).useSendBeacon; | ||
} | ||
@@ -53,11 +62,12 @@ /** | ||
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 transport = should_use_sendBeacon() ? _transports.default.get('sendBeacon')() : window.XMLHttpRequest && 'withCredentials' in new window.XMLHttpRequest() ? _transports.default.get('xhr')() : _transports.default.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'), | ||
var core_system = _settings.default.get('config') && _settings.default.get('config').system || {}; | ||
var system = _utils.default.merge(core_system, { | ||
api_key: _settings.default.get('api_key'), | ||
// 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 | ||
version: settings.get('version'), | ||
version: _settings.default.get('version'), | ||
// Version of the tracking client e.g. '1.2' | ||
source: settings.get('source'), | ||
source: _settings.default.get('source'), | ||
// Source of the tracking client e.g. 'o-tracking' | ||
@@ -67,3 +77,4 @@ transport: transport.name // The transport method used. | ||
}); | ||
request = utils.merge({ | ||
request = _utils.default.merge({ | ||
system: system | ||
@@ -81,9 +92,13 @@ }, request); // Only bothered about offlineLag if it's longer than a second, but less than 12 months. (Especially as Date can be dodgy) | ||
delete request.queueTime; | ||
utils.log('user_callback', user_callback); | ||
utils.log('PreSend', request); | ||
_utils.default.log('user_callback', user_callback); | ||
_utils.default.log('PreSend', request); | ||
var stringifiedData = JSON.stringify(request); | ||
transport.complete(function (error) { | ||
if (utils.is(user_callback, 'function')) { | ||
if (_utils.default.is(user_callback, 'function')) { | ||
user_callback.call(request); | ||
utils.log('calling user_callback'); | ||
_utils.default.log('calling user_callback'); | ||
} | ||
@@ -94,4 +109,5 @@ | ||
if (isIe11() && transport.name === 'xhr') { | ||
var image_method = transports.get('image')(); // Append image label to transport value so that we know it tried xhr first | ||
var image_method = _transports.default.get('image')(); // Append image label to transport value so that we know it tried xhr first | ||
request.system.transport = [request.system.transport, image_method.name].join('-'); | ||
@@ -109,3 +125,4 @@ image_method.send(url, JSON.stringify(request)); | ||
queue.add(request).save(); | ||
utils.broadcast('oErrors', 'log', { | ||
_utils.default.broadcast('oErrors', 'log', { | ||
error: error.message, | ||
@@ -129,3 +146,3 @@ info: { | ||
if (!(settings.get('developer') && settings.get('no_send'))) { | ||
if (!(_settings.default.get('developer') && _settings.default.get('no_send'))) { | ||
transport.send(url, stringifiedData); | ||
@@ -151,3 +168,3 @@ } | ||
utils.log('AddedToQueue', queue); | ||
_utils.default.log('AddedToQueue', queue); | ||
} | ||
@@ -163,3 +180,3 @@ /** | ||
function run(callback) { | ||
if (utils.isUndefined(callback)) { | ||
if (_utils.default.isUndefined(callback)) { | ||
callback = function callback() {}; | ||
@@ -224,4 +241,4 @@ } // Investigate queue lengths bug | ||
function setDomain() { | ||
if (settings.get('config') && settings.get('config').server) { | ||
domain = settings.get('config').server; | ||
if (_settings.default.get('config') && _settings.default.get('config').server) { | ||
domain = _settings.default.get('config').server; | ||
} | ||
@@ -236,9 +253,10 @@ } | ||
function init() { | ||
queue = new Queue('requests'); | ||
queue = new _queue.default('requests'); | ||
setDomain(); // If any tracking calls are made whilst offline, try sending them the next time the device comes online | ||
utils.addEvent(window, 'online', function () { | ||
_utils.default.addEvent(window, 'online', function () { | ||
run(); | ||
}); // On startup, try sending any requests queued from a previous session. | ||
run(); | ||
@@ -248,11 +266,14 @@ return queue; | ||
module.exports = { | ||
init: init, | ||
setDomain: setDomain, | ||
getDomain: function getDomain() { | ||
return domain; | ||
}, | ||
add: add, | ||
run: run, | ||
addAndRun: addAndRun | ||
}; | ||
function getDomain() { | ||
return domain; | ||
} | ||
var _default = { | ||
init, | ||
setDomain, | ||
getDomain, | ||
add, | ||
run, | ||
addAndRun | ||
}; | ||
exports.default = _default; |
@@ -1,7 +0,16 @@ | ||
/*global module, require */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.session = getSession; | ||
exports.init = init; | ||
exports.default = void 0; | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
var _store = _interopRequireDefault(require("./store")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var store; | ||
@@ -14,6 +23,2 @@ var defaultSessionConfig = { | ||
}; | ||
var utils = require("../utils"); | ||
var Store = require("./store"); | ||
/** | ||
@@ -26,3 +31,2 @@ * Set the session in the store. | ||
function setSession(session) { | ||
@@ -59,3 +63,3 @@ var d = new Date(); | ||
if (!session) { | ||
session = utils.guid(); | ||
session = _utils.default.guid(); | ||
isNew = true; | ||
@@ -80,3 +84,3 @@ } // Refreshes the cookie... | ||
function init(config) { | ||
if (utils.is(config, 'string')) { | ||
if (_utils.default.is(config, 'string')) { | ||
config = { | ||
@@ -87,8 +91,9 @@ name: config | ||
if (utils.isUndefined(config)) { | ||
if (_utils.default.isUndefined(config)) { | ||
config = {}; | ||
} | ||
var c = utils.merge(defaultSessionConfig, config); // config.name is important here, means the user has specifically asked for a cookie name. | ||
var c = _utils.default.merge(defaultSessionConfig, config); // config.name is important here, means the user has specifically asked for a cookie name. | ||
if (c.storage === 'cookie' && config.name) { | ||
@@ -98,9 +103,10 @@ c.nameOverride = c.name; | ||
store = new Store(c.name, c); | ||
store = new _store.default(c.name, c); | ||
return getSession(); | ||
} | ||
module.exports = { | ||
init: init, | ||
var _default = { | ||
init, | ||
session: getSession | ||
}; | ||
}; | ||
exports.default = _default; |
@@ -1,7 +0,8 @@ | ||
/*global module */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.destroy = destroy; | ||
exports.get = exports.set = exports.default = void 0; | ||
var settings = {}; | ||
@@ -68,6 +69,11 @@ /** | ||
module.exports = { | ||
'set': setValue, | ||
'get': getValue, | ||
'destroy': destroy | ||
}; | ||
var set = setValue; | ||
exports.set = set; | ||
var get = getValue; | ||
exports.get = get; | ||
var _default = { | ||
set, | ||
get, | ||
destroy | ||
}; | ||
exports.default = _default; |
@@ -1,7 +0,12 @@ | ||
/*global module, require, window */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Store = exports.default = void 0; | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -15,3 +20,2 @@ * Class for storing data | ||
*/ | ||
var Store = function Store(name, config) { | ||
@@ -29,7 +33,6 @@ /** | ||
var utils = require("../utils"); | ||
if (_utils.default.isUndefined(name)) { | ||
var undefinedName = new Error('You must specify a name for the store.'); | ||
if (utils.isUndefined(name)) { | ||
var undefinedName = new Error('You must specify a name for the store.'); | ||
utils.broadcast('oErrors', 'log', { | ||
_utils.default.broadcast('oErrors', 'log', { | ||
error: undefinedName.message, | ||
@@ -40,6 +43,7 @@ info: { | ||
}); | ||
throw undefinedName; | ||
} | ||
this.config = utils.merge({ | ||
this.config = _utils.default.merge({ | ||
storage: 'best', | ||
@@ -89,3 +93,3 @@ expires: 10 * 365 * 24 * 60 * 60 * 1000 | ||
} catch (error) { | ||
utils.broadcast('oErrors', 'log', { | ||
_utils.default.broadcast('oErrors', 'log', { | ||
error: error.message, | ||
@@ -109,3 +113,3 @@ info: { | ||
if (cookie.indexOf(name) === 0) { | ||
return utils.decode(cookie.substring(name.length, cookie.length)); | ||
return _utils.default.decode(cookie.substring(name.length, cookie.length)); | ||
} | ||
@@ -122,3 +126,3 @@ } | ||
if (utils.is(expiry, 'number')) { | ||
if (_utils.default.is(expiry, 'number')) { | ||
d = new Date(); | ||
@@ -129,3 +133,3 @@ d.setTime(d.getTime() + expiry); | ||
cookie = utils.encode(name) + '=' + utils.encode(value) + ';' + expires + 'path=/;' + (config.domain ? 'domain=.' + config.domain + ';' : ''); | ||
cookie = _utils.default.encode(name) + '=' + _utils.default.encode(value) + ';' + expires + 'path=/;' + (config.domain ? 'domain=.' + config.domain + ';' : ''); | ||
window.document.cookie = cookie; | ||
@@ -165,6 +169,7 @@ } | ||
} catch (error) { | ||
utils.broadcast('oErrors', 'log', { | ||
_utils.default.broadcast('oErrors', 'log', { | ||
error: error.message, | ||
module: 'o-tracking' | ||
}); | ||
this.data = loadStore; | ||
@@ -183,2 +188,4 @@ } | ||
exports.Store = Store; | ||
Store.prototype.read = function () { | ||
@@ -213,2 +220,3 @@ return this.data; | ||
module.exports = Store; | ||
var _default = Store; | ||
exports.default = _default; |
"use strict"; | ||
var utils = require("../../utils"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.image = image; | ||
exports.default = void 0; | ||
module.exports = function () { | ||
var _utils = _interopRequireDefault(require("../../utils")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function image() { | ||
var image = new Image(1, 1); | ||
@@ -11,3 +19,3 @@ return { | ||
url = url.replace('https://spoor-api.ft.com/ingest', 'https://spoor-api.ft.com/px.gif'); | ||
image.src = url + (url.indexOf('?') > -1 ? '&' : '?') + 'data=' + utils.encode(data); | ||
image.src = url + (url.indexOf('?') > -1 ? '&' : '?') + 'data=' + _utils.default.encode(data); | ||
}, | ||
@@ -25,2 +33,5 @@ complete: function complete(callback) { | ||
}; | ||
}; | ||
} | ||
var _default = image; | ||
exports.default = _default; |
"use strict"; | ||
module.exports = { | ||
xhr: require("./xhr"), | ||
sendBeacon: require("./send-beacon"), | ||
image: require("./image"), | ||
get: function get(name) { | ||
return this.mock || this[name]; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.get = get; | ||
Object.defineProperty(exports, "xhr", { | ||
enumerable: true, | ||
get: function get() { | ||
return _xhr.default; | ||
} | ||
}; | ||
}); | ||
Object.defineProperty(exports, "sendBeacon", { | ||
enumerable: true, | ||
get: function get() { | ||
return _sendBeacon.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "image", { | ||
enumerable: true, | ||
get: function get() { | ||
return _image.default; | ||
} | ||
}); | ||
exports.default = void 0; | ||
var _xhr = _interopRequireDefault(require("./xhr")); | ||
var _sendBeacon = _interopRequireDefault(require("./send-beacon")); | ||
var _image = _interopRequireDefault(require("./image")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function get(name) { | ||
return this.mock || this[name]; | ||
} | ||
var _default = { | ||
xhr: _xhr.default, | ||
sendBeacon: _sendBeacon.default, | ||
image: _image.default, | ||
get | ||
}; | ||
exports.default = _default; |
"use strict"; | ||
module.exports = function () { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.sendBeacon = sendBeacon; | ||
exports.default = void 0; | ||
function sendBeacon() { | ||
var resolver; | ||
@@ -25,2 +31,5 @@ var rejecter; | ||
}; | ||
}; | ||
} | ||
var _default = sendBeacon; | ||
exports.default = _default; |
"use strict"; | ||
module.exports = function () { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.xhr = xhr; | ||
exports.default = void 0; | ||
function xhr() { | ||
var xhr = new window.XMLHttpRequest(); | ||
@@ -27,2 +33,5 @@ return { | ||
}; | ||
}; | ||
} | ||
var _default = xhr; | ||
exports.default = _default; |
@@ -1,14 +0,20 @@ | ||
/*global module, require */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.init = init; | ||
exports.setUser = setUser; | ||
exports.userID = id; | ||
exports.destroy = destroy; | ||
exports.default = void 0; | ||
var _userID; | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
var store; | ||
var _store = _interopRequireDefault(require("./store")); | ||
var utils = require("../utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Store = require("./store"); | ||
var userID; | ||
var store; | ||
/** | ||
@@ -22,3 +28,2 @@ * Init | ||
function init(value, cookieDomain) { | ||
@@ -38,3 +43,3 @@ var defaultUserConfig = { | ||
store = new Store(defaultUserConfig.name, defaultUserConfig); | ||
store = new _store.default(defaultUserConfig.name, defaultUserConfig); | ||
var id = store.read(); | ||
@@ -57,11 +62,11 @@ | ||
function setUser(id) { | ||
_userID = id; | ||
userID = id; | ||
if (!_userID) { | ||
_userID = utils.guid(); | ||
if (!userID) { | ||
userID = _utils.default.guid(); | ||
} | ||
store.write(_userID); // Refreshes the cookie... | ||
store.write(userID); // Refreshes the cookie... | ||
return _userID; | ||
return userID; | ||
} | ||
@@ -78,9 +83,12 @@ /** | ||
module.exports = { | ||
init: init, | ||
setUser: setUser, | ||
userID: function userID() { | ||
return _userID; | ||
}, | ||
destroy: destroy | ||
}; | ||
function id() { | ||
return userID; | ||
} | ||
var _default = { | ||
init, | ||
setUser, | ||
userID: id, | ||
destroy | ||
}; | ||
exports.default = _default; |
@@ -1,16 +0,22 @@ | ||
/*global module, require */ | ||
'use strict'; // eslint-disable-line strict | ||
"use strict"; | ||
var Delegate = require("ftdomdelegate"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.init = exports.default = void 0; | ||
var Queue = require("../core/queue"); | ||
var _ftdomdelegate = _interopRequireDefault(require("ftdomdelegate")); | ||
var Core = require("../core"); | ||
var _queue = _interopRequireDefault(require("../core/queue")); | ||
var utils = require("../utils"); | ||
var _core = _interopRequireDefault(require("../core")); | ||
var settings = require("../core/settings"); | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
var getTrace = require("../../libs/get-trace"); | ||
var _settings = _interopRequireDefault(require("../core/settings")); | ||
var _getTrace = _interopRequireDefault(require("../../libs/get-trace")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var internalQueue; | ||
@@ -27,3 +33,3 @@ var eventPropertiesToCollect = ["ctrlKey", "altKey", "shiftKey", "metaKey"]; // Trigger the event tracking | ||
if (isInternal && !skipQueue) { | ||
eventData.context.source_id = Core.getRootID(); // Queue the event and send it on the next page load | ||
eventData.context.source_id = _core.default.getRootID(); // Queue the event and send it on the next page load | ||
@@ -34,3 +40,4 @@ internalQueue.add(eventData).save(); | ||
eventData.async = false; | ||
Core.track(eventData); | ||
_core.default.track(eventData); | ||
} | ||
@@ -45,3 +52,3 @@ }; // Get properties for the event (as opposed to properties of the clicked element) | ||
if (event[property]) { | ||
returnObject[property] = utils.sanitise(event[property]); | ||
returnObject[property] = _utils.default.sanitise(event[property]); | ||
} | ||
@@ -68,9 +75,12 @@ } catch (e) { | ||
customContext | ||
} = getTrace(clickElement); | ||
} = (0, _getTrace.default)(clickElement); | ||
context.domPathTokens = trace; | ||
context.url = window.document.location.href || null; | ||
utils.assignIfUndefined(customContext, context); | ||
_utils.default.assignIfUndefined(customContext, context); | ||
eventData.context = context; // Merge the event data into the "parent" config data | ||
var config = utils.merge(settings.get('config'), eventData); | ||
var config = _utils.default.merge(_settings.default.get('config'), eventData); | ||
track(config); | ||
@@ -95,3 +105,3 @@ }; | ||
if (nextLink) { | ||
Core.track(nextLink, next); | ||
_core.default.track(nextLink, next); | ||
} | ||
@@ -120,13 +130,15 @@ }; | ||
var delegate = new Delegate(document.body); | ||
var delegate = new _ftdomdelegate.default(document.body); | ||
delegate.on('click', elementsToTrack, handleClickEvent(eventData), true); // Track any queued events | ||
internalQueue = new Queue('clicks'); | ||
internalQueue = new _queue.default('clicks'); | ||
runQueue(); // Listen for page requests. If this is a single page app, we can send link requests now. | ||
utils.onPage(runQueue); | ||
_utils.default.onPage(runQueue); | ||
}; | ||
module.exports = { | ||
init: init | ||
}; | ||
exports.init = init; | ||
var _default = { | ||
init | ||
}; | ||
exports.default = _default; |
@@ -1,10 +0,16 @@ | ||
/*global module, require */ | ||
'use strict'; // eslint-disable-line strict | ||
"use strict"; | ||
var Core = require("../core"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.init = exports.default = void 0; | ||
var getTrace = require("../../libs/get-trace"); | ||
var _core = _interopRequireDefault(require("../core")); | ||
var utils = require("../utils"); | ||
var _getTrace = _interopRequireDefault(require("../../libs/get-trace")); | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var TRACKING_ATTRIBUTES = ['componentContentId', 'type', 'subtype', 'component']; | ||
@@ -16,3 +22,3 @@ | ||
customContext | ||
} = getTrace(viewedEl); | ||
} = (0, _getTrace.default)(viewedEl); | ||
var context; | ||
@@ -31,3 +37,3 @@ | ||
context = utils.whitelistProps(dataBeforeWhitelist, TRACKING_ATTRIBUTES); | ||
context = _utils.default.whitelistProps(dataBeforeWhitelist, TRACKING_ATTRIBUTES); | ||
} else { | ||
@@ -39,3 +45,5 @@ context = {}; | ||
context.url = window.document.location.href || null; | ||
utils.assignIfUndefined(customContext, context); | ||
_utils.default.assignIfUndefined(customContext, context); | ||
eventData.context = context; | ||
@@ -76,3 +84,5 @@ }; | ||
decorateEventData(eventData, viewedEl, opts); | ||
Core.track(eventData); | ||
_core.default.track(eventData); | ||
this.unobserve(viewedEl); | ||
@@ -89,4 +99,4 @@ } | ||
module.exports = { | ||
init: init | ||
}; | ||
exports.init = init; | ||
var _default = init; | ||
exports.default = _default; |
@@ -1,10 +0,15 @@ | ||
/*global module, require */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.event = event; | ||
exports.default = void 0; | ||
var Core = require("../core"); | ||
var _core = _interopRequireDefault(require("../core")); | ||
var utils = require("../utils"); | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -16,4 +21,2 @@ * Default properties for events. | ||
*/ | ||
var defaultEventConfig = function defaultEventConfig() { | ||
@@ -40,5 +43,6 @@ return { | ||
function event(trackingEvent, callback) { | ||
if (utils.is(trackingEvent.detail.category) || utils.is(trackingEvent.detail.action)) { | ||
if (_utils.default.is(trackingEvent.detail.category) || _utils.default.is(trackingEvent.detail.action)) { | ||
var noCategoryActionVals = 'Missing category or action values'; | ||
utils.broadcast('oErrors', 'log', { | ||
_utils.default.broadcast('oErrors', 'log', { | ||
error: noCategoryActionVals, | ||
@@ -49,6 +53,7 @@ info: { | ||
}); | ||
throw noCategoryActionVals; | ||
} | ||
var config = utils.merge(defaultEventConfig(), { | ||
var config = _utils.default.merge(defaultEventConfig(), { | ||
category: trackingEvent.detail.category, | ||
@@ -58,2 +63,3 @@ action: trackingEvent.detail.action, | ||
}); | ||
delete config.context.category; | ||
@@ -71,3 +77,3 @@ delete config.context.action; | ||
Core.track(config, callback); | ||
_core.default.track(config, callback); | ||
} | ||
@@ -230,6 +236,8 @@ /** | ||
module.exports = event; | ||
var init = function init() { | ||
_utils.default.addEvent(window, 'oTracking.event', event); | ||
}; | ||
module.exports.init = function () { | ||
utils.addEvent(window, 'oTracking.event', event); | ||
}; | ||
event.init = init; | ||
var _default = event; | ||
exports.default = _default; |
@@ -1,14 +0,18 @@ | ||
/*global module, require */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.page = page; | ||
exports.default = void 0; | ||
var Core = require("../core"); | ||
var _core = _interopRequireDefault(require("../core")); | ||
var utils = require("../utils"); | ||
var _utils = _interopRequireDefault(require("../utils")); | ||
var settings = require("../core/settings"); | ||
var _settings = _interopRequireDefault(require("../core/settings")); | ||
settings.set('page_viewed', false); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
_settings.default.set('page_viewed', false); | ||
/** | ||
@@ -20,2 +24,3 @@ * Default properties for page tracking requests. | ||
var defaultPageConfig = function defaultPageConfig() { | ||
@@ -43,14 +48,16 @@ return { | ||
function page(config, callback) { | ||
config = utils.merge(defaultPageConfig(), { | ||
config = _utils.default.merge(defaultPageConfig(), { | ||
context: config | ||
}); // New PageID for a new Page... Unless... It's the first pageview, and some events may have been sent before this. | ||
if (settings.get('page_viewed')) { | ||
Core.setRootID(); | ||
if (_settings.default.get('page_viewed')) { | ||
_core.default.setRootID(); | ||
} | ||
Core.track(config, callback); // Alert internally that a new page has been tracked - for single page apps for example. | ||
_core.default.track(config, callback); // Alert internally that a new page has been tracked - for single page apps for example. | ||
settings.set('page_viewed', true); | ||
utils.triggerPage(); | ||
_settings.default.set('page_viewed', true); | ||
_utils.default.triggerPage(); | ||
} | ||
@@ -70,6 +77,8 @@ /** | ||
module.exports = page; | ||
var init = function init() { | ||
_utils.default.addEvent(window, 'oTracking.page', listener); | ||
}; | ||
module.exports.init = function () { | ||
utils.addEvent(window, 'oTracking.page', listener); | ||
}; | ||
page.init = init; | ||
var _default = page; | ||
exports.default = _default; |
@@ -1,7 +0,35 @@ | ||
/*global module, require, window */ | ||
"use strict"; | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.log = log; | ||
exports.isUndefined = exports.is = is; | ||
exports.merge = merge; | ||
exports.encode = encode; | ||
exports.decode = decode; | ||
exports.addEvent = addEvent; | ||
exports.broadcast = broadcast; | ||
exports.onPage = onPage; | ||
exports.triggerPage = triggerPage; | ||
exports.getValueFromCookie = getValueFromCookie; | ||
exports.getValueFromUrl = getValueFromUrl; | ||
exports.getValueFromJsVariable = getValueFromJsVariable; | ||
exports.sanitise = sanitise; | ||
exports.assignIfUndefined = assignIfUndefined; | ||
exports.whitelistProps = whitelistProps; | ||
Object.defineProperty(exports, "guid", { | ||
enumerable: true, | ||
get: function get() { | ||
return _browserCuid.default; | ||
} | ||
}); | ||
exports.default = void 0; | ||
var _settings = _interopRequireDefault(require("./core/settings")); | ||
var _browserCuid = _interopRequireDefault(require("../libs/browser-cuid")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -12,3 +40,2 @@ * Shared 'internal' scope. | ||
var settings = require("./core/settings"); | ||
/** | ||
@@ -18,9 +45,5 @@ * CUID Generator | ||
var cuid = require("../libs/browser-cuid"); | ||
/** | ||
* Record of callbacks to call when a page is tracked. | ||
*/ | ||
var page_callbacks = []; | ||
@@ -35,3 +58,3 @@ /** | ||
function log() { | ||
if (settings.get('developer') && window.console) { | ||
if (_settings.default.get('developer') && window.console) { | ||
for (var i = 0; i < arguments.length; i++) { | ||
@@ -238,2 +261,15 @@ window.console.log(arguments[i]); | ||
/** | ||
* Whitelist props | ||
* @param {Object} props - An object whose props need to be whitelisted | ||
* @param {Array} list - A list for whitelisting | ||
* @return | ||
*/ | ||
function whitelistProps(props, list) { | ||
return list.reduce((acc, propName) => Object.assign({}, acc, props[propName] ? { | ||
[propName]: props[propName] | ||
} : undefined), {}); | ||
} | ||
/** | ||
* Trim strings | ||
@@ -266,15 +302,2 @@ * @param {String} str - The string to trim. | ||
/** | ||
* Whitelist props | ||
* @param {Object} props - An object whose props need to be whitelisted | ||
* @param {Array} list - A list for whitelisting | ||
* @return | ||
*/ | ||
function whitelistProps(props, list) { | ||
return list.reduce((acc, propName) => Object.assign({}, acc, props[propName] ? { | ||
[propName]: props[propName] | ||
} : undefined), {}); | ||
} | ||
/** | ||
* Utilities. | ||
@@ -285,20 +308,21 @@ * @alias utils | ||
module.exports = { | ||
log: log, | ||
is: is, | ||
var _default = { | ||
log, | ||
is, | ||
isUndefined: is, | ||
merge: merge, | ||
encode: encode, | ||
decode: decode, | ||
guid: cuid, | ||
addEvent: addEvent, | ||
broadcast: broadcast, | ||
onPage: onPage, | ||
triggerPage: triggerPage, | ||
getValueFromCookie: getValueFromCookie, | ||
getValueFromUrl: getValueFromUrl, | ||
getValueFromJsVariable: getValueFromJsVariable, | ||
sanitise: sanitise, | ||
assignIfUndefined: assignIfUndefined, | ||
whitelistProps: whitelistProps | ||
}; | ||
merge, | ||
encode, | ||
decode, | ||
guid: _browserCuid.default, | ||
addEvent, | ||
broadcast, | ||
onPage, | ||
triggerPage, | ||
getValueFromCookie, | ||
getValueFromUrl, | ||
getValueFromJsVariable, | ||
sanitise, | ||
assignIfUndefined, | ||
whitelistProps | ||
}; | ||
exports.default = _default; |
"use strict"; | ||
/*eslint-disable*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.api = exports.default = void 0; | ||
@@ -16,86 +19,78 @@ /** | ||
*/ | ||
var c = 0; | ||
var blockSize = 4; | ||
var base = 36; | ||
var discreteValues = Math.pow(base, blockSize); | ||
/*global window, navigator, document, require, process, module */ | ||
(function (app) { | ||
'use strict'; | ||
var pad = function pad(num, size) { | ||
var s = "000000000" + num; | ||
return s.substr(s.length - size); | ||
}; | ||
var namespace = 'cuid', | ||
c = 0, | ||
blockSize = 4, | ||
base = 36, | ||
discreteValues = Math.pow(base, blockSize), | ||
pad = function pad(num, size) { | ||
var s = "000000000" + num; | ||
return s.substr(s.length - size); | ||
}, | ||
randomBlock = function randomBlock() { | ||
return pad((Math.random() * discreteValues << 0).toString(base), blockSize); | ||
}, | ||
safeCounter = function safeCounter() { | ||
c = c < discreteValues ? c : 0; | ||
c++; // this is not subliminal | ||
var randomBlock = function randomBlock() { | ||
return pad((Math.random() * discreteValues << 0).toString(base), blockSize); | ||
}; | ||
return c - 1; | ||
}, | ||
api = function cuid() { | ||
// Starting with a lowercase letter makes | ||
// it HTML element ID friendly. | ||
var letter = 'c', | ||
// hard-coded allows for sequential access | ||
// timestamp | ||
// warning: this exposes the exact date and time | ||
// that the uid was created. | ||
timestamp = new Date().getTime().toString(base), | ||
// Prevent same-machine collisions. | ||
counter, | ||
// A few chars to generate distinct ids for different | ||
// clients (so different computers are far less | ||
// likely to generate the same id) | ||
fingerprint = api.fingerprint(), | ||
// Grab some more chars from Math.random() | ||
random = randomBlock() + randomBlock(); | ||
counter = pad(safeCounter().toString(base), blockSize); | ||
return letter + timestamp + counter + fingerprint + random; | ||
}; | ||
var safeCounter = () => { | ||
c = c < discreteValues ? c : 0; | ||
c++; // this is not subliminal | ||
api.slug = function slug() { | ||
var date = new Date().getTime().toString(36), | ||
counter, | ||
print = api.fingerprint().slice(0, 1) + api.fingerprint().slice(-1), | ||
random = randomBlock().slice(-2); | ||
counter = safeCounter().toString(36).slice(-4); | ||
return date.slice(-2) + counter + print + random; | ||
}; | ||
return c - 1; | ||
}; | ||
api.globalCount = function globalCount() { | ||
// We want to cache the results of this | ||
var cache = function calc() { | ||
var i, | ||
count = 0; | ||
var api = function cuid() { | ||
// Starting with a lowercase letter makes | ||
// it HTML element ID friendly. | ||
// hard-coded allows for sequential access | ||
var letter = 'c'; // timestamp | ||
// warning: this exposes the exact date and time | ||
// that the uid was created. | ||
for (i in window) { | ||
count++; | ||
} | ||
var timestamp = new Date().getTime().toString(base); // Prevent same-machine collisions. | ||
return count; | ||
}(); | ||
var counter; // A few chars to generate distinct ids for different | ||
// clients (so different computers are far less | ||
// likely to generate the same id) | ||
api.globalCount = function () { | ||
return cache; | ||
}; | ||
var fingerprint = api.fingerprint(); // Grab some more chars from Math.random() | ||
return cache; | ||
}; | ||
var random = randomBlock() + randomBlock(); | ||
counter = pad(safeCounter().toString(base), blockSize); | ||
return letter + timestamp + counter + fingerprint + random; | ||
}; | ||
api.fingerprint = function browserPrint() { | ||
return pad((navigator.mimeTypes.length + navigator.userAgent.length).toString(36) + api.globalCount().toString(36), 4); | ||
}; // don't change anything from here down. | ||
exports.api = api; | ||
api.slug = function slug() { | ||
var date = new Date().getTime().toString(36); | ||
var counter; | ||
var print = api.fingerprint().slice(0, 1) + api.fingerprint().slice(-1); | ||
var random = randomBlock().slice(-2); | ||
counter = safeCounter().toString(36).slice(-4); | ||
return date.slice(-2) + counter + print + random; | ||
}; | ||
if (typeof module !== 'undefined') { | ||
module.exports = api; | ||
} else { | ||
app[namespace] = api; | ||
} | ||
})(void 0); | ||
/*eslint-enable */ | ||
api.globalCount = function globalCount() { | ||
// We want to cache the results of this | ||
var cache = function calc() { | ||
var count = 0; | ||
for (var i in window) { | ||
// eslint-disable-line no-unused-vars, guard-for-in | ||
count++; | ||
} | ||
return count; | ||
}(); | ||
api.globalCount = () => cache; | ||
return cache; | ||
}; | ||
api.fingerprint = function browserPrint() { | ||
return pad((navigator.mimeTypes.length + navigator.userAgent.length).toString(36) + api.globalCount().toString(36), 4); | ||
}; | ||
var _default = api; | ||
exports.default = _default; |
"use strict"; | ||
var _utils = _interopRequireDefault(require("../javascript/utils")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// Trace the element and all of its parents, collecting properties as we go | ||
var utils = require("../javascript/utils"); | ||
var elementPropertiesToCollect = ["nodeName", "className", "id", "href", "text", "role"]; // For a given container element, get the number of elements that match the | ||
@@ -27,5 +29,5 @@ // original element (siblings); and the index of the original element (position). | ||
if (el[property]) { | ||
returnObject[property] = utils.sanitise(el[property]); | ||
returnObject[property] = _utils.default.sanitise(el[property]); | ||
} else if (el.getAttribute(property)) { | ||
returnObject[property] = utils.sanitise(el.getAttribute(property)); | ||
returnObject[property] = _utils.default.sanitise(el.getAttribute(property)); | ||
} else if (el.hasAttribute(property)) { | ||
@@ -86,3 +88,5 @@ returnObject[property] = el.hasAttribute(property); | ||
var contextProps = getContextProps(attrs, props, el === originalEl); | ||
utils.assignIfUndefined(contextProps, customContext); | ||
_utils.default.assignIfUndefined(contextProps, customContext); | ||
el = el.parentNode; | ||
@@ -89,0 +93,0 @@ } |
@@ -28,6 +28,6 @@ { | ||
"name": "@financial-times/o-tracking", | ||
"version": "1.7.3", | ||
"version": "2.0.0-beta.1", | ||
"description": "Origami module for FT tracking.", | ||
"dependencies": { | ||
"ftdomdelegate": ">=2.2.0 <4.0.0" | ||
"ftdomdelegate": "v4.0.0-beta.1" | ||
}, | ||
@@ -34,0 +34,0 @@ "component": "o-tracking", |
@@ -5,2 +5,10 @@ # 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) | ||
- [The spoor ecosystem](#the-spoor-ecosystem) | ||
- [Usage](#usage) | ||
- [Events](#events) | ||
- [Parameters](#parameters) | ||
- [Migration Guide](#migration-guide) | ||
- [Contact](#contact) | ||
- [Licence](#licence) | ||
## The Spoor ecosystem | ||
@@ -76,3 +84,3 @@ ![ScreenShot](https://rawgit.com/Financial-Times/o-tracking/master/resources/images/ngda-system-design.svg) | ||
```js | ||
var oTracking = require('o-tracking'); | ||
import oTracking from 'o-tracking'; | ||
``` | ||
@@ -199,5 +207,5 @@ | ||
* Click events [initalised as above](#usage), will populate a `domPathTokens` property. If the clicked element has the `data-trackable` attribute, sibling elements will also be included within `domPathTokens`. | ||
* View events are fired for elements with the `data-o-tracking-view` attribute by default, unless `o-tracking`'s `selector` option is configured. Like click events, view events populate a `domPathTokens` property. To collect data for events, set the `category` option, or provide a callback[`getContextData`] | ||
_Note:_ This feature requires `window.IntersectionObserver` in order to track the events | ||
_Note:_ `getContextData` should be a function which returns `{Object}`. It accepts the viewed element as an argument | ||
* View events are fired for elements with the `data-o-tracking-view` attribute by default, unless `o-tracking`'s `selector` option is configured. Like click events, view events populate a `domPathTokens` property. To collect data for events, set the `category` option, or provide a callback[`getContextData`] | ||
_Note:_ This feature requires `window.IntersectionObserver` in order to track the events | ||
_Note:_ `getContextData` should be a function which returns `{Object}`. It accepts the viewed element as an argument | ||
```js | ||
@@ -288,1 +296,21 @@ const opts = { | ||
[JSDoc](https://registry.origami.ft.com/components/o-tracking/jsdoc#Tracking) | ||
## Migration Guide | ||
| State | Major Version | Last Minor Release | Migration guide | | ||
| :---: | :---: | :---: | :---: | | ||
| ✨ active | 2 | N/A | [migrate to v2](MIGRATION.md#migrating-from-v1-to-v2) | | ||
| ╳ deprecated | 1 | 1.7.2 | N/A | | ||
--- | ||
## Contact | ||
If you have any questions or comments about this component, or need help using it, please either [raise an issue](https://github.com/Financial-Times/o-tracking/issues), visit [#ft-origami](https://financialtimes.slack.com/messages/ft-origami/) or email [Origami Support](mailto:origami-support@ft.com). | ||
--- | ||
## Licence | ||
This software is published by the Financial Times under the [MIT licence](http://opensource.org/licenses/MIT). |
@@ -1,11 +0,7 @@ | ||
/*global module, require */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
import Send from './core/send'; | ||
const Send = require('./core/send'); | ||
const User = require('./core/user'); | ||
const Session = require('./core/session'); | ||
const settings = require('./core/settings'); | ||
const utils = require('./utils'); | ||
import User from './core/user'; | ||
import Session from './core/session'; | ||
import settings from './core/settings'; | ||
import utils from './utils'; | ||
@@ -92,7 +88,11 @@ let rootID; | ||
} | ||
module.exports = { | ||
setRootID: setRootID, | ||
getRootID: getRootID, | ||
track: track | ||
export default { | ||
setRootID, | ||
getRootID, | ||
track | ||
}; | ||
export { | ||
setRootID, | ||
getRootID, | ||
track | ||
}; |
@@ -1,9 +0,4 @@ | ||
/*global module, require */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
import utils from '../utils'; | ||
import Store from './store'; | ||
const utils = require('../utils'); | ||
const Store = require('./store'); | ||
/** | ||
@@ -173,2 +168,3 @@ * Class for handling a queue backed up by a store. | ||
module.exports = Queue; | ||
export default Queue; | ||
export { Queue }; |
@@ -1,10 +0,6 @@ | ||
/*global module, require, window */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
import settings from './settings'; | ||
import utils from '../utils'; | ||
import Queue from './queue'; | ||
import transports from './transports'; | ||
const settings = require('./settings'); | ||
const utils = require('../utils'); | ||
const Queue = require('./queue'); | ||
const transports = require('./transports'); | ||
const isIe11 = function () { return !!window.MSInputMethodContext && !!document.documentMode; }; | ||
@@ -229,9 +225,21 @@ /** | ||
module.exports = { | ||
init: init, | ||
setDomain: setDomain, | ||
getDomain: function () { return domain;}, | ||
add: add, | ||
run: run, | ||
addAndRun: addAndRun | ||
function getDomain() { | ||
return domain; | ||
} | ||
export default { | ||
init, | ||
setDomain, | ||
getDomain, | ||
add, | ||
run, | ||
addAndRun | ||
}; | ||
export { | ||
init, | ||
setDomain, | ||
getDomain, | ||
add, | ||
run, | ||
addAndRun | ||
}; |
@@ -1,5 +0,3 @@ | ||
/*global module, require */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
import utils from '../utils'; | ||
import Store from './store'; | ||
@@ -13,5 +11,2 @@ let store; | ||
const utils = require('../utils'); | ||
const Store = require('./store'); | ||
/** | ||
@@ -94,6 +89,6 @@ * Set the session in the store. | ||
} | ||
module.exports = { | ||
init: init, | ||
export default { | ||
init, | ||
session: getSession | ||
}; | ||
export { getSession as session, init }; |
@@ -1,5 +0,1 @@ | ||
/*global module */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
@@ -60,7 +56,14 @@ const settings = {}; | ||
} | ||
const set = setValue; | ||
const get = getValue; | ||
module.exports = { | ||
'set': setValue, | ||
'get': getValue, | ||
'destroy': destroy | ||
export default { | ||
set, | ||
get, | ||
destroy | ||
}; | ||
export { | ||
set, | ||
get, | ||
destroy | ||
}; |
@@ -1,5 +0,2 @@ | ||
/*global module, require, window */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
import utils from '../utils'; | ||
@@ -26,3 +23,2 @@ /** | ||
let loadStore; | ||
const utils = require('../utils'); | ||
@@ -195,2 +191,3 @@ if (utils.isUndefined(name)) { | ||
module.exports = Store; | ||
export default Store; | ||
export { Store }; |
@@ -1,4 +0,4 @@ | ||
const utils = require('../../utils'); | ||
import utils from '../../utils'; | ||
module.exports = function () { | ||
function image () { | ||
const image = new Image(1,1); | ||
@@ -22,2 +22,5 @@ | ||
}; | ||
}; | ||
} | ||
export default image; | ||
export { image }; |
@@ -1,8 +0,20 @@ | ||
module.exports = { | ||
xhr: require('./xhr'), | ||
sendBeacon: require('./send-beacon'), | ||
image: require('./image'), | ||
get: function (name) { | ||
return this.mock || this[name]; | ||
} | ||
import xhr from './xhr'; | ||
import sendBeacon from './send-beacon'; | ||
import image from './image'; | ||
function get(name) { | ||
return this.mock || this[name]; | ||
} | ||
export default { | ||
xhr, | ||
sendBeacon, | ||
image, | ||
get | ||
}; | ||
export { | ||
xhr, | ||
sendBeacon, | ||
image, | ||
get | ||
}; |
@@ -1,2 +0,2 @@ | ||
module.exports = function () { | ||
function sendBeacon() { | ||
let resolver; | ||
@@ -24,2 +24,5 @@ let rejecter; | ||
}; | ||
}; | ||
} | ||
export default sendBeacon; | ||
export { sendBeacon }; |
@@ -1,2 +0,2 @@ | ||
module.exports = function () { | ||
function xhr() { | ||
const xhr = new window.XMLHttpRequest(); | ||
@@ -25,2 +25,5 @@ | ||
}; | ||
}; | ||
} | ||
export default xhr; | ||
export { xhr }; |
@@ -1,5 +0,3 @@ | ||
/*global module, require */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
import utils from '../utils'; | ||
import Store from './store'; | ||
@@ -9,5 +7,2 @@ let userID; | ||
const utils = require('../utils'); | ||
const Store = require('./store'); | ||
/** | ||
@@ -70,7 +65,17 @@ * Init | ||
module.exports = { | ||
init: init, | ||
setUser: setUser, | ||
userID: function () { return userID; }, | ||
destroy: destroy | ||
function id() { | ||
return userID; | ||
} | ||
export default { | ||
init, | ||
setUser, | ||
userID: id, | ||
destroy | ||
}; | ||
export { | ||
init, | ||
setUser, | ||
id as userID, | ||
destroy | ||
}; |
@@ -1,11 +0,8 @@ | ||
/*global module, require */ | ||
'use strict'; // eslint-disable-line strict | ||
import Delegate from 'ftdomdelegate'; | ||
import Queue from '../core/queue'; | ||
import Core from '../core'; | ||
import utils from '../utils'; | ||
import settings from '../core/settings'; | ||
import getTrace from '../../libs/get-trace'; | ||
const Delegate = require('ftdomdelegate'); | ||
const Queue = require('../core/queue'); | ||
const Core = require('../core'); | ||
const utils = require('../utils'); | ||
const settings = require('../core/settings'); | ||
const getTrace = require('../../libs/get-trace'); | ||
let internalQueue; | ||
@@ -118,4 +115,8 @@ | ||
module.exports = { | ||
init: init | ||
export default { | ||
init | ||
}; | ||
export { | ||
init | ||
}; |
@@ -1,7 +0,5 @@ | ||
/*global module, require */ | ||
'use strict'; // eslint-disable-line strict | ||
const Core = require('../core'); | ||
const getTrace = require('../../libs/get-trace'); | ||
const utils = require('../utils'); | ||
import Core from '../core'; | ||
import getTrace from '../../libs/get-trace'; | ||
import utils from '../utils'; | ||
@@ -85,4 +83,4 @@ const TRACKING_ATTRIBUTES = [ | ||
module.exports = { | ||
init: init | ||
}; | ||
export default init; | ||
export { init }; | ||
@@ -1,9 +0,4 @@ | ||
/*global module, require */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
import Core from '../core'; | ||
import utils from '../utils'; | ||
const Core = require('../core'); | ||
const utils = require('../utils'); | ||
/** | ||
@@ -224,7 +219,9 @@ * Default properties for events. | ||
const init = function init() { | ||
utils.addEvent(window, 'oTracking.event', event); | ||
}; | ||
event.init = init; | ||
export default event; | ||
export { event }; | ||
module.exports = event; | ||
module.exports.init = function () { | ||
utils.addEvent(window, 'oTracking.event', event); | ||
}; |
@@ -1,10 +0,5 @@ | ||
/*global module, require */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
import Core from '../core'; | ||
import utils from '../utils'; | ||
import settings from '../core/settings'; | ||
const Core = require('../core'); | ||
const utils = require('../utils'); | ||
const settings = require('../core/settings'); | ||
settings.set('page_viewed', false); | ||
@@ -65,7 +60,7 @@ | ||
module.exports = page; | ||
module.exports.init = function () { | ||
const init = function init() { | ||
utils.addEvent(window, 'oTracking.page', listener); | ||
}; | ||
page.init = init; | ||
export default page; | ||
export { page }; |
@@ -1,6 +0,1 @@ | ||
/*global module, require, window */ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
/*eslint-enable*/ | ||
/** | ||
@@ -10,3 +5,3 @@ * Shared 'internal' scope. | ||
*/ | ||
const settings = require('./core/settings'); | ||
import settings from './core/settings'; | ||
@@ -16,3 +11,3 @@ /** | ||
*/ | ||
const cuid = require('../libs/browser-cuid'); | ||
import cuid from '../libs/browser-cuid'; | ||
@@ -220,2 +215,19 @@ /** | ||
/** | ||
* Whitelist props | ||
* @param {Object} props - An object whose props need to be whitelisted | ||
* @param {Array} list - A list for whitelisting | ||
* @return | ||
*/ | ||
function whitelistProps (props, list) { | ||
return list.reduce( | ||
(acc, propName) => Object.assign( | ||
{}, | ||
acc, | ||
props[propName] ? { [propName]: props[propName] } : undefined | ||
), | ||
{} | ||
); | ||
} | ||
/** | ||
* Trim strings | ||
@@ -246,40 +258,42 @@ * @param {String} str - The string to trim. | ||
/** | ||
* Whitelist props | ||
* @param {Object} props - An object whose props need to be whitelisted | ||
* @param {Array} list - A list for whitelisting | ||
* @return | ||
*/ | ||
function whitelistProps (props, list) { | ||
return list.reduce( | ||
(acc, propName) => Object.assign( | ||
{}, | ||
acc, | ||
props[propName] ? { [propName]: props[propName] } : undefined | ||
), | ||
{} | ||
); | ||
} | ||
/** | ||
* Utilities. | ||
* @alias utils | ||
*/ | ||
module.exports = { | ||
log: log, | ||
is: is, | ||
export default { | ||
log, | ||
is, | ||
isUndefined: is, | ||
merge: merge, | ||
encode: encode, | ||
decode: decode, | ||
merge, | ||
encode, | ||
decode, | ||
guid: cuid, | ||
addEvent: addEvent, | ||
broadcast: broadcast, | ||
onPage: onPage, | ||
triggerPage: triggerPage, | ||
getValueFromCookie: getValueFromCookie, | ||
getValueFromUrl: getValueFromUrl, | ||
getValueFromJsVariable: getValueFromJsVariable, | ||
sanitise: sanitise, | ||
assignIfUndefined: assignIfUndefined, | ||
whitelistProps: whitelistProps, | ||
addEvent, | ||
broadcast, | ||
onPage, | ||
triggerPage, | ||
getValueFromCookie, | ||
getValueFromUrl, | ||
getValueFromJsVariable, | ||
sanitise, | ||
assignIfUndefined, | ||
whitelistProps | ||
}; | ||
export { | ||
log, | ||
is, | ||
is as isUndefined, | ||
merge, | ||
encode, | ||
decode, | ||
cuid as guid, | ||
addEvent, | ||
broadcast, | ||
onPage, | ||
triggerPage, | ||
getValueFromCookie, | ||
getValueFromUrl, | ||
getValueFromJsVariable, | ||
sanitise, | ||
assignIfUndefined, | ||
whitelistProps | ||
}; |
@@ -1,2 +0,1 @@ | ||
/*eslint-disable*/ | ||
/** | ||
@@ -13,99 +12,89 @@ * cuid.js | ||
*/ | ||
let c = 0; | ||
const blockSize = 4; | ||
const base = 36; | ||
const discreteValues = Math.pow(base, blockSize); | ||
/*global window, navigator, document, require, process, module */ | ||
(function (app) { | ||
'use strict'; | ||
var namespace = 'cuid', | ||
c = 0, | ||
blockSize = 4, | ||
base = 36, | ||
discreteValues = Math.pow(base, blockSize), | ||
const pad = function pad(num, size) { | ||
const s = "000000000" + num; | ||
return s.substr(s.length-size); | ||
}; | ||
pad = function pad(num, size) { | ||
var s = "000000000" + num; | ||
return s.substr(s.length-size); | ||
}, | ||
const randomBlock = function randomBlock() { | ||
return pad((Math.random() * | ||
discreteValues << 0) | ||
.toString(base), blockSize); | ||
}; | ||
randomBlock = function randomBlock() { | ||
return pad((Math.random() * | ||
discreteValues << 0) | ||
.toString(base), blockSize); | ||
}, | ||
const safeCounter = () => { | ||
c = (c < discreteValues) ? c : 0; | ||
c++; // this is not subliminal | ||
return c - 1; | ||
}; | ||
safeCounter = function () { | ||
c = (c < discreteValues) ? c : 0; | ||
c++; // this is not subliminal | ||
return c - 1; | ||
}, | ||
const api = function cuid() { | ||
// Starting with a lowercase letter makes | ||
// it HTML element ID friendly. | ||
// hard-coded allows for sequential access | ||
const letter = 'c'; | ||
api = function cuid() { | ||
// Starting with a lowercase letter makes | ||
// it HTML element ID friendly. | ||
var letter = 'c', // hard-coded allows for sequential access | ||
// timestamp | ||
// warning: this exposes the exact date and time | ||
// that the uid was created. | ||
const timestamp = (new Date().getTime()).toString(base); | ||
// timestamp | ||
// warning: this exposes the exact date and time | ||
// that the uid was created. | ||
timestamp = (new Date().getTime()).toString(base), | ||
// Prevent same-machine collisions. | ||
let counter; | ||
// Prevent same-machine collisions. | ||
counter, | ||
// A few chars to generate distinct ids for different | ||
// clients (so different computers are far less | ||
// likely to generate the same id) | ||
const fingerprint = api.fingerprint(); | ||
// A few chars to generate distinct ids for different | ||
// clients (so different computers are far less | ||
// likely to generate the same id) | ||
fingerprint = api.fingerprint(), | ||
// Grab some more chars from Math.random() | ||
const random = randomBlock() + randomBlock(); | ||
// Grab some more chars from Math.random() | ||
random = randomBlock() + randomBlock(); | ||
counter = pad(safeCounter().toString(base), blockSize); | ||
counter = pad(safeCounter().toString(base), blockSize); | ||
return (letter + timestamp + counter + fingerprint + random); | ||
}; | ||
return (letter + timestamp + counter + fingerprint + random); | ||
}; | ||
api.slug = function slug() { | ||
const date = new Date().getTime().toString(36); | ||
let counter; | ||
api.slug = function slug() { | ||
var date = new Date().getTime().toString(36), | ||
counter, | ||
print = api.fingerprint().slice(0,1) + | ||
api.fingerprint().slice(-1), | ||
random = randomBlock().slice(-2); | ||
const print = api.fingerprint().slice(0,1) + | ||
api.fingerprint().slice(-1); | ||
counter = safeCounter().toString(36).slice(-4); | ||
const random = randomBlock().slice(-2); | ||
return date.slice(-2) + | ||
counter + print + random; | ||
}; | ||
counter = safeCounter().toString(36).slice(-4); | ||
api.globalCount = function globalCount() { | ||
// We want to cache the results of this | ||
var cache = (function calc() { | ||
var i, | ||
count = 0; | ||
return date.slice(-2) + | ||
counter + print + random; | ||
}; | ||
for (i in window) { | ||
count++; | ||
} | ||
api.globalCount = function globalCount() { | ||
// We want to cache the results of this | ||
const cache = (function calc() { | ||
let count = 0; | ||
return count; | ||
}()); | ||
for (let i in window) { // eslint-disable-line no-unused-vars, guard-for-in | ||
count++; | ||
} | ||
api.globalCount = function () { return cache; }; | ||
return cache; | ||
}; | ||
return count; | ||
}()); | ||
api.fingerprint = function browserPrint() { | ||
return pad((navigator.mimeTypes.length + | ||
navigator.userAgent.length).toString(36) + | ||
api.globalCount().toString(36), 4); | ||
}; | ||
api.globalCount = () => cache; | ||
return cache; | ||
}; | ||
// don't change anything from here down. | ||
if (typeof module !== 'undefined') { | ||
module.exports = api; | ||
} else { | ||
app[namespace] = api; | ||
} | ||
api.fingerprint = function browserPrint() { | ||
return pad((navigator.mimeTypes.length + | ||
navigator.userAgent.length).toString(36) + | ||
api.globalCount().toString(36), 4); | ||
}; | ||
}(this)); | ||
/*eslint-enable */ | ||
export default api; | ||
export { api }; |
// Trace the element and all of its parents, collecting properties as we go | ||
const utils = require('../javascript/utils'); | ||
import utils from '../javascript/utils'; | ||
@@ -5,0 +5,0 @@ const elementPropertiesToCollect = [ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
126006
3833
313
2
- Removedftdomdelegate@3.1.0(transitive)
Updatedftdomdelegate@v4.0.0-beta.1