ネストされた.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]);
});