Daniel
Daniel

Reputation: 349

How to write a Google Analytics filter to record site searches

I what to record all my website searches with google analytics but the problem is my search links look like this

**www.mywebsite.com/search/category/your+query+here**

From what i found out i must give GA the query parameter (mywebsite.com/search.php?q=your+query+here) but i have none (and don't want any).

Is there a way to rewrite the URL with a google analytics filter? If yes how.

Upvotes: 0

Views: 852

Answers (3)

Jamie
Jamie

Reputation: 816

I know this is old, but to expand on the prev accepted answer, use a 'virtual url' in the _trackPageview call, so for www.mywebsite.com/search/category/your+query+here have

gat._trackPageview( "/search/content/your+query+here?query=your+query+here&cat=category" )

This means that URLs won't be changed, so everything else works (as noted in the previous answer) - if you really want to you could remove the search params, but unless you're running into a URL limit I'd probably prefer to keep them present so they can be seen in the content reports.

Upvotes: 0

user202865
user202865

Reputation: 26

Site Search is processed BEFORE Filters are applied.

I went through a week of testing to realize this. Yes, the Filter logic is correct, but as of Nov 1, 2009 this will not work with Site Search.

We accomplished this by appeding the ?search= parameter to the page URI in the GA script. Then we strip search params in the Profile Settings and we get the pure URI's in the content section as well as the Searches tracked in Site Search.

Upvotes: 1

viam0Zah
viam0Zah

Reputation: 26312

Yes, you can create a custom filter that rewrites URL /search/<category>/<query> to ?q=<query>&c=<category>.

Go to Analytics Settings › Filter Manager, and click Add Filter. Choose Custom Filter in the Filter Type drop-down list, select Search and Replace radio button, and then set two Request URI fields with the corresponding values. For further details, see ’How do I create a filter?’ page in Google Analytics Help Center.

Keep in mind! Since past visitor data cannot be reprocessed, always keep a ’raw’ profile that you do not apply filters against. For further details, see chapter ’Best Practices for Filters & Profiles’ in presentation ’Filters in Google Analytics’.

Upvotes: 3

Related Questions