Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save funnelback/6280244 to your computer and use it in GitHub Desktop.
Save funnelback/6280244 to your computer and use it in GitHub Desktop.
Track zero and partially-matching search results events in Google Analytics. Embed in existing search template. Modern UI only.
<@s.AfterSearchOnly>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'GOOGLE-ANALYTICS-UA']);
<#if response.resultPacket.resultsSummary.totalMatching == 0>
<#-- TRACK QUERIES WITH ZERO RESULTS -->
_gaq.push(['_setCustomVar', 1, 'No matching results', '<@s.QueryClean/>', 3]);
<#else>
<#if response.resultPacket.resultsSummary.fullyMatching == 0>
<#-- TRACK QUERIES WITH PARTIALLY-MATCHING RESULTS ONLY -->
_gaq.push(['_setCustomVar', 1, 'Partially-matching results', '<@s.QueryClean/>', 3]);
<#else>
_gaq.push(['_trackPageview']);
</#if>
</#if>
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</@s.AfterSearchOnly>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment