Last active
February 25, 2018 08:42
-
-
Save EastSideCode/e28994da5dedf56b75fcd7515614ec52 to your computer and use it in GitHub Desktop.
Phone and Email Link Tracking with gtag
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
// add tracking for phone call and email link clicks | |
function google_phone_email_clicks() { ?> | |
<!-- phone call tracking for analytics --> | |
<script type="text/javascript"> | |
jQuery(document).ready(function() { | |
jQuery("a[href^='tel:']").click(function(event) { | |
if (typeof gtag !== 'undefined') { | |
gtag('event', 'Click', { | |
'event_category': 'Contact', | |
'event_label': 'Phone', | |
'event_callback': function() { | |
console.log("phone tracking sent successfully"); | |
} | |
}); | |
} // end if variable defined | |
}); // end click function | |
jQuery("a[href^='mailto']").click(function(event) { | |
if (typeof gtag !== 'undefined') { | |
gtag('event', 'Click', { | |
'event_category': 'Contact', | |
'event_label': 'Email', | |
'event_callback': function() { | |
console.log("email tracking sent successfully"); | |
} | |
}); | |
} // end if variable defined | |
}); // end click function | |
jQuery(".zoc-doc-link a").click(function(event) { | |
if (typeof gtag !== 'undefined') { | |
gtag('event', 'Click', { | |
'event_category': 'Contact', | |
'event_label': 'Zocdoc Link', | |
'event_callback': function() { | |
console.log("Zocdoc link tracking sent successfully"); | |
} | |
}); | |
} // end if variable defined | |
}); // end click function | |
jQuery(".dentist-design-link").click(function(event) { | |
if (typeof gtag !== 'undefined') { | |
gtag('event', 'Click', { | |
'event_category': 'Contact', | |
'event_label': 'Dentist Design', | |
'event_callback': function() { | |
console.log("Dentist Design link tracking sent successfully"); | |
} | |
}); | |
} // end if variable defined | |
}); // end click function | |
<?php if (is_page(172)) : ?> | |
document.addEventListener( 'wpcf7mailsent', function( event ) { | |
if (typeof gtag !== 'undefined') { | |
gtag('event', 'Submit', { | |
'event_category': 'Contact Form', | |
'event_callback': function() { | |
console.log("contact form tracking sent successfully"); | |
} | |
}); | |
} // end if variable defined | |
}, false ); | |
<?php endif; ?> | |
}); // end document ready | |
</script> | |
<?php | |
} | |
// include in footer | |
add_action('wp_footer', 'google_phone_email_clicks', 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment