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    
Size: Mime:
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var utils = require('../../helpers/utils.js');
var constants = require('../../constants.js');

/**
 * Formats a trackingIntent object to be compatible with Google Analytics tracker API
 *
 * @param {TrackingDefinitionData} trackingData - An object produced by getTrackingDefinition function
 * @return {Object}
 * @see https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
 * @see https://support.google.com/analytics/answer/1033068#Anatomy
 */

var mapTrackingDataToGoogleAnalytics = function mapTrackingDataToGoogleAnalytics(_ref) {
  var track = _ref.track;

  if (!track) {
    throw new TypeError('Please check a valid tracking intent was provided');
  }

  var eventAction = track.event,
      _track$type = track.type,
      eventCategory = _track$type === void 0 ? constants.EVENT_TYPE.userInteraction : _track$type,
      _track$properties = track.properties,
      _track$properties$cat = _track$properties.category,
      eventPage = _track$properties$cat === void 0 ? '' : _track$properties$cat,
      _track$properties$lab = _track$properties.label,
      eventLabel = _track$properties$lab === void 0 ? '' : _track$properties$lab,
      _track$properties$nam = _track$properties.name,
      eventName = _track$properties$nam === void 0 ? '' : _track$properties$nam,
      _track$properties$val = _track$properties.value,
      eventValue = _track$properties$val === void 0 ? '' : _track$properties$val; // Coerce to number if possible

  if (eventValue !== '' && !utils.isNumeric(eventValue)) {
    throw new TypeError('Please check a valid tracking intent was provided. Property "value" must be a number');
  }

  var destinationData = {
    eventAction: eventAction,
    eventCategory: eventCategory,
    eventLabel: eventLabel,
    eventName: eventName,
    eventValue: parseFloat(eventValue) || '',
    eventPage: eventPage
  };
  return destinationData;
};

exports.mapTrackingDataToGoogleAnalytics = mapTrackingDataToGoogleAnalytics;
//# sourceMappingURL=mapper.js.map