Skip to content

Instantly share code, notes, and snippets.

@EastSideCode
Created February 20, 2018 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EastSideCode/84db44473af8818064e1cb99fe8065e0 to your computer and use it in GitHub Desktop.
Save EastSideCode/84db44473af8818064e1cb99fe8065e0 to your computer and use it in GitHub Desktop.
Track phone clicks and Contact form 7 submissions
// add tracking for phone call clicks
function google_phone_clicks_and_contact_form() { ?>
<!-- phone call tracking for analytics -->
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("a[href^='tel:']").click(function(event){
if (typeof ga !== 'undefined') {
ga('send', 'event', 'Contact', 'Phone', 'Click');
}
});
});
<?php if (is_page(558)) : // if on the contact page. replace page id with id of contact page on website ?>
document.addEventListener( 'wpcf7mailsent', function( event ) {
ga('send', 'event', 'Contact Form', 'submit');
}, false );
<?php endif; ?>
</script>
<?php
}
// include in footer
add_action('wp_footer', 'google_phone_clicks_and_contact_form');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment