6

次の関数を使用して、Web サイトの 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();
            });
    });
});

Google アナリティクスのトラッキングと Disqus の読み込みを機能に統合できるかどうかを知りたいです。これは私がdisqusを読み込もうとしたコードですが、何らかの理由で別のWebサイトからコメントを読み込みます:

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

ありがとう

4

1 に答える 1

3

新しい仮想 URL を 2 番目のパラメーターに配置して、Google アナリティクス関数をイベント呼び出しに直接配置するだけです。

$(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 ]);
            });
    });
});

(イベント内でキャッシュするように関数を編集しました。これはhref、呼び出しごとに固定される値に対して 3 つ (現在は 4 つ) の個別の jQuery オブジェクトをスピンアップするのは非効率的であるためです。)

于 2011-04-29T16:43:35.413 に答える