views:

270

answers:

3

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.

+3  A: 

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’.

Török Gábor
i actually did exactly that. but even if the final url looks like this www.mysite.com/search.php?query=something they don;t appear as searches. and i did configure the website profile with the search parameter. any
Daniel
+1  A: 

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.

can you please give me more info about the appending tot he GA script? How does the script look? thank you very much :)
Daniel
A: 

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.

Jamie