Repository URL to install this package:
|
Version:
0.6.0 ▾
|
/**
* This functions returns an objects with html data-attributes,
* that can be spread over any clickable JSX element for tracking
* @param {object} valuesToTrack An object that holdes value that should be tracked
* @return {object} An object containing data attributes
*
*/
const setTrackingAttributes = valuesToTrack => {
const { ga, amplitude } = valuesToTrack;
const obj = {
'data-tracking': 'true',
// ga
...(ga && {
'data-ga-page': ga.eventPage,
'data-ga-category': ga.eventCategory,
'data-ga-action': ga.eventAction,
'data-ga-label': ga.eventLabel,
}),
// amplitude
...(amplitude && {
'data-amplitude-type': amplitude.eventType,
'data-amplitude-name': amplitude.eventName,
'data-amplitude-properties': JSON.stringify(amplitude.eventProperties),
}),
};
return obj;
};
export default setTrackingAttributes;