Repository URL to install this package:
|
Version:
1.0.1 ▾
|
import { EVENT_TYPE } from '../../constants.js';
import { getUtmParams } from '../../helpers/url.js';
/**
* Formats a trackingIntent object to be compatible with Doodle Data Layer track API
*
* @param {TrackingDefinitionData} trackingData - An object produced by getTrackingDefinition function
* @return {Object}
*/
const mapTrackingDataToDoodleDataLayer = ({
track,
identify
}) => {
if (track) {
const {
userId,
...restTrack
} = track;
return {
timestamp: new Date().toISOString(),
user_id: userId,
type: EVENT_TYPE.userInteraction,
...getUtmParams(),
...restTrack
};
}
if (identify) {
const {
userId,
properties
} = identify;
return {
timestamp: new Date().toISOString(),
user_id: userId,
properties
};
}
throw new TypeError('Please check a valid tracking intent was provided');
};
export { mapTrackingDataToDoodleDataLayer };
//# sourceMappingURL=mapper.js.map