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 > Websites & apps > Select a website or an app > Settings > Internal search engine tracking). 

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. _paq.push(['trackSiteSearch','keyword','category','search_count']);
  3. You may use variables in Tag Manager to capture each piece of information — keyword, category, and search count.
  4. If you have variables, add them to the function:
_paq.push(['trackSiteSearch',{keyword_variable},{category_variable},{search_count_variable}]);
Was this article helpful?

Technical Support

If you have any questions, drop us a line at support_SPC@piwik_SPC.pro.

We’re happy to help!