Search code examples
jqueryformsgoogle-analyticsanalytics

Tracking submissions of a form which doesn't submit anywhere


I have an overlay with form (just a radio button group with 3 buttons and a submit button) that, on submit, uses jQuery to open a specific file (a PDF) in a new tab and then close the overlay. The file depends on which button was selected. The problem: the form doesn't actually submit so I don't know how to track submissions, and the client wants to know the percentage of people clicking each button.

How can I track that? I can't track actual submissions because obviously nothing gets POST'ed or GET'ed, and I can't track Google Analytics clicks because GA only tracks clicks on links, not on form buttons.

Any ideas? Is this enough info? I can post the code, but it involves cookies and Thickbox and would just add more confusion to anyone trying to understand the situation.


Solution

  • Function _trackPageview()—that is part of the standard tracking code you embed in your web pages—could be also called with an argument string at anytime to generate a virtual page request for Google Analytics.

    Google Analytics' _trackPageview is a function for use on ga.js tracked sites that allows you to track events on your site that do not generate a pageview. Using the _trackPageview JavaScript, you can assign a specific page filename to Flash events, JavaScript events, file downloads, outbound links, and more.

    For further details see article How do I track JavaScript events? in Google Analytics Help Center.