-
-
Save hkb/2149884 to your computer and use it in GitHub Desktop.
atach event to list
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
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