Skip to content

Instantly share code, notes, and snippets.

@yratof
Last active August 29, 2015 14:01
Show Gist options
  • Save yratof/30cb927ee09009b4d18e to your computer and use it in GitHub Desktop.
Save yratof/30cb927ee09009b4d18e to your computer and use it in GitHub Desktop.
Track Zero Search Results
<script type="text/javascript">
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
var SearchTerm = gup('s');
_gaq.push(['_trackEvent', 'Search', 'ZeroResults', (SearchTerm ? SearchTerm : 'blank')]);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment