Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google-Analytics API to track Site Search?

So there's this nifty _trackPageview() api method on a tracker object, but is there a corresponding method that can be used to manually track a search? In other words, _trackPageview() reports to GA that a user hit a page. I want something like _trackSearch("terms") that would report to GA that a user searched for something.

like image 355
Mike Caron Avatar asked Dec 30 '09 22:12

Mike Caron


People also ask

How do I use Google Analytics to search a website?

Click Admin, and navigate to the view in which you want to set up Site Search. In the View column, click View Settings. Under Site Search Settings, set Site Search Tracking to ON. In the Query Parameter field, enter the word or words that designate internal query parameters, such as term,search,query,keywords.

Can I use Google Analytics to track other websites?

When you have multiple websites to track, you can use a single account to add multiple sites in Google Analytics, which can be done in two ways. You can either add all your sites under a single Analytics account as different properties or add a unique Analytics account ID to each individual site.


1 Answers

Though not exactly what I was looking for, it seems that one can generate virtual page views to track search results programatically.

Suppose that you've set up a Site Search parameter called "q", so that when a URI is tracked that contains q=these+are+some+terms, GA will mark it as a search hit. One can use the _trackPageview() method to generate virtual search hits like so:

pageTracker._trackPageview('/custom/search?q=These+are+some+terms')
like image 124
Mike Caron Avatar answered Oct 18 '22 07:10

Mike Caron