Analytics
5.1K members online now
5.1K 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

Site Search for Post-based search result

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I've search option in my website which shows result in POST based query. So, there is no url string generating in search result. ie. mywebsite.com/search_result.php

 

Now, I want to set Site Search in my Google Analytics. The solution from Analytics help in https://support.google.com/analytics/answer/1012264 suggests:

Setting Up Site Search for POST-Based Search Engines

If you're using a POST-based search engine, the your-search-results URL would look something like:

http://www.yoursite.com/search_results.php

 

You have two options to use Site Search for POST-based search engines:

Option 1: Configure your web application to append the query keywords to the end of the URL (e.g., http://www.yoursite.com/search_results.php?q=keyword) and then set up Site Search as described in the previous section.

Option 2: Customize the tracking code on your results page to dynamically specify a virtual page path that includes the query keywords. The tracking code on the results page would look something like:

analytics.js: ga('send', 'pageview', '/search_results.php?q=keyword');

 

 

I can not use option 1 and I'm not getting what option 2 exactly means. If someone can explain it to me, it'd be great. I understood that q is the query string name passed in POST but what is keyword?

 

Thanks in advance Smiley Happy

Re: Site Search for Post-based search result

Follower ✭ ✭ ✭
# 2
Follower ✭ ✭ ✭
Hello

q is the query string and keyword is what someone search on the site for.

So presume I come to your site and search for "cat videos"
In this case you need to configure your code to output the following code:
analytics.js: ga('send', 'pageview', '/search_results.php?q=cat videos');

So the keyword is the actual query someone typed in your site search.

Re: Site Search for Post-based search result

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
So, you mean that I've to set my analytics code as

analytics.js: ga('send', 'pageview', '/search_results.php?q=<?php echo $_POST["q"]?>');

Right?