Repository URL to install this package:
|
Version:
1.1.0 ▾
|
'use strict';
var init = require('./init.js');
var handlers = require('./handlers.js');
const 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(options) {
if (!this._initialized) {
// eslint-disable-next-line global-require
const {
initTracking
} = init;
initTracking(options);
this._initialized = true;
}
this.options = options;
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({
trackingIntent,
trackingEl,
event
}) {
return handlers.handleTrack({
trackingIntent,
trackingEl,
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({
trackingIntent,
trackingEl
}) {
return handlers.handleIdentify({
trackingIntent,
trackingEl
}, this.options);
}
};
module.exports = API;
//# sourceMappingURL=api.js.map