Repository URL to install this package:
|
Version:
1.1.0-rc.0 ▾
|
'use strict';
var init = require('./init.js');
var utils = require('../helpers/utils.js');
var handlers = require('./handlers.js');
const API = {
/**
* Factory method for initializing @doodle/tracking library, returning an instance of an API
*
* @public
* @param {Object} options This contains fields for either imperative or declarative (data attributes based) tracking
* @param {string} options.amplitudeApiKey The Amplitude key, usually retrieved from an env var
* @param {boolean} [options.autoTracking] Controls whether the automated handling of tracking clicks occur
* @param {TrackingApiServices} [options.services] An HTML element with tracking data attributes
* @return {API} An initialized instance of API class
*/
init(options) {
if (this._initialized) {
return this;
}
const {
services,
...restOptions
} = options;
this.options = {
services: utils.sampleServices(services, Math.random()),
...restOptions
}; // eslint-disable-next-line global-require
const {
initTracking
} = init;
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 This contains fields for either imperative or declarative (data attributes based) tracking
* @param {TrackingIntent} [payload.trackingIntent] A tracking intent
* @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<void>}
*/
track({
trackingIntent,
trackingEl,
event
} = {}) {
return handlers.handleTrack({
trackingIntent,
trackingEl,
event
}, this.options);
},
/**
* Client method user identification
*
* @public
* @async
* @param {Object} [payload]
* @param {TrackingIntent} [payload.trackingIntent] An object with same interface accepted by getTrackingDataAttrs, useful for
* imperative tracking
* @param {HTMLElement} [payload.trackingEl] An HTML element to inspect
* @return {Promise<void>}
*/
identify({
trackingIntent,
trackingEl
} = {}) {
return handlers.handleIdentify({
trackingIntent,
trackingEl
}, this.options);
}
};
module.exports = API;
//# sourceMappingURL=api.js.map