Repository URL to install this package:
|
Version:
3.2.1 ▾
|
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
var constants = require('../../constants.js');
var _excluded = ["category", "description"],
_excluded2 = ["event", "type", "properties"];
/**
* Formats a trackingIntent object to be compatible with Amplitude tracking APIs
*
* It assumes there is only one preferred tracking command per tracking intent. If multiple are provided,
* the destination tracking data is formatted observing the following precedence: `track` then `identify`
* (`page` API is not used in Amplitude)
*
* We remove `label`, `name` and `value` which are used for Google Analytics but shouldn't be sent to Amplitude
* One alternative would be to stop forwarding remaining keys via `restTrack` but we need it for custom keys, e.g. FAQ
*
* @param {TrackingDefinitionData} trackingData - An object produced by getTrackingDefinition function
* @return {Object}
*/
var mapTrackingDataToAmplitude = function mapTrackingDataToAmplitude(_ref) {
var track = _ref.track,
identify = _ref.identify;
if (track) {
var eventName = track.event,
_track$type = track.type,
eventType = _track$type === void 0 ? constants.EVENT_TYPE.userInteraction : _track$type,
_track$properties = track.properties,
EventCategory = _track$properties.category,
EventDescription = _track$properties.description,
eventProperties = _rollupPluginBabelHelpers.objectWithoutProperties(_track$properties, _excluded),
restTrack = _rollupPluginBabelHelpers.objectWithoutProperties(track, _excluded2);
var destinationData = {
eventName: eventName,
eventProperties: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({
EventCategory: EventCategory,
EventDescription: EventDescription,
'Event Type': eventType
}, eventProperties), restTrack)
};
return destinationData;
}
if (identify) {
return identify;
}
throw new TypeError('Please check a valid tracking intent was provided');
};
exports.mapTrackingDataToAmplitude = mapTrackingDataToAmplitude;
//# sourceMappingURL=mapper.js.map