Skip to content

Commit

Permalink
Bug 884358 - Refactor & test GA event tracking/timeout functionality …
Browse files Browse the repository at this point in the history
…in TabZilla
  • Loading branch information
kyoshino committed Jun 18, 2013
1 parent 4b5fe49 commit 7ca4249
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 7ca4249

Please sign in to comment.