Repository URL to install this package:
|
Version:
0.6.0 ▾
|
/**
* Helper function to get the tracking attribute values from a DOM element
* and returns them mapped to an object
*
* @param {Object} element - any DOM element
* @return {Object}
*/
const getTrackingAttributes = element => ({
href: element.getAttribute('href'),
isSameTabLink: element.getAttribute('href') && element.getAttribute('target') !== '_blank',
valuesToTrack: {
ga: {
eventPage: element.getAttribute('data-ga-page') || '',
eventAction: element.getAttribute('data-ga-action') || '',
eventCategory: element.getAttribute('data-ga-category') || '',
eventLabel: element.getAttribute('data-ga-label') || '',
},
amplitude: {
eventType: element.getAttribute('data-amplitude-type') || '',
eventName: element.getAttribute('data-amplitude-name') || '',
eventProperties: element.getAttribute('data-amplitude-properties')
? JSON.parse(element.getAttribute('data-amplitude-properties'))
: '',
},
},
});
export default getTrackingAttributes;