Piwik: Tracking Search Suggestions

Hello All,

I’m trying to figure out how to track search suggestions as search actions in Piwik. I have managed to do this for the standard search, but can’t figure out what page needs to hold the tracking script for the suggestions (is this loaded uing AJAX?)

Tried googleing a bit but only found this page: analytics - How to track searches in piwik? - Stack Overflow

Can anyone point me to the page that performs this action?

Unless I don’t understand what you are asking I explained on Piwik Edit Tracking Script? - #4 by tmortagne where is the tracking code located on XWiki side.

So, this is slightly different. I’m wanting to take advantage of the site search tracking provided by Piwik. It does a decent job out of the box once I configured it to detect the “text=” string part of the query. However, this only logs searches returned from a “full search”, and I’ve noticed that lots of people click on the results generated by the search suggest feature but this isn’t being logged.

To solve this I believe I need to use the trackSiteSearch function somehow in the call to SuggestSolrService.

Maybe an onmouseclick event like this but using the trackSiteSearch function. As you can probably tell, I don’t really understand asynchronous requests, etc.

OK I understand now.

I’m really not the best one to answer that question technically but few things:

  • it’s not really one search but the first results of several searches (search for users, search for documents names, etc.)
  • it’s indeed coming from an ajax request

Yes, multiple AJAX requests for the page/URL configured in the search suggest source (each search suggest source can use a different service). But most of them use SuggestSolrService as you noted. The URL is like

/xwiki/bin/get/XWiki/SuggestSolrService?query=<advancedSearchParams>&nb=3&outputSyntax=plain&input=wiki

So the typed text is passed in input=wiki.

@mflorea,

I’ve added input as a parameter to look for in URLs but I can’t seem to get Matomo to track AJAX requests even though I’m using _paq.push(['enableLinkTracking']);. I’m not convinced it’s detecting the input string as it’s of a different form to the full search URLs ?text parameter.

If I was to use the below function instead, is there a way to pass the query keywords in? What about the number of returned results?

_paq.push(['trackSiteSearch',
    // Search keyword searched for
    "Banana",
    // Search category selected in your search engine. If you do not need this, set to false
    "Organic Food",
    // Number of results on the Search results page. Zero indicates a 'No Result Search Keyword'. Set to false if you don't know
    0
]);

// We recommend not to call trackPageView() on the Site Search Result page
// _paq.push(['trackPageView']);

Thanks,
Ben

I don’t see any dedicated event for this but you can probably use Prototype v1.7.3 API documentation | Ajax.Responders to catch the AJAX requests that are being sent using Prototype.js (which is used by the search suggest), filter those coming from the search suggest and extract the search keywords from the request parameters.

You could listen to xwiki:suggest:updated and count the results in the DOM. See https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/uicomponents/suggest/suggest.js#L656 .

Thanks Marius, I’ll see what I can cook up. If I get something working I’ll create a pull request.