Skip to content

Instantly share code, notes, and snippets.

@EastSideCode
Created January 16, 2019 14:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EastSideCode/2e87893dda72a0e6d6136b460d997488 to your computer and use it in GitHub Desktop.
Save EastSideCode/2e87893dda72a0e6d6136b460d997488 to your computer and use it in GitHub Desktop.
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