2011-04-29 48 views
6

我使用下面的函数重载与阿贾克斯我的网站的URL链接:JQuery的生活+ Disqus /谷歌Analytics(分析)

$(document).ready(function() { 
    $('.insite').live("click", function(ev) { 
     if (history.pushState) history.pushState({}, document.title, $(this).attr('href')); 
     ev.preventDefault(); 
     $('#content').fadeOut().load($(this).attr('href')+' #content', function() { 
       $(this).fadeIn(); 
      }); 
    }); 
}); 

我想知道是否有可能整合谷歌Analytics跟踪和Disqus装入功能。 这是我试图加载disqus的代码,但它加载从其他网站由于某些原因评论:

window.disqus_no_style = true; 
$.getScript("http://disqus.com/forums/mnml/embed.js") 

感谢

回答

3

你可以只是把谷歌Analytics(分析)功能直接在事件调用,放置新的虚拟URL在第二个参数中。

$(document).ready(function() { 
    $('.insite').live("click", function(ev) { 
    var href = $(this).attr('href'); 
     if (history.pushState) history.pushState({}, document.title, href); 
     ev.preventDefault(); 
     $('#content').fadeOut().load(href+' #content', function() { 
       $(this).fadeIn(); 
       _gaq.push(['_trackPageview', href ]); 
      }); 
    }); 
}); 

(I已经编辑缓存事件内的href的功能,因为它的低效率的旋转起来3(现在4)单独的jQuery对象为将要固定的每个呼叫的值。)

相关问题