Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Phone call tracking without jQuery
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if (typeof gtag !== 'undefined') {
gtag('event', 'Submit', {
'event_category': 'Contact Form',
'event_label': 'Main Contact Form',
'event_callback': function() {
console.log("contact form tracking sent successfully");
}
});
} // end if variable defined
}, false );
document.addEventListener('click', function (event) {
// If the clicked element doesn't have the right selector, bail
if (event.target.matches(".phone-num")) {
if (typeof gtag !== 'undefined') {
gtag('event', 'Click', {
'event_category': 'Contact',
'event_label': 'Phone',
'event_callback': function() {
console.log("phone call information sent successfully");
}
});
} // end if variable defined
} // end if phone number was clicked
if (event.target.matches(".fax-num")) {
if (typeof gtag !== 'undefined') {
gtag('event', 'Click', {
'event_category': 'Contact',
'event_label': 'Fax',
'event_callback': function() {
console.log("fax clickinformation sent successfully");
}
});
} // end if variable defined
} // end if fax number was clicked
}, false);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.