Being able to track search queries in Drupal can give you valuable insight into what your users want or need.
Let’s say for example your website only sells red bicycles, but you notice that users are always searching for yellow bicycles. This type of insight into what your users are searching for can be very useful.
In Drupal there are a few modules that can help you track keywords used on a search page. In this article, you’ll learn about a few of these modules and how to track searches using just Google Analytics
“Top search phrases” Page
Drupal out of the box already does some level of search tracking. As long as you’re using the core Search module; you can see the most popular search phrases by going to Report -> “Top search phrases”.
But be careful, this is not a good solution for long-term search logging. The data used on this page comes from the watchdog table (or database log). Drupal by default only keeps a certain amount of log messages in the watchdog table. So use this page to find out the “most recent” top search phrases and understand that the phrases will change depending on how long you keep the watchdog data.
Search Log Module
The Search Log module offers search logging for the core Search module or any module that implements the
hook_search_info() hook. The module stores the log data in its own table, however, it allows you to clear out the logs from its adminstration page (Configuration -> “Search log”).
You can also configure the module to keep logs only for a certain amount of days. By default, it’s set to
0 which means it’ll keep the logs indefinitely.
The module also has a pretty cool dashboard that allows you to view all the logs and filter them by date. Just go to Reports -> “Top search terms”.
If you install the Google chart API module you also get some fancy charts on the page.
The module ships with a basic report page called “Zeitgeist report”. You can access it by going to Reports -> “Top search phrases” and click on the “Zeitgeist report” tab.
The module has a fairly comprehensive configuration page where you can configure the reports page and its custom blocks. Similar to Search Log, you can define how long the logs should be kept for, by default it’s set to indefinitely.
To configure the module, just go to Configuration -> “Search settings” and click on the “Zeitgeist settings” tab.
If you’re using Drupal’s core Search module and the Google Analytics module, then go to Configuration -> “Google Analytics”, click on the “Search and Advertisting” vertical tab and check the “Track internal search” checkbox.
But you’ll also need to setup your GA profile to track site searches, go to this page for more details.
If you’re not using the core Search module, then you can have GA track site searches by defining a “Query parameter”. You configure all of this in the web application, not inside of the module.
For example, the search page on Web Wash is
/search?search=views. The query parameter in this case is
search, so all I did was define
search as a query parameter and now GA tracks any parameter like
Go to the Set up and configure Site Search page for more details.
As with most things in Drupal you have a few options. If you’re using the core Search module and you want to view the logs within Drupal then look at Search Log or Zeitgeist. However, understand that both of these modules only work with the core Search module.