• Resolved nturne

    (@nturne)


    Hi

    I see that using the ‘on_sent_ok’ hook is to be abolished and that the recommendation for tracking form submissions in Google Analytics is now to add the event tracking code to the page head (https://contactform7.com/tracking-form-submissions-with-google-analytics/). However, the suggestion does not allow for tracking different forms as different events. For example, if I have a standard contact form and a quote request form on the same page which I would like to track separately.

    Please could you suggest how this could be worked?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter nturne

    (@nturne)

    I think I’ve answered my own question…

    I have added the following to my child theme functions.php file and it appears to work:

    function hook_google_analytics() {
    	echo "<script>\r\n";
    	echo "document.addEventListener('wpcf7mailsent', function(event) {\r\n";
    	echo "	if ( '5' == event.detail.contactFormId ) {\r\n";
    	echo "		ga('send', 'event', 'Contact Form', 'Submit');\r\n";
    	echo "	} else if ( '179' == event.detail.contactFormId ) {\r\n";
    	echo "		ga('send', 'event', 'Quote Reservation', 'Submit');\r\n";
    	echo "	}\r\n";
    	echo "}, false );\r\n";
    	echo "</script>\r\n";
    }
    add_action('wp_head', 'hook_google_analytics');

    In this case the standard contact form has an ID of ‘5’ and the quote form has an ID of ‘179’ (taken from the shortcode).

    Any comments would be appreciated.

    Hello nturne! I have the same question, did your solution work? Does it appear on your analytics results?

    Thread Starter nturne

    (@nturne)

    Hello danielgc. I believe it works OK, but it hasn’t been subjected to rigorous testing yet – the only website that I needed to install it on is a very small (and low traffic) website, but I haven’t had an issue so far. If you try it yourself and later have any feedback, maybe you could post it?

    Thx nturne, I ended using a different technique: https://ww.wp.xz.cn/support/topic/event-detail-contactformname-or-something-similar/

    best regards!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Google Analytics Tracking Multiple Forms’ is closed to new replies.