• Hello,

    I try to use Tracking Form Submissions with Google Analytics. When I copy this code in functions.php, I have a few error :

    document.addEventListener( ‘wpcf7mailsent’, function( event ) {
    ga( ‘send’, ‘event’, ‘Contact Form’, ‘submit’ );
    }, false );

    Can you give me exactly the code to copy in functions.php

    Thanks

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    you cannot just past JavaScript snippet directly into PHP code…

    You want something like this:

    add_action('wp_footer', function() {
    ?><script>
    document.addEventListener('wpcf7mailsent', function(event) {
        ga('send', 'event', 'Contact Form', 'submit');
    }, false);
    </script><?php
    }, 30, 0);
    

    This code prints the snippet wrapped within <script></script> tag in your site’s footer (ie. before </body>).

    Thread Starter Baptiste-C

    (@baptiste-c)

    Ok thanks. I test this.

    Just for be sure, in this page https://contactform7.com/tracking-form-submissions-with-google-analytics/ at the end of step, it is write :
    “If you have set up everything correctly, Google Analytics will track successful form submissions through contact forms as an event with “Contact Form” as the event category, and “submit” as the event action.”

    My question: in Google Analytics, I have need to create an event ? or the event is create automatically ?

    Thanks

    My question: in Google Analytics, I have need to create an event ? or the event is create automatically ?

    I believe the events in GA are created automatically based on what your tracking script sends. But you’re getting ouf of the scope of this support forum ??

    Thread Starter Baptiste-C

    (@baptiste-c)

    Ok thanks ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Tracking Form Submissions with Google Analytics’ is closed to new replies.