Skip to content

Instantly share code, notes, and snippets.

@pavenuto
Created November 15, 2010 20:41
Show Gist options
  • Save pavenuto/700901 to your computer and use it in GitHub Desktop.
Save pavenuto/700901 to your computer and use it in GitHub Desktop.
if ($('#no-results').length) {
var term = $('#search-results').find('li:first a.only-this-tag').text();
if ($("#search-results").find('li').length == 1) {
$.track('ProductSearch', 'ZeroResults', term);
}
}
if ($("#zip-code-search").length) {
$("#zip-code-search").bind("submit", function(e) {
var zipcode = $('#zip_code').val();
$.track('Locations','ZipCodeSearch',zipcode,{pause: true});
});
}
$("a[rel=external]").attr("target", "_blank").bind("click.external", function (b) {
$.track("External Links", "click", this.href, {pause: true});
});
$.extend({
trace: function(msg){
if (window.console) {
console.log(msg);
};
},
track: function(category, action, label, options){
var settings = { pause: false };
if (options) $.extend(settings, options);
try {
_gaq.push(['_trackEvent', category, action, (label ? label : 'blank')]);
} catch(e) {}
$.trace('_gaq.push([\'_trackEvent\', ' + category + ', ' + action + ', ' + label + ')]);');
if (settings.pause) {
// pause to allow google script to run
var date = new Date();
var curDate = null;
do {
curDate = new Date();
} while(curDate-date < 300);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment