Skip to content

Commit

Permalink
Merge pull request #981 from kyoshino/bug-884358-tabzilla-refactor
Browse files Browse the repository at this point in the history
Bug 884358 - Refactor & test GA event tracking/timeout functionality in TabZilla
  • Loading branch information
jpetto committed Jun 19, 2013
2 parents 8e972ac + 7ca4249 commit 9465905
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions bedrock/tabzilla/templates/tabzilla/tabzilla.js
Expand Up @@ -231,14 +231,22 @@ var Tabzilla = (function (Tabzilla) {
$('#tabzilla-contents').on('click', 'a', function (e) {
var newTab = (this.target === '_blank' || e.metaKey || e.ctrlKey);
var href = this.href;
var timer = null;
var callback = function () {
clearTimeout(timer);
window.location = href;
};

if (typeof(_gaq) == 'object') {
_gaq.push(['_trackEvent', 'Tabzilla', 'click', href]);
if (!newTab) {
if (newTab) {
_gaq.push(['_trackEvent', 'Tabzilla', 'click', href]);
} else {
e.preventDefault();
setTimeout(function () {
window.location = href;
}, 500);
timer = setTimeout(callback, 500);
_gaq.push(
['_set', 'hitCallback', callback()],
['_trackEvent', 'Tabzilla', 'click', href]
);
}
}
});
Expand All @@ -248,14 +256,20 @@ var Tabzilla = (function (Tabzilla) {

var $form = $(this);
var keyword = $form.find('#q').val();
var timer = null;
var callback = function () {
clearTimeout(timer);
$form.submit();
};

$form.unbind('submit');

if (typeof(_gaq) == 'object' && keyword !== '') {
_gaq.push(['_trackEvent', 'Tabzilla', 'search', keyword]);
setTimeout(function () {
$form.submit();
}, 500);
timer = setTimeout(callback, 500);
_gaq.push(
['_set', 'hitCallback', callback()],
['_trackEvent', 'Tabzilla', 'search', keyword]
);
} else {
$form.submit();
}
Expand Down

0 comments on commit 9465905

Please sign in to comment.