How can I track internal search with JavaScript function?

When Piwik PRO tracks an internal search, it grabs a piece of a URL address with query parameters like q, query, s, search, searchword, and keyword. If you’re using different query parameters then you can add them to the internal search settings, and the tracking will work fine (Menu > Administration > Sites & apps > Select a site or app > Data collection > Keywords from your internal search engine). 

But in some cases, a URL address doesn’t store query parameters, and then you need to use a JavaScript function to record and send internal search data.

Note: You can also use this method to track a search category and count of search results.

To track internal search with JavaScript function, follow these steps:

  1. On the page with search results, before  _paq.push(['trackPageView']); use the following function:
  2. You may use variables in Tag Manager to capture each piece of information — keyword, category, and search count.
  3. If you have variables, add them to the function:

For developers: For more information about internal search tracking, read our developer guide.

Was this article helpful?

Technical support

If you still have any questions, visit our community.
There’s always someone happy to help!

Related articles

Back to help center