Created
October 21, 2020 19:16
-
-
Save jonarnaldo/19485040d4135f37ee6bd5939ea3754e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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