I’m trying to put Google Analytics code in place to track searches on my site, as per the instructions in the Wiki article.
I have the following in place in my search results template (at /search/results/) (the forum will have removed some parts of it, of course)
[removed]
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
[removed](unescape("<script src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'></script>"));
[removed]
[removed]
var pageTracker = _gat._getTracker("UA-XXXXXX-XX");
pageTracker._initData();
terms='{exp:search:keywords}';
searchterms=terms.toLowerCase().replace(/\s/g,'+');
pageTracker._trackPageview('/search?q='+searchterms);
[removed]
With the correct account number in place of XXXXXX of course.
It’s been in place for over a week now and yet isn’t tracking any searches at all. Analytics reports no searches having taken place, though I know they have - I’ve been doing loads to see the results, and there are lots being reported in the CP search logs.
Can anyone see what I’m doing wrong here? My regular Analytics code looks like this:
[removed]
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
[removed](unescape("[removed][removed]"));
[removed]
[removed]
try {
var pageTracker = _gat._getTracker("UA-XXXXXX-XX");
pageTracker._trackPageview();
} catch(err) {}[removed]
which looks a little different. I’m going to try and adapt the search code a bit more, but any help in the meantime really appreciated.
Thanks.