Skip to content

Commit

Permalink
Add datalayer pushes when form validation is triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmking committed Jan 22, 2021
1 parent 983fc88 commit 0f822e4
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,28 @@

@section breadcrumb {
<div class="das-js-back-link"></div>
}

@section pageSpecificJS {
<script type="text/javascript">
// DataLayer pushes when form validation message is shown
$(function () {
var errorSummary = $('.govuk-error-summary');
var pageTitle = $('h1.govuk-heading-xl').text();
errorSummary.each(function () {
var dataLayerObj
var numberOfErrors = $(this).find('ul.govuk-error-summary__list li').length;
var validationMessage = "Form validation";
if (numberOfErrors === 1) {
validationMessage = $(this).find('a').eq(0).text();
}
dataLayerObj = {
event: 'form submission error',
page: pageTitle,
message: validationMessage
}
window.dataLayer.push(dataLayerObj)
});
});
</script>
}

0 comments on commit 0f822e4

Please sign in to comment.