How can I track internal searches with JavaScript function?

Piwik PRO records keywords from internal searches by checking the URL address. If the address has query parameters such as q, query, s, search, searchword or custom, Piwik PRO logs the keywords used in searches.

But, if your URLs don’t store query parameters, you can use a JavaScript function to capture internal search data.

To track internal searches with a JavaScript function, follow these steps:

  1. On the search results page, add the function below just before _paq.push(['trackPageView']);.
    _paq.push(['trackSiteSearch','keyword','category','search_count']);
  2. You can use variables in Tag Manager to record keywords, categories and search counts. If you use them, add them to your JavaScript functions like this:
    _paq.push(['trackSiteSearch',{keyword_variable},{category_variable},{search_count_variable}]);

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

Note: You can add custom query parameters in Menu > Administration > Sites & apps > Data collection > Keywords from your internal search engine.

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