Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #863906

    Hi Support,

    I am trying to set up Google Analytics tracking for users that submit a Contact Form 7 enquiry. The simplest way to do this would be to point to a ‘Thank You’ page after form submission but CF7 say that this method is old and will be removed by the end of 2017.

    They suggest using javascript as below by inserting into the Enfold Header file. If we do this, I assume it will be overwritten by future updates, right?

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

    How can we set up the Analytics and avoid adding the above code to the header every time there is an Enfold Update please?

    Regards
    Neil

    #864240

    Hey Neil,

    If you use a child theme then your edits won’t be overwritten on updates: http://kriesi.at/documentation/enfold/portfolio-item/create-a-child-theme/

    Best regards,
    Rikard

    #864723

    Hi Rikard,

    I have installed the child theme. I now have to either add the following code into the header.php (and copy this file to the child theme folder) or preferably use the wp_head hook as per Contact Form 7 instructions. (https://contactform7.com/tracking-form-submissions-with-google-analytics/)
    Sorry, but I do not know what code I need to insert into the child themes functions.php file to enable this – can you help please?
    This is the code I need to insert
    <script>
    document.addEventListener( ‘wpcf7mailsent’, function( event ) {
    ga(‘send’, ‘event’, ‘Contact Form’, ‘submit’);
    }, false );
    </script>

    Thank you in advance
    Neil

    • This reply was modified 7 years, 1 month ago by NeilJC.
    #864778

    Hi,

    Great, glad you figured it out and thanks for letting us know. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

    #864781

    Hi Rikard,
    I am struggling to understand the wp_head action and the correct code to insert in order to enable the google analytics code above.
    Can you help please?
    Thanks
    Neil

    #865083

    Hi Neil,

    Anything added using wp_head will end up in the head section of your site, what exactly do you need to insert and where?

    Best regards,
    Rikard

    #865295

    Hi Rikard,
    Apologies for bothering you with this but to be honest, it seems a bit complicated for me :)
    I need to insert the following code to Enfold to be able to track the contact form 7 events in google analytics. I am reading CF7’s instructions and they tell me to use the wp-head hook. I do not know how to do this – that is the problem.
    CF7 Instructions – (https://contactform7.com/tracking-form-submissions-with-google-analytics/)

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

    I have created a child theme so I assume I need to add the code to the functions.php file – right?

    Thank you
    Neil

    #865574

    Hi Neil,

    No problem and thanks for the code, though I think that should have script tags around it? Please try this in your child themes functions.php:

    function neil_add_cf7_tracking(){ ?>
    <script>
    document.addEventListener( ‘wpcf7mailsent’, function( event ) {
    ga( ‘send’, ‘event’, ‘Contact Form’, ‘submit’ );
    }, false );
    </script>
    <?php }
    add_action('wp_head', 'neil_add_cf7_tracking');

    Best regards,
    Rikard

    #865908

    Thank you Rikard,

    I really appreciate your help :)
    I’ll give it a try.

    Regards
    Neil

    #866006

    Hi Neil,

    Glad that Rikard helped you. Just let us know if you need more assistance :)

    Best regards,
    Nikko

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.