Track Forms in iModules

Script Google Analytics Events into a Form

July 25, 2014

How successful are your web forms?

Find out by comparing how many visitors to a form complete the form. If your form sends users to a new URL, use Google Analytics to compare the results.

But completed forms in iModules (as well as Net Community) have the same URL as the previous step. So Google Analytics won’t work out of the box.

You can use JavaScript to log an event or create a dummy URL in Google Analytics. In Net Community, this is a built-in feature and you can set this up through the CMS. In iModules, you’ll need to add some code to the content stage you want to track as well as a script to the template.

This solution utilizes Google Analytics events, which provides sample code for creating an event when a user clicks a link.

<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']);">Play</a>

This is useful for tracking pdf downloads, video plays, external links, and other user actions that don’t involve loading a unique url on your website. But we need to do a few things to get it to work for our purposes.

  1. Change onClick to onLoad
  2. Change the link to a block that can fire onLoad
  3. Externalize the gag.push script because the iModules WYSIWYG will strip it out

Add the gag.push script to your template. The script must appear prior to the onLoad text.

//Fires an event in Google Analytics
function gaEvent(category, action, label) {    
  ga('send', {
    'hitType': 'event',          // Required.
    'eventCategory': category,   // Required.
    'eventAction': action,      // Required.
    'eventLabel': label,
    //'eventValue': 4

Add the following code to your finish page (and any other step in your form you want to track). Replace $variables with your customized tracking fields.

<!--Record Google Analytics Event-->
<style onload="gaEvent('$category' , '$action', '$label')"></style>

So how successful are your forms? Now that you are recording data, here are some suggested research projects that will give you insight into how to improve your forms.

  1. Figure out the drop off, by dividing your event number by the number of visits
  2. Compare the drop off of different devices and browsers
  3. Compare the drop off between different forms
  4. Change your form (preferably through A/B split tests) and see if your results improve