Skip to content

Instantly share code, notes, and snippets.

@hkb
Forked from fadur/log_click.js
Created March 21, 2012 17:30
Show Gist options
  • Save hkb/2149884 to your computer and use it in GitHub Desktop.
Save hkb/2149884 to your computer and use it in GitHub Desktop.
atach event to list
function bind_click_logging() {
$('.product_items > a').click(function() {
// fetch link destination
var href = $(this).attr('href');
// extract product id
var _href = href.split('/');
var id = parseInt(_href[_href.length-2]);
// set timeout
var t = setTimeout('window.location.href = "' + href + '";', 500);
// do remote call
$.getJSON(
'http://api.thesocialdigits.com/v1/__log_click?callback=?',
{
'key': 'your_api_key', // <-- insert api key here
'payload': JSON.stringify({'product': id,
'metadata': {'api': 'search', 'args': {}}})
},
function() {
// on success, clear timeout and go!
clearTimeout(t);
window.location.href = href; // go on success
}
);
return false; // don't go yet
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment