Contact Form 7 Analytics Tracking

A short code snippet showing you how to enable google goal tracking analytics on your wordpress contact form 7 plugin.

GA Property

First you must initiate the Analytics Property

<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
 
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

Then you must insert this code in the footer to activate on form submit.

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
    ga('send', 'event', 'Contact Form', 'submit');
}, false );
</script>

 

GTAG Property

First you must initiate the Analytics Property

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-48421145-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXXX');
</script>


Then you must insert this code in the footer to activate on form submit.

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
    gtag('event', 'call', {'event_category': 'btn', 'event_action' : 'press', 'event_label': 'call'});
}, false );
</script>