Roc*_*och 6 javascript jquery google-analytics live disqus
我正在使用以下函数来重载我的网站URL链接与Ajax:
$(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();
});
});
});
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以将Google Analytics跟踪和Disqus加载集成到该功能中.这是我试图加载disqus的代码,但由于某些原因它从其他网站加载评论:
window.disqus_no_style = true;
$.getScript("http://disqus.com/forums/mnml/embed.js")
Run Code Online (Sandbox Code Playgroud)
谢谢
您可以直接将 Google 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 ]);
});
});
});
Run Code Online (Sandbox Code Playgroud)
(我已经编辑了函数来缓存href事件中的内容,因为为每个调用固定的值旋转 3 个(现在是 4 个)单独的 jQuery 对象效率很低。)