Capture Site Search Terms in X-Cart w/ Google Analytics
Tracking your internal site search engine is a great way to optimize your e-commerce store. The standard X-Cart reporting of site search does very little in helping you better analyze your visitor patterns. You can uncover more actionable data by including Site Search in your Google Analytics reports. For more help on actionable data checkout the Top 5 Actionable Analytics Reports For X-Cart post.
To accurately track internal site search for X-cart (using X-Cart’s standard search engine) you must follow two steps.
NOTE: If you are using Altered Carts Smart Search module you can skip to step 2.
Installation
1. First we must modify the code. Navigate to skin1/modules/Google_Analytics/ga_code.tpl and replace those contents with the following:
{if $main eq “search”}
<!– Start of GATC –>
<script type=”text/javascript”>
var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
</script>
<script type=”text/javascript”>
var pageTracker = _gat._getTracker(”UA-XXXXXX-X“);
terms=’{$search_prefilled.substring|escape}’;
searchterms=terms.toLowerCase().replace(/\s/g,’+');
pageTracker._trackPageview(’/search?q=’+searchterms);
</script>
<!– End of GATC –>
{else}
<!– Start of GATC –>
<script type=”text/javascript”>
var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
</script>
<script type=”text/javascript”>
var pageTracker = _gat._getTracker(”UA-XXXXXX-X“);
pageTracker._trackPageview();
</script>
<!– End of GATC –>
{/if}
Be sure to replace UA-XXXXXX-X with your actual Analytics account number.
Save the new file and upload it over the old (after backing up).
2. Now login to your Google Analytics account
- Click the ‘Edit’ link next to your profile
- On the next page in the first box click the upper right corner that says ‘Edit’
Adjust your Site Search settings so they match below
To view your new Site Search data navigate to Content->Site Search inside your profile









This did not seem to work. I did exactly as stated above, then used the search function on the site and checked analytics…no searches.
Is there any sort of waiting period before it works correctly?
Hi Matt,
What version of X-Cart are you using?
I checked your store code and X-Cart is not calling the first portion of the .tpl
Did you include the {if $main eq “search”} part?