Repository URL to install this package:
|
Version:
1.4.1 ▾
|
'use strict';
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var init = require('./init.js');
var utils = require('../helpers/utils.js');
var handlers = require('./handlers.js');
var API = {
/**
* Factory method for initializing @doodle/tracking library, returning an instance of an API
*
* @public
* @param {TrackingApiOptions} options - The configuration options for API client
* @return {API} - An initialized instance of API class
*/
init: function init$1(options) {
if (this._initialized) {
return this;
}
var services = options.services,
restOptions = _rollupPluginBabelHelpers.objectWithoutProperties(options, ["services"]);
this.options = _rollupPluginBabelHelpers.objectSpread2({
services: utils.sampleServices(services, Math.random())
}, restOptions); // eslint-disable-next-line global-require
var _require = init,
initTracking = _require.initTracking;
initTracking(restOptions);
this._initialized = true;
return this;
},
/**
* Client method for tracking
*
* It may be called either with a trackingIntent or with a trackingEl, which carries tracking data attributes
* In case both are passed: trackingIntent is preferred
*
* @public
* @async
* @param {Object} payload - Either a trackingIntent or a trackingEl must be part of the payload
* @param {TrackingIntent} [payload.trackingIntent] - The tracking intent passed to the API client
* @param {HTMLElement} [payload.trackingEl] - An HTML element with tracking data attributes
* @param {MouseEvent} [payload.event] - A click event to be cancelled in case of same tab links
* @return {Promise<undefined>}
*/
track: function track(_ref) {
var trackingIntent = _ref.trackingIntent,
trackingEl = _ref.trackingEl,
event = _ref.event;
return handlers.handleTrack({
trackingIntent: trackingIntent,
trackingEl: trackingEl,
event: event
}, this.options);
},
/**
* Client method for user identification
*
* @public
* @async
* @param {Object} [payload] - Either a trackingIntent or a trackingEl must be part of the payload
* @param {TrackingIntent} [payload.trackingIntent] - The tracking intent passed to the API client
* @param {HTMLElement} [payload.trackingEl] - An HTML element with tracking data attributes
* @return {Promise<undefined>}
*/
identify: function identify(_ref2) {
var trackingIntent = _ref2.trackingIntent,
trackingEl = _ref2.trackingEl;
return handlers.handleIdentify({
trackingIntent: trackingIntent,
trackingEl: trackingEl
}, this.options);
}
};
module.exports = API;
//# sourceMappingURL=api.js.map