Tagged: Analytics, CONTACT FORM, ReCAPTCHA
-
AuthorPosts
-
September 30, 2021 at 5:14 pm #1323058
Hey guys,
My developer and I noticed a bug related to the contact form and tracking form submissions when Google ReCaptcha (v2 – haven’t tested v3) is enabled.
We have tried it on multiple sites and noticed the same issue. To try and explain it:
When you want to track contact form submissions, we add some code from your documentation:
add_filter('avf_contact_form_submit_button_attr','avia_add_submit_attributes_to_cf', 10, 3); function avia_add_submit_attributes_to_cf($att, $formID, $form_params){ $att = "onclick=\"gtag('event', 'Submit',{ 'event_category': 'ContactForms', 'event_label': 'contactPage' });\""; return $att; }
This successfully tracks form submissions on both GA3 and GA4 setups.
However, as soon as you enabled Google ReCaptcha, it adds the code into the page twice, so duplicate submissions are recorded for every for submission.
This is what gets added to the page:
<input type="button" value="Submit" class="button av-verify-recaptcha-0 av-recaptcha-submit avia_button_inactive" onclick="gtag('event', 'Submit',{ 'event_category': 'ContactForms', 'event_label': 'contactPage' });" data-sending-label="Sending" title="Please validate that you are a human first"> <input type="submit" value="Submit" class="button avia_button_inactive av-recaptcha-submit-real" onclick="gtag('event', 'Submit',{ 'event_category': 'ContactForms', 'event_label': 'contactPage' });" data-sending-label="Sending" style="display: none;">
If you turn off ReCaptcha and use the Enfold number captcha, the second set of code gets removed and so the tracking works correctly.
Can you please take a look?
Thanks guys.
Tim
September 30, 2021 at 11:31 pm #1323079examples below
October 1, 2021 at 1:06 pm #1323144Hi,
Thanks for reporting this.
Can you please try to update enfold\framework\js\conditional_load\avia_google_recaptcha_api.js
with the content of
I added the following around line 188:
// added 4.8.6.4 https://kriesi.at/support/topic/google-analytics-on-click-bug/ var analytics_ckeck = new_submit.prop( 'onclick' ); if( 'undefined' != typeof analytics_ckeck ) { analytics_ckeck = analytics_ckeck.toLowerCase(); if( analytics_ckeck.indexOf( 'gtag(' ) >= 0 ) { new_submit.prop( 'onclick', null ); } }
Important is, that “gtag(” is used (and not e.g. “gtag (“.
Best regards,
GünterOctober 2, 2021 at 8:04 pm #1323292Hey Gunter,
I tried this on a dev site and unfortunately it doesn’t seem to be working, it throws some errors, please see below.
Thanks
Tim
October 4, 2021 at 7:27 am #1323383Hi,
Thank you for the update.
Try to replace the snippet with the following code. We just replaced the prop function with attr.
// added 4.8.6.4 https://kriesi.at/support/topic/google-analytics-on-click-bug/ var analytics_ckeck = new_submit.attr( 'onclick' ); if( 'undefined' != typeof analytics_ckeck ) { analytics_ckeck = analytics_ckeck.toLowerCase(); if( analytics_ckeck.indexOf( 'gtag(' ) >= 0 ) { new_submit.attr( 'onclick', null ); } }
Please toggle or temporarily disable the Enfold > Performance > File Compression settings after doing the modification.
Best regards,
IsmaelOctober 4, 2021 at 11:47 am #1323428October 4, 2021 at 3:43 pm #1323481Hi @ismael and @Gunter,
Thank you for the update, I tested it and can confirm it’s fixed.
Really appreciate you jumping on this one quickly, this will have thrown off client reporting quite a bit, but appreciate getting it fixed up.
Tim
October 4, 2021 at 3:58 pm #1323488Hi Tim,
Thanks for the report and confirmation! Fix will be included in upcoming update :)
Best regards,
YigitOctober 4, 2021 at 4:09 pm #1323493Perfect, thanks!
Off topic – will the final post-css elements be included in the next release too?
October 4, 2021 at 4:51 pm #1323501Hi,
No, 4.8.6.4 should be released today – but they will be in the following release.
Together with contact form (empty line and headline element).Best regards,
GünterOctober 4, 2021 at 7:06 pm #1323527Brilliant, thanks Gunter, the following release sounds great!
November 11, 2021 at 3:53 pm #1328675This can be closed, thanks.
-
AuthorPosts
- The topic ‘Google Analytics On Click Bug’ is closed to new replies.