2

ネストされた.headerdivをクリックすることで最大化および最小化できる、多くの.itemdivを含むIsotope#containerdivがあります。また、視聴者が現在最大化されているコンテンツdivを最小化(ヘッダーをクリック)せずに別のコンテンツdivを直接クリックすると、自動的に最小化されます。

したがって、Googleアナリティクスのイベントトラッキングが2回発生することがあります。視聴者が別の.itemdivの.headerdivを直接クリックしない場合ですが、現在最大化されているものを最初にクリックしてから、別のdivをクリックすることで最小化することにします。

ロジックを変更して、分析に1つのクリックイベントのみが登録されるようにするにはどうすればよいですか?

$('.header').click(function () { // instead of registering the entire .item div (default use), only its .header div (child div) receives clicks

    var $previousSelected = $('.selected'); // necessary for maximising and minimising

    if ($(this).parent().hasClass('selected')) { // use $(this).parent() - not $(this) - because the .header div is a child of the .item div

        $(this).parent().removeClass('selected');
        $(this).parent().children('.maximised').hide();
        $(this).parent().children('.minimised').show();

        $items.find('.minimised').removeClass('overlay'); // returns all .minimised divs to previous state after the .item is closed again

    } else {

        $previousSelected.removeClass('selected');
        $previousSelected.children('.minimised').show();
        $previousSelected.children('.maximised').hide();

        $(this).parent().addClass('selected');
        $(this).parent().children('.minimised').hide();
        $(this).parent().children('.maximised').show();

        $items.not('.selected').find('.minimised').addClass('overlay'); // adds .overlay on each .item which is not currently .selected

    }

    $container.isotope('reLayout');

    <!-- ga project interest tracking -->

    var clicked = $(this).parent().data('item');
    _gaq.push(['_trackEvent', 'Items viewed', 'Clicked', clicked, null, true]);

});
4

1 に答える 1

1

したがって、私が正しく理解している場合は、何かが最大化されたときにのみGA追跡を実行する必要があります。

$(this).parent().children('.maximised').show(function(){
    _gaq.push(['_trackEvent', 'Items viewed', 'Clicked', clicked, null, true]);
});

.click関数の下部で試すこともできます。

if( $(this).parent().children('.maximised').is(':visible') ){
   _gaq.push(['_trackEvent', 'Items viewed', 'Clicked', clicked, null, true]); 
}
于 2012-08-23T14:57:48.243 に答える