1

Google Analytics provide a feature that can analyze "Age" & "Gender" of visitors. But my customer want to track these data by submiting a form after checkout successfully.

That form looks as follow:

<form id="form-checkout" class="form-success" method="post"  action="">
        <ol class="fs-fields">
          <li class="gender">
            <label><?php echo $this->__('Gender') ?></label>
            <div class="fs-radio-group fs-radio-custom clearfix fs-anim-lower">
              <span><input type="radio" name="gender" value="Male" /><label><?php echo $this->__('Male')?></label></span>
              <span><input type="radio" name="gender" value="Female" /><label><?php echo $this->__('Female')?></label></span>
            </div>
          </li>
          <li class="ages">
            <label><?php echo $this->__('Ages') ?></label>
            <select name="ages">
              <option value="< 20"><?php echo $this->__('< 20') ?></option>
              <option value="20-35"><?php echo $this->__('20-35') ?></option>
              <option value="35-50"><?php echo $this->__('35-50') ?></option>
              <option value="> 50"><?php echo $this->__('> 50') ?></option>
            </select>
          </li>
        </ol>
        <div class="button-box">
          <button class="fs-submit fs-show" type="button" title="<?php echo $this->__('submit') ?>" onclick="sendDataToUa();"><span><?php echo $this->__("Back to Home")?></span></button>
          <button class="fs-submit fs-show" type="button" title="<?php echo $this->__('Continue Shopping') ?>" onclick="window.location='<?php echo $this->getUrl() ?>'"><span><?php echo $this->__('Continue Shopping') ?></span></button>
        </div>
      </form>

Js script:

<script type="text/javascript">
  function sendDataToUa(){
    var gender = jQuery('input[name=gender]:checked', '#form-checkout').val();
    var ages = jQuery('#form-checkout option:selected').val();
    ga('set', 'dimension1', gender);
    ga('set', 'dimension2', ages);
    ga('send', 'pageview', {
      'dimension1': gender,
      'dimension2': ages,
    });
  }
</script>

UPDATE: I'm waiting for report data on google analytics.

1 Answer 1

1

To get started on customer attributes of the dropdown variety:

how to create drop down attributes for customer

However, do you need to tie that information in to Magento when it is only needed on GA? You don't have to save the data in the backend for the age range.

For gender you might want to just collect people's title, e.g. Mr, Ms, then have a hidden form element with your Google-friendly gender field. Then people aren't going to be irritated by being asked their gender (a minor obstacle to purchase but one nonetheless). With the 'salutation' field (title) you just need to enable it in sys config.

With that done you can then have a js script in your form to observe onchange or onblur with the title element, then a couple of 'if' statements to update your hidden 'google only' form element.

Sorry I haven't posted any code for this yet, however, I am thinking of implementing roughly the above because I have wanted to capture that information for a while and did not see how to do it easily with GA until I saw your question.

5
  • Thank you for your opinion, I'm still thinking the solution. I've just updated the question, could you take a look please ?
    – HungDQ
    Commented Jul 8, 2015 at 9:45
  • I can't work on checkout today so it might be a while before I get back to you regarding implementation. But I will star this question. Commented Jul 8, 2015 at 11:02
  • Thank you Wolfie, I'm waiting for your response. I've just updated my code.
    – HungDQ
    Commented Jul 8, 2015 at 16:14
  • Let's see how the report goes! Commented Jul 8, 2015 at 16:47
  • I have been waiting for 40 hours but the report is still empty.
    – HungDQ
    Commented Jul 10, 2015 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.