Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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

    #1323079

    examples below

    #1323144

    Hi,

    Thanks for reporting this.

    Can you please try to update enfold\framework\js\conditional_load\avia_google_recaptcha_api.js

    with the content of

    https://github.com/KriesiMedia/enfold-library/blob/master/temp_fixes/Enfold_4_8_6_3/js/avia_google_recaptcha_api.js.

    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ünter

    #1323292

    Hey 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

    #1323383

    Hi,

    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,
    Ismael

    #1323428

    Hi,


    @THP
    @Ismael

    I can confirm, that the fix above works for me.

    Best regards,
    Günter

    #1323481

    Hi @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

    #1323488

    Hi Tim,

    Thanks for the report and confirmation! Fix will be included in upcoming update :)

    Best regards,
    Yigit

    #1323493

    Perfect, thanks!

    Off topic – will the final post-css elements be included in the next release too?

    #1323501

    Hi,

    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ünter

    #1323527

    Brilliant, thanks Gunter, the following release sounds great!

    #1328675

    This can be closed, thanks.

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Google Analytics On Click Bug’ is closed to new replies.