Tracking of internal Drupal search using Google Analytics is problematic. Drupal URL after
search has a form like
/search/node/query+term. Google Analytics cannot parse
this URL and obtain a query term. That That is the reason for it is advisable to change the
URL and track a virtual pageview in format
/search?q=query-term - this
format is acceptable for Google Analytics
In addition, if a function which returns the number of search results is defined, searched term and result count will be automatically tracked as event. You can trace easily frequently searched terms for which site search does not find any results.
It is needed to create a route and add it to
addRoute method. Creating a route might look like this:
Route constructor has two optional parameters.
_trackPageviewis sent. Function is executed only once even if more trackers are created.