Repository URL to install this package:
|
Version:
3.2.1 ▾
|
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import { EVENT_TYPE } from '../../constants.js';
import { getUtmParams } from '../../helpers/url.js';
var _excluded = ["userId"],
_excluded2 = ["path", "referrer", "title", "url"];
/**
* Formats a trackingIntent object to be compatible with Doodle Data Layer API
*
* @see https://ambassador-stg.doodle-test.com/data-layer/docs
* @param {TrackingDefinitionData} trackingData - An object produced by getTrackingDefinition function
* @return {Object}
*/
var mapTrackingDataToDoodleDataLayer = function mapTrackingDataToDoodleDataLayer(_ref) {
var track = _ref.track,
identify = _ref.identify,
page = _ref.page;
if (track) {
var userId = track.userId,
restTrack = _objectWithoutProperties(track, _excluded);
return _objectSpread2(_objectSpread2({
timestamp: new Date().toISOString(),
user_id: userId,
type: EVENT_TYPE.userInteraction
}, getUtmParams()), restTrack);
}
if (identify) {
var _userId = identify.userId,
properties = identify.properties;
return {
timestamp: new Date().toISOString(),
user_id: _userId,
properties: properties
};
}
if (page) {
var name = page.name,
_page$properties = page.properties,
path = _page$properties.path,
referrer = _page$properties.referrer,
title = _page$properties.title,
url = _page$properties.url,
_properties = _objectWithoutProperties(_page$properties, _excluded2);
return {
timestamp: new Date().toISOString(),
name: name,
path: path,
referrer: referrer,
title: title,
url: url,
properties: _properties
};
}
throw new TypeError('Please check a valid tracking intent was provided');
};
export { mapTrackingDataToDoodleDataLayer };
//# sourceMappingURL=mapper.js.map