I have a contact form that is submitted via ajax and upon a successful submission, a thank you/success message is displayed.
Additionally, I\'ve set up a goal (Goal Comp
This answer possibly needs to be updated for more recent versions of GA. I did the following to set up goals when the page is submitted via ajax.
$.ajax({
type: "POST",
url: "/some/page/that/does/not/have/ga/on/it.php",
data: { formData:formData },
success: function() {
// Some success message to user.
// Create a virtual page view that you can track in GA.
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.
});
}
});
Then in GA -> Admin -> Goals -> New Goal
(1) Goal setup - Custom
(2) Goal description -> choose 'Destination'.
(3) Goal details -> Destination Equals to /contact-us-success
Hope this helps someone else.