-
AuthorPosts
-
October 13, 2017 at 12:51 pm #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
NeilOctober 14, 2017 at 9:16 am #864240Hey 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,
RikardOctober 16, 2017 at 9:59 am #864723Hi 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, 2 months ago by NeilJC.
October 16, 2017 at 12:24 pm #864778Hi,
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,
RikardOctober 16, 2017 at 12:31 pm #864781Hi 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
NeilOctober 17, 2017 at 4:33 am #865083Hi 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,
RikardOctober 17, 2017 at 2:31 pm #865295Hi 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
NeilOctober 18, 2017 at 8:39 am #865574Hi 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,
RikardOctober 18, 2017 at 9:03 pm #865908Thank you Rikard,
I really appreciate your help :)
I’ll give it a try.Regards
NeilOctober 19, 2017 at 12:40 am #866006Hi Neil,
Glad that Rikard helped you. Just let us know if you need more assistance :)
Best regards,
Nikko -
AuthorPosts
- You must be logged in to reply to this topic.