Skip to content

Instantly share code, notes, and snippets.

@ubershmekel
Last active March 15, 2020 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ubershmekel/6d465a80f5e450deda870adb560473c5 to your computer and use it in GitHub Desktop.
Save ubershmekel/6d465a80f5e450deda870adb560473c5 to your computer and use it in GitHub Desktop.
Trigger a google analytics (new or old) and a pixel event
function eventAll(eventName) {
// https://support.google.com/analytics/answer/1033068?hl=en
// non_interaction/nonInteraction to avoid raising bounce rate
// when there's an event that fires every page load.
if (window.gtag) {
gtag('event', eventName, {
non_interaction: true,
});
} else if (window.ga) {
ga('send', {
hitType: 'event',
eventCategory: 'general', // `general` is used by the new google `gtag`
eventAction: eventName,
//eventLabel: '',
nonInteraction: true,
});
}
if (window.fbq) {
fbq('trackCustom', eventName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment