Ripwinder Ripwinder - 1 year ago 202
Ajax Question

AJAX form submission and Google Analytics

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">

submitHandler: function(form) {
target: '#contact-form-result',
success: function() {
$('#contact-form-result').attr('data-notify-msg', $('#contact-form-result').html()).html('');
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.


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'});

Answer Source

I found the easiest solution for me was to include the below code in the submit button of my form:

onClick="ga('send', 'event', { eventCategory: 'Contact', eventAction: 'ContactRequest'});

In Google Analytics do the following:

Click on Admin. Under the View list, click on Goals Click on the New Goal button, click on the Custom radio button and then click on the Next step button. Name the goal and select the Event radio button. Populate all of the relevant goal details:

Category: Contact

Action: ContactRequest

Label: Optional

Value: Optional

Click the Create Goal button. You can now track form submissions in conversions.

Keep in mind this is tracking every click, so if you have mandatory fields and a user forgets and is prompted to complete the field, this will still register. For my use case its fine, but another solution would have to be sought if this is not the case for your forms.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download