Analytics
1.7K members online now
1.7K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

On-Site Search reporting not working

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

We have an issue with GA not picking on our onsite search queries.  

http://staplescopyandprint.ca/WebSearchResult.aspx/#?query=asfass

 

This is how its setup on GA

vsitesearch.png

 

 

 

Our onsite search tool provider told us that we needed to send a 'virtual pageview' to google analytics to be able to pick up the queries.  So we tried that, which did help us see what queries are being searched, but in the pageview report form....  We want to be able to use the Behaviour>Search reports.

 

Any assistance is greatly appreciated.

 

Here's our GA custom code to send these virtual pageviews:

 

<script type="text/javascript">
 var enDom = 'staplescopyandprint.ca'; var frDom = 'copiesbureauengros.ca';
 var currHost = document.location.hostname; var trimmedHost = currHost.replace(/([a-zA-Z0-9]+.)/, "");
 var isNotSubDomain = (currHost == 'www.' + trimmedHost) || (currHost == trimmedHost);
 var _accInUse = ((enDom == trimmedHost) || (frDom == trimmedHost)) && isNotSubDomain ? 'UA-34383141-1' : 'UA-34383141-2';
 var _trackUrl = '/WebSearchResult.aspx/';
  
 if (_trackUrl == '/WebSearchResult.aspx/' && location.href.indexOf('?') >= 0)
 _trackUrl = '/WebSearchResult.aspx/#' + location.href.substring(location.href.indexOf('?'));
  
 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', _accInUse],
 ['_trackPageview', _trackUrl]
 );
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Dewey N
January 2017

On-Site Search reporting not working

Explorer ✭ ✭ ✭
# 5
Explorer ✭ ✭ ✭

I've made some test with my toy account and it looks as if it works when page path does not contain hash "#" and query parameter is wrapped with question sign and 'equals' signs such as '?search=".

Hope this will help

View solution in original post

On-Site Search reporting not working

Explorer ✭ ✭ ✭
# 2
Explorer ✭ ✭ ✭

Hi Dewey

Try to modify your code to omit hash symbol in the following line:
_trackUrl = '/WebSearchResult.aspx/' + location.href.substring(location.href.indexOf('?'));

On-Site Search reporting not working

Explorer ✭ ✭ ✭
# 3
Explorer ✭ ✭ ✭

Google Analytics usually does not recognize part of the URL following the hash '#' (so called URL fragment). So I suggest modifing your code to avoid hash in URL could help

On-Site Search reporting not working

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

your comment with the # makes sense, I will update the code and report back.  Bare with me as it may take some time before I provide you with an update Smiley Happy

Marked as Best Answer.
Solution
Accepted by topic author Dewey N
January 2017

On-Site Search reporting not working

Explorer ✭ ✭ ✭
# 5
Explorer ✭ ✭ ✭

I've made some test with my toy account and it looks as if it works when page path does not contain hash "#" and query parameter is wrapped with question sign and 'equals' signs such as '?search=".

Hope this will help

On-Site Search reporting not working

[ Edited ]
Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hi thank you so much. 

 

I should have noticed that the hash # was present. GA is picking up the terms after the word 'query' properly.


Thanks again!