In our YII app, we would like to capture google analytics on validation failures. We are using modal rules for validating our data. Here is one of our validation modal code snippet
public function rules() {
return [
['email', 'validateEmail'],
];
}
public function validateEmail($attribute_name, $params) {
if (EMAIL EXITS IN DATABASE) {
$this->addError($attribute_name, Yii::t('app', 'Email Already Exist.'));
return false;
}
}
It correctly shows an error message on our frontend but we can not track this in google analytics. We would like to call a javascript function whenever this validation fails. Here is our javascript function
function captureGAEvent(category, action, label) {
alert(category + " " + action + " " + label);
ga('send', 'event', category, action, label);
}
Please guide.