Skip to content

Instantly share code, notes, and snippets.

@maxcal
Created January 26, 2012 16:01
Show Gist options
  • Select an option

  • Save maxcal/1683484 to your computer and use it in GitHub Desktop.

Select an option

Save maxcal/1683484 to your computer and use it in GitHub Desktop.
Action Tracker...
/**
*
* 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