From c44f4afcbe6faa7369c1628cdb411d42463c2b94 Fri, 19 Oct 2012 13:03:27 +0200 From: hass Date: Fri, 19 Oct 2012 13:03:04 +0200 Subject: [PATCH] #1801020: Track colorbox as pageview diff --git a/googleanalytics.js b/googleanalytics.js index d86d3de..b81babd 100644 --- a/googleanalytics.js +++ b/googleanalytics.js @@ -16,8 +16,12 @@ // Is the clicked URL internal? if (isInternal.test(this.href)) { + // Skip 'click' tracking, if custom tracking events are bound. + if ($(this).is('.colorbox')) { + // Do nothing here. The custom event will handle all tracking. + } // Is download tracking activated and the file extension configured for download tracking? - if (ga.trackDownload && isDownload.test(this.href)) { + else if (ga.trackDownload && isDownload.test(this.href)) { // Download link clicked. var extension = isDownload.exec(this.href); _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]); @@ -39,4 +43,14 @@ } }); }); + + // Colorbox: This event triggers when the transition has completed and the + // newly loaded content has been revealed. + $(document).bind("cbox_complete", function() { + var href = $.colorbox.element().attr("href"); + if (href) { + _gaq.push(["_trackPageview", href]); + } + }); + });