Created
July 25, 2019 21:44
-
-
Save javimata/0f18543f70549b13e5933f36e7f7e45c to your computer and use it in GitHub Desktop.
Add events with JS pure
This file contains 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
/** | |
* Activacion e incrustación de clases para eventos | |
*/ | |
document.querySelectorAll('a[href^="tel"]').forEach( element => { | |
element.classList.add("link-phone"); | |
element.addEventListener('click', function() { | |
if (typeof gtag == 'function') { | |
gtag('event', 'click', { 'event_category': 'telefono', 'event_label': 'llamada' }); | |
}; | |
if (typeof ga == 'function') { | |
ga('send', 'event', 'telefono', 'click', 'llamada'); | |
}; | |
if (typeof fbq == 'function') { | |
fbq('track', 'Contact', { content_name: 'telefono' }); | |
}; | |
}) | |
}); | |
document.querySelectorAll('a[href^="mailto"]').forEach(element => { | |
element.classList.add("link-email"); | |
element.setAttribute("target", "_blank"); | |
element.addEventListener('click', function () { | |
if (typeof gtag == 'function') { | |
gtag('event', 'click', { 'event_category': 'email', 'event_label': 'envio' }); | |
}; | |
if (typeof ga == 'function') { | |
ga('send', 'event', 'email', 'click', 'envio'); | |
}; | |
if (typeof fbq == 'function') { | |
fbq('track', 'Contact', { content_name: 'email' }); | |
}; | |
}); | |
}); | |
document.querySelectorAll('a[href*="wa.me"]').forEach(element => { | |
element.classList.add("link-whatsapp"); | |
element.setAttribute("target", "_blank"); | |
element.addEventListener('click', function () { | |
if (typeof gtag == 'function') { | |
gtag('event', 'click', { 'event_category': 'whatsapp', 'event_label': 'envio' }); | |
}; | |
if (typeof ga == 'function') { | |
ga('send', 'event', 'whatsapp', 'click', 'envio'); | |
}; | |
if (typeof fbq == 'function') { | |
fbq('track', 'Contact', { content_name: 'whatsapp' }); | |
}; | |
}); | |
}); | |
document.querySelectorAll('a[href*="m.me"]').forEach(element => { | |
element.classList.add("link-messenger"); | |
element.setAttribute("target", "_blank"); | |
element.addEventListener('click', function () { | |
if (typeof gtag == 'function') { | |
gtag('event', 'click', { 'event_category': 'messenger', 'event_label': 'envio' }); | |
}; | |
if (typeof ga == 'function') { | |
ga('send', 'event', 'messenger', 'click', 'envio'); | |
}; | |
if (typeof fbq == 'function') { | |
fbq('track', 'Contact', { content_name: 'messenger' }); | |
}; | |
}); | |
}); | |
document.querySelectorAll('a[href*="maps.google"]').forEach(element => { | |
element.classList.add("link-map"); | |
element.setAttribute("target", "_blank"); | |
element.addEventListener('click', function () { | |
if (typeof gtag == 'function') { | |
gtag('event', 'click', { 'event_category': 'maps', 'event_label': 'envio' }); | |
}; | |
if (typeof ga == 'function') { | |
ga('send', 'event', 'maps', 'click', 'envio'); | |
}; | |
if (typeof fbq == 'function') { | |
fbq('track', 'Contact', { content_name: 'maps' }); | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remote file use, don't update