Skip to content

Instantly share code, notes, and snippets.

@jonarnaldo
Created October 21, 2020 19:16
Show Gist options
  • Select an option

  • Save jonarnaldo/19485040d4135f37ee6bd5939ea3754e to your computer and use it in GitHub Desktop.

Select an option

Save jonarnaldo/19485040d4135f37ee6bd5939ea3754e to your computer and use it in GitHub Desktop.
function isObject(value) {
const type = typeof value;
return value != null && type === 'object';
}
function trackTealium(category, action, label, value, nonInteraction = false) {
let eventData;
if (isObject(category)) {
eventData = category;
} else {
eventData = {
eventCategory: category,
eventAction: action,
eventLabel: label,
eventValue: (Number.isInteger(value) && value),
nonInteraction,
};
}
eventData = Object.keys(eventData).reduce((result, key) => {
const val = eventData[key];
if (val) {
result[key] = val;
}
return result;
}, {});
if (window.utag && window.analytics) {
window.analytics.ready(() => {
window.utag.link({
/* eslint-disable babel/camelcase */
event_action: eventData.eventAction || 'Action',
event_category: eventData.eventCategory || 'Category',
event_label: eventData.eventLabel || 'Label',
event_non_interaction: 'false',
event_value: eventData.eventValue || 'Value',
project: 'Burst',
tealium_event: 'event',
user_token: window.analytics.user().traits().uniqToken || '',
/* eslint-enable babel/camelcase */
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment