Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/tracking / dist / esm / src / core / api.js
Size: Mime:
import * as init$1 from './init.js';
import { handleTrack, handleIdentify } from './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(options) {
    if (!this._initialized) {
      // eslint-disable-next-line global-require
      var _require = init$1,
          initTracking = _require.initTracking;

      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: function track(_ref) {
    var trackingIntent = _ref.trackingIntent,
        trackingEl = _ref.trackingEl,
        event = _ref.event;
    return 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 handleIdentify({
      trackingIntent: trackingIntent,
      trackingEl: trackingEl
    }, this.options);
  }
};

export default API;
//# sourceMappingURL=api.js.map