我有一个关于这个答案的问题https://stackoverflow.com/a/2078233/560972
据我所知,使用JS(Ajax)跟踪传出链接点击最常见的问题是,有时用户在脚本(更快)抓取数据之前就离开了页面。。。?
所以,也许可以强制某种延迟,让脚本完成录制,然后让用户导航到其他网站?点击链接和发生导航时的延迟
这有帮助吗?我想~200ms/300ms对用户来说是不可见的,但对于ajax调用来说可能已经足够了?
你怎么想?
谢谢!
使用jquery:
$('a').click(function(e) {
//check that it is offsite
if($(this).attr("href").indexOf("http")==1) {
//prevent the redirect;
e.preventDefault();
//do your tracking
$.ajax{
url: 'yourtracking.php',
data: "link=" + $(this).attr("href"),
complete: function(){
//now do the redirect
window.location = $(this).attr("href");
}
}
}
});