Track form errors on the page - GUA

Gold Contributor
Gold Contributor

When the user filling a form submission the form may return a page error based on its own set of validation rules (some fields may be required, other fields may contain invalid data, some combinations of selection may not work, etc). These need to be captured in GA using events.

 

So for each site of the sites, we need to scrape the error messages from the form. We then need to call a utag.link() to fire an event. If we have 5 error messages on the page, we need to fire 5 error message events. 

 

How should i write custom error tracking code on this page to pick up all error messages and then convert these to events using Extensions?

 

Could anyone provide solutions on this to proceed further. Thanks in advance!

3 REPLIES 3

Track form errors on the page - GUA

Gold Contributor
Gold Contributor
Could anyone help me on this.

Thanks in advance!

Track form errors on the page - GUA

Employee Emeritus

@Srinivasan,

 

I suggest contacting the development team in charge of the form validation. They can passback the data you need once the form doesn't pass validation for any given field. 

 

You may be able to leverage the form validation return true or false responses depending on what validation method you use. I don't know anything about the form or validation method you're using, but you might be able to create a jQuery onHandler for this form id (on submit or mousedown), then add a 'custom' code like below:

 

	
// Checks the input fields for the error class/id
var el = jQuery(this)
var erVis = el.parents().find('[id*="-error"]')
// Iterate through the input fields that have the error class/id
jQuery.each(erVis, function() {
    var er = jQuery(this)
    // Send the data for each error message
    utag.link({
        form_id: el.attr('id'),
        error_element: er.attr('for').split('c')[1],
        error_message: er.text()
    })
})

I don't recommend scraping the HTML like this because it can be difficult to maintain and cause issues if/when the CSS or HTML changes in the future. This is only my recommended attempt as a last resort.

 

Track form errors on the page - GUA

Gold Contributor
Gold Contributor

christina_schel

 

Thanks for your response on this.

 

Have a great day!

 

Public