Skip to content

Instantly share code, notes, and snippets.

@simondahla
Created October 15, 2013 09:22
Show Gist options
  • Save simondahla/6988950 to your computer and use it in GitHub Desktop.
Save simondahla/6988950 to your computer and use it in GitHub Desktop.
/* Track 0 Serch Results with if statment */
var content = document.getElementById('middlewrapper');
if (content.innerHTML.search('Inga produkter hittades!')) {
var sn = "q";
var sr = new RegExp(sn+"=[^\&]+"),
p = document.location.pathname,
s = document.location.search,
sm = s.match(sr).toString(),
srs = sm.split("="),
sre = sm.replace(sr,srs[0]+"=no-results: "+srs[1]+"&cat=no-results"),
sf = s.replace(sr,sre);
_gaq.push(['_trackPageview', p + sf]);
}
/* Track 0 Serch Results */
var sn = "q";
var sr = new RegExp(sn+"=[^\&]+"),
p = document.location.pathname,
s = document.location.search,
sm = s.match(sr).toString(),
srs = sm.split("="),
sre = sm.replace(sr,srs[0]+"=no-results: "+srs[1]+"&cat=no-results"),
sf = s.replace(sr,sre);
_gaq.push(['_trackPageview', p + sf]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment