Created
January 26, 2012 16:01
-
-
Save maxcal/1683484 to your computer and use it in GitHub Desktop.
Action Tracker...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * Some boilerplate code to explain tracking... | |
| * | |
| * @param jQuery $form - a form to bind the action against. | |
| * @param string url - where to post tracking data | |
| */ | |
| function TrackActionForm($form, url){ | |
| $form.submit(function(e){ | |
| var data = { | |
| // Put data from form here. | |
| referrer: window.location | |
| }; | |
| if (jQuery.data($form, 'tracked') !== 'true') { | |
| // Prevent default submit action... | |
| e.preventDefault(); | |
| $.post(url, data, function(){ | |
| // Do this when complete | |
| jQuery.data($form, 'tracked', 'true'); | |
| $form.submit(); | |
| }, 'jsonp'); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment