Created
August 20, 2013 11:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<@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