I want to be able to track searches using the Site Search feature of Google Analytics but I’m a little unsure of how to set it up.
There are four URL formats used on my site for searching:
The initial search:
domain.com/module/search?q=terms
If you view a second page of search results:
domain.com/module/search/page/2/perPage/25/order/relevance/direction/DESC?q=terms
If you filter the results by a specific category:
domain.com/module/search/filter_category/the-category?q=terms
If you view a second page of search results with a category filter:
domain.com/module/search/filter_category/the-category/page/2/perPage/25/order/relevance/direction/DESC?q=terms
In Google Analytics when you select to track Site Search, it gives you a few options you have to (optionally) fill in.
-
Query Parameter - this would be “q” for me
-
Yes or No, strip query parameters out of URL - what does this mean?
-
Do you use categories for site search? - I optionally use categories (the category filter). Since it’s passed in the actual URL and not the query string, what would I enter here?
-
Yes or No, strip category parameters out of URL - again, what does this mean and what should I select?
Any help would be appreciated, thanks!
Ah, see your problem there is that you’ve constructed the URL wrong. That isn’t a file path, so you shouldn’t present it as one. What that should say is domain.com/search?q=terms&page=2&perPage=25&order=relevance&direction=desc. It’s a dynamic URL, fetching content from a database depending on the parameters, so you should present it as one. That way, Google will be able to handle it better, both in terms of analytics and in search results, because it can correctly understand how the URL is formed.
In terms of the analytics, it probably doesn’t matter what the page, perPage, order or direction parameters are, which is why it gives you the option to exclude them. Unfortunately because they look like part of the filepath rather than parameters here, that option is not going to work.
As a general rule, if you have a filepath made up of strings separated by / then you should be able to chop the URL off at any / and get a meaningful page out of it. That clearly isn’t going to be the case with the URLs you’ve given, which is the first clue that you’ve constructed them wrong.
I inherited the project as is and have not been authorized to re-code anything because it was originally “done wrong.” 
That’s often a problem when you’re left trying to make someone else’s cruddy code work 
I found a “work around” … I can just construct a virtual pageview for the search results pages in the form of
/module/search?q=terms&c=category&p=page
So I think that’ll work… so back to my original questions:
-
Query Parameter - this would be “q” for me
-
Yes or No, strip query parameters out of URL - what does this mean?
-
Do you use categories for site search? - yes
-
Yes or No, strip category parameters out of URL - again, what does this mean and what should I select?
In my virtual pageview scenario, q = search terms, c = category filter, and p = results page. Would I enter p in the category parameters or just c? What happens if you select “Yes” to strip out category paremeters?