Last active
March 15, 2020 22:21
-
-
Save javimata/c0cd4d9fae416636f9e6f6e7d2b35d40 to your computer and use it in GitHub Desktop.
Script para agregar eventos de Google Analytics a los enlaces de teléfono y email de manera automática
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
(function ($) { | |
$(document).ready(function () { | |
/** | |
* Asigna una clase en base al tipo de enlace | |
*/ | |
$('a[href^=tel]').addClass("link-phone"); | |
$('a[href^=mailto]').addClass("link-email").attr("target", "_blank"); | |
$('a[href*="wa.me"]').addClass("link-whatsapp").attr("target", "_blank"); | |
$('a[href*="m.me"]').addClass("link-messenger").attr("target", "_blank"); | |
$('a[href*="maps.google"]').addClass("link-map").attr("target", "_blank"); | |
// Manejo de Eventos | |
$('.link-phone').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'}); | |
}; | |
}); | |
$('.link-email').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'}); | |
}; | |
}); | |
$('.link-whatsapp').click(function () { | |
if (typeof gtag == 'function') { | |
gtag('event', 'click', { 'event_category': 'telefono', 'event_label': 'whatsapp' }); | |
} | |
if (typeof ga == 'function') { | |
ga('send', 'event', 'telefono', 'click', 'whatsapp'); | |
}; | |
if (typeof fbq == 'function') { | |
fbq('track','Contact', {content_name:'whatsapp'}); | |
}; | |
}); | |
$('.link-messenger').click(function () { | |
if (typeof gtag == 'function') { | |
gtag('event', 'click', { 'event_category': 'telefono', 'event_label': 'messenger' }); | |
} | |
if (typeof ga == 'function') { | |
ga('send', 'event', 'telefono', 'click', 'messenger'); | |
}; | |
if (typeof fbq == 'function') { | |
fbq('track','Contact', {content_name:'messenger'}); | |
}; | |
}); | |
$('.link-map').click(function () { | |
if (typeof gtag == 'function') { | |
gtag('event', 'click', { 'event_category': 'site', 'event_label': 'map' }); | |
} | |
if (typeof ga == 'function') { | |
ga('send', 'event', 'site', 'click', 'map'); | |
}; | |
if (typeof fbq == 'function') { | |
fbq('track','Contact', {content_name:'map'}); | |
}; | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment