- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
02-02-2016 08:43 PM - edited 02-02-2016 09:09 PM
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!
02-08-2016 09:49 AM - edited 02-08-2016 09:51 AM
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.
Copyright All Rights Reserved © 2008-2023