• Resolved chatzidimosa

    (@chatzidimosa)


    We have successfully integrated the plugin with our mailchimp account and created a sign up form (custom integration) with an email field and some radio buttons. We are trying to pass the value of the radio button the user checked to the data layer using Tag Manager using this guide, https://www.mc4wp.com/kb/google-tag-manager-tracking/, but while the tag fires up and the form name and id passes to the data layer, the variable for the checkbox value does not. If we set a default value for the checkboxes the value passes successfully. This is our code below the form.

    <script type="text/javascript">
       jQuery('.radio-box').on('click',function(){
       jQuery(this).attr('checked', 'checked');
       });
       mc4wp.forms.on('started', function(form) {
    
       var radioName = "MMERGE6";
       var checked = document.querySelector('[name="' + radioName + '"]:checked').value;
       window.dataLayer = window.dataLayer || [];
       window.dataLayer.push({ 'event' : 'Sign-up', 'name' : form.name + ' ID: ' + form.id, 'checked' : checked});
      });
    
    </script> 

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Lap

    (@lapzor)

    Hi,

    I’m afraid that this sort of custom code is out of scope for our free support.
    Here is a hint in the right direction: https://www.w3schools.com/jsref/prop_radio_checked.asp

    I recommend you use the browser console first to see if you correctly get the value and then integrate that into your script to send that value to Google.

    Hope that helps. If you have any questions directly related to our plugin, please let me know!

    Thread Starter chatzidimosa

    (@chatzidimosa)

    Hello Lap! Thank you for your swift answer! We modified the code so it can return the value of the radio button if we omit the following line of code (based on the guide provided):
    mc4wp.forms.on('success', function(form)

    So the tag fires correctly by capturing the radio button, although this is problematic because the tag needs to fire only on success.

    Any ideas?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Google tag manager variable for checked radio button does is always undefined’ is closed to new replies.