Created
February 20, 2018 18:55
-
-
Save EastSideCode/84db44473af8818064e1cb99fe8065e0 to your computer and use it in GitHub Desktop.
Track phone clicks and Contact form 7 submissions
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 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