I did it because I need it quickly…
<script type="text/javascript">
(function($) {
$(document).ready(function() {
$('form').find(':input').blur(function() {
if (this.value === this.defaultValue) {
var inputAction = 'skipped';
} else {
var inputAction = this.value ? 'completed' : 'skipped';
}
// console.log('Form Abandonment Tracking - Detected: ' + (this.form.id || 'form-without-id') + ' Label: ' + this.name + ' Action: ' + inputAction);
// G.A. Universal
if (typeof ga !== 'undefined') {
ga('send', 'event', (this.form.id || 'form-without-id'), inputAction, $(this).attr('name'));
console.log('Form Abandonment Tracking - GA Universal in use, sent: ' + (this.form.id || 'form-without-id') + ' Label: ' + this.name + ' Action: ' + inputAction);
}
// G.A. Universal compatible Google Analytics by Yoast plugin
if (typeof __gaTracker !== 'undefined') {
__gaTracker('send', 'event', (this.form.id || 'form-without-id'), inputAction, $(this).attr('name'));
console.log('Form Abandonment Tracking - GA Universal in use, sent: ' + (this.form.id || 'form-without-id') + ' Label: ' + this.name + ' Action: ' + inputAction);
}
//check if _gaq is set too
if (typeof _gaq !== 'undefined') {
_gaq.push(['_trackEvent', (this.form.id || 'form-without-id'), inputAction, $(this).attr('name')]);
console.log('Form Abandonment Tracking - Google Analytics in use, sent: ' + (this.form.id || 'form-without-id') + ' Label: ' + this.name + ' Action: ' + inputAction);
}
});
$('form').find(':input').click(function() {
if(this.type && this.type.toLowerCase() === 'submit') {
inputAction = 'submitted';
// console.log('Form Abandonment Tracking - Submit clicked: ' + (this.form.id || 'form-without-id') + ' Label: ' + this.name + ' Action: ' + inputAction);
// G.A. Universal
if (typeof ga !== 'undefined') {
ga('send', 'event', (this.form.id || 'form-without-id'), inputAction, $(this).attr('name'));
console.log('Form Abandonment Tracking - GA Universal in use, sent: ' + (this.form.id || 'form-without-id') + ' Label: ' + this.name + ' Action: ' + inputAction);
}
// G.A. Universal compatible Google Analytics by Yoast plugin
if (typeof __gaTracker !== 'undefined') {
__gaTracker('send', 'event', (this.form.id || 'form-without-id'), inputAction, $(this).attr('name'));
console.log('Form Abandonment Tracking - GA Universal in use, sent: ' + (this.form.id || 'form-without-id') + ' Label: ' + this.name + ' Action: ' + inputAction);
}
//check if _gaq is set too
if (typeof _gaq !== 'undefined') {
_gaq.push(['_trackEvent', (this.form.id || 'form-without-id'), inputAction, $(this).attr('name')]);
console.log('Form Abandonment Tracking - Google Analytics in use, sent: ' + (this.form.id || 'form-without-id') + ' Label: ' + this.name + ' Action: ' + inputAction);
}
}
});
});
})(jQuery);
</script>