Richard Parnaby-King

Track pages that do not exist with Google Analytics

Using Google Analytics it is possible to track pages as though a user had visited it, even if the page does not exist. This is useful for, for example, ajax form submissions – instead of redirecting to a thank-you page, you can leave the user on the same page and track a custom page (that does not exist) in Google Analytics.

Below is the minimum configuration needed to track a page asynchronously.
[javascript]

(function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'https://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
[/javascript]

To submit a custom page, have the call-back of the ajax form request echo the following code:
[javascript]

[/javascript]

If you are not using an ajax request to submit a form, e.g. you are submitting the form to the same page, then simply add the above code after the Google Analytics code.