Created
January 16, 2019 14:34
-
-
Save EastSideCode/2e87893dda72a0e6d6136b460d997488 to your computer and use it in GitHub Desktop.
Phone call tracking without jQuery
This file contains hidden or 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
<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