Script para agregar eventos de Google Analytics a los enlaces de teléfono y email de manera automática
(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");
// 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');
};
});
$('.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');
};
});
});
})(jQuery);