I am trying to track an AJAX form submission in Google Analytics. I have tried using the following code to create a page view in GA to track goals, however the page view is not tracking.
<script type="text/JavaScript">
$("#template-contactform").validate({
submitHandler: function(form) {
$('.form-process').fadeIn();
$(form).ajaxSubmit({
target: '#contact-form-result',
success: function() {
$('.form-process').fadeOut();
$('#template-contactform').find('.sm-form-control').val('');
$('#contact-form-result').attr('data-notify-msg', $('#contact-form-result').html()).html('');
SEMICOLON.widget.notifications($('#contact-form-result'));
ga('send', {
'hitType' : 'pageview',
'page' : '/contact-us-success' // Virtual page (aka, does not actually exist) that you can now track in GA Goals as a destination page.
});
}
});
}
});
</script>
UPDATE:
I have resolved this by using Event Tracking. I used the code below in the submit button and created a new goal tracking the event in GA.
onClick="ga('send', 'event', { eventCategory: 'Contact', eventAction: 'ContactRequest'});
ga('set', 'page', page);ga('send', 'pageview');