Gravatar for christian.rikong@agencyq.com

Question by crikong, Dec 13, 2016 12:09 PM

Queries Done Via Coveo REST API not being reported in Coveo Admin Panel

Hey There,

I have a very quick question. Today I was testing out the Coveo REST API; more specifically the search function. I was able to get the searches up and running and get results using the API, however, I noticed that the Queries Count in my Analytics Page (in Coveo Admin) was not updating. My questions are the following:

1) Are queries done via the API logged automatically into Coveo Analytics or Do I have to log the search myself ?

2) If yes Are the queries being logged in real time or is there a delay between the time I do a query via the API and the time the Analytics report it back to me ?

1 Reply
Gravatar for sbelzile@coveo.com

Answer by Sébastien Belzile, Dec 13, 2016 12:33 PM

Are queries done via the API logged automatically into Coveo Analytics or Do I have to log the search myself?

The REST API itself does not log to Coveo Analytics. The JS framework contains the logic to send the UA event on query success or failure. If you use the REST API directly, you need to implement this yourself. Since you tagged Coveo for Sitecore, I suppose you are coding your interface via LINQ? The need to implement UA events logging is one of the many reasons why using LINQ with Coveo is not the recommended way to proceed when implementing your search interfaces.

If yes Are the queries being logged in real time or is there a delay between the time I do a query via the API and the time the Analytics report it back to me ?

No, there will be a delay of max 15 mins.

Gravatar for christian.rikong@agencyq.com

Comment by crikong, Dec 13, 2016 12:47 PM

Hi sbezile,

Thank you for taking the time to answer my question. I really appreciate it. Basically I am writing a C# script that is trying to feed a list of specific keywords to Coveo so that it could suggest them to users.

From what I have read (https://onlinehelp.coveo.com/en/cloud/aboutusageanalyticsservicequery_suggestions.htm) a query has to be performed 5 times, have a result that has been clicked at least once for it to be considered a suggestion.

So basically my script is simply going through my keywords list, perform 5 searches on each of them and record a click event (on one of the search results returned by Coveo) using the analytics service click method (https://usageanalytics.coveo.com/rest/v15/analytics/click). However, the search is not being recorded automatically and the clicks neither.

However, I have found that I can also record a search via the REST API by using the search call and passing a custom JSON object like the following (please ignore the + it is from code):

@"{" + "\"language\": \"" + Language + "\"," + "\"userAgent\": \"" + UserAgent + "\"," + "\"customData\":" + CustomDataJSON + "," + "\"anonymous\":" + Anonymous.ToString().ToLower().Trim() + "," + "\"username\":\"" + Username + "\"," + "\"userDisplayName\":\"" + UserDisplayName + "\"," + "\"splitTestRunName\":\"" + SplitTestRunName + "\"," + "\"splitTestRunVersion\":\"" + SplitTestRunVersion + "\"," + "\"originLevel1\":\"" + OriginLevel1 + "\"," + "\"originLevel2\":\"" + OriginLevel2 + "\"," + "\"originLevel3\":\"" + OriginLevel3 + "\"," + "\"searchQueryUid\":\"" + SearchQueryUId + "\"," + "\"queryText\": \"" + QueryText + "\"," + "\"actionCause\": \"" + ActionCause + "\"," + "\"advancedQuery\": \"" + AdvancedQuery + "\"," + "\"numberOfResults\":" + NumberOfResults + "," + "\"contextual\":" + Contextual.ToString().ToLower().Trim() + "," + "\"responseTime\":" + ResponseTime + "," + "\"results\": " + DocumentResultsJSON + "," + "\"queryPipeline\": \"" + QueryPipeLine + "\"," + "\"userGroups\": " + UserGroups + "" +

"}";

My first question is does my approach makes sense for what I am trying to accomplish ? The second is do you have a better suggestion :) ? Thank you again for your time and your help. Take Care.

Sincerely, Christian

Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Dec 13, 2016 12:54 PM

Your approach is almost correct: the search in itself does not matter. What matters is your UA data. If you want to influence your suggestions, your script does not need to perform a search query, it needs to log one. You can do so via the /searches call.

Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Dec 13, 2016 1:08 PM

I would like to raise a flag here. This is not the best way to proceed. By doing this, you will destroy part of your index relevancy by polluting your analytics data.

A better approach, would be to configure Featured Results on your query pipeline.

Gravatar for christian.rikong@agencyq.com

Comment by crikong, Dec 13, 2016 3:18 PM

Thank you sbelzile for your prompt answers. I really appreciate it. I find this article here: https://developers.coveo.com/display/public/SitecoreV3/Add+Query+Suggestions+to+Your+Search+Box

It almost does what I need but the problem is that the ToCoveoFieldName seems not to be in the SitecoreUtilities name space and the following code throws an error

" data-header-title="Suggested Queries">

. Any idea if the method still exists in the new Coveo packages for stirecore (8.0.450) ? . If yes any idea where to find it ?

Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Dec 13, 2016 3:31 PM

No, SitecoreUtilities.ToCoveoFieldName has been removed from C4SC with version 4.0. Coveo for Sitecore 4.0.450 has this a client side field name translator you could use instead: https://developers.coveo.com/display/public/SitecoreV4/Coveo+Fields+Resources+Component .

TopFieldsSuggestions has changed a lot between JS UI 0.9 and V1. Use the V1 doc: https://coveo.github.io/search-ui/components/fieldsuggestions.html. headerTitle is not available with the default Coveo theme.

Gravatar for christian.rikong@agencyq.com

Comment by crikong, Dec 13, 2016 4:19 PM

Hey sbelzile,

Thank you for the update. I have indeed replaced Sitecore.Utilities.ToCoveoFieldName with simply ToCoveoFieldName. Thank you for the pointer. However, even after following the tutorial, I am not seeing my keywords being pulled as suggestions. Anything I am doing wrong

Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Dec 13, 2016 4:22 PM

You do display an omnibox component? (data-omnibox="true"?)

Do you see a query being launched in your browser dev tools?

Gravatar for christian.rikong@agencyq.com

Comment by crikong, Dec 13, 2016 4:34 PM

Hey sbelzile, thank you so much for your prompt feedback. Indeed I see the querysuggest being called but the completions Array that is returned is empty which is kind of weird since I have keywords in the folder. The only thing I did not follow to the letter in the tutorial id the location of the folder Auto Suggestion Keywords but that shouldn't matter normally unless I am missing something :(

Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Dec 14, 2016 7:58 AM

Your items are indexed?

Are they excluded by your query?

Ask a question