Coveo V5 Analytics Error

If you get a 500 error on calls to /coveo/rest/v6/analytics/searches, then this post is for you. Here's a quick fix for this obscure Coveo Analytics Events error.


I ran into this with a Sitecore 9.1 project using Coveo V5. I was using the "Coveo Send Analytics to Sitecore" Hive component on my search pages.

When I browsed to a search page on the Content Delivery I noticed an error when inspecting with Chrome developer tools:

/coveo/rest/v6/analytics/searches - 500 application error

...and also several instances of...

Uncaught (in promise) Cancelling current pending query

After enabling debugging I browsed directly to the "searches" API to get a more detailed error message:

Server Error in '/' Application.
Precondition failed: The parameter 'p_SearchEvents' must not be null
Parameter name: p_SearchEvents
Description: An unhandled exception occurred.

Exception Details: System.ArgumentNullException: Precondition failed: The parameter 'p_SearchEvents' must not be null
Parameter name: p_SearchEvents

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentNullException: Precondition failed: The parameter 'p_SearchEvents' must not be null
Parameter name: p_SearchEvents]
Coveo.Framework.CNL.Precondition.NotNull(Object p_Parameter, String p_ParameterName) +208
Coveo.Framework.CNL.Precondition.NotEmpty(String p_Parameter, String p_ParameterName) +47
Coveo.UI.Rest.Controllers.AnalyticsController.Searches(String p_ApiVersion, String p_SearchEvents) +292
lambda_method(Closure , ControllerBase , Object[] ) +143
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +77
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0() +72
System.Web.Mvc.Async.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +387
System.Web.Mvc.Async.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +387
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__3() +50
System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult) +39


Analytics were clearly not working because of this error. I found this article on the Coveo support site which gave me something to try, and ultimately led me to a solution.

In the Coveo.Authentication.config file, you need to move the <site name="coveoapi" element so that it becomes the first child of the <sites> element, as follows:

  <!-- The site coveoapi needs to be inserted as the first element, or before any other sites that have the coveoapi site as a child (e.g. sites defined with virtualpath="/coveo*"). -->
  <site patch:before="*[1]" name="coveoapi" virtualFolder="/coveo" physicalFolder="/coveo" enableTracking="false" content="master" domain="sitecore" set:loginPage="$(loginPath)shell/SitecoreIdentityServer" />
  <site patch:before="*[1]" name="coveorest" virtualFolder="/coveo/rest" physicalFolder="/coveo/rest" enableTracking="false" database="web" domain="extranet" />
  <!-- The site coveoanalytics needs to be inserted before coveorest, as it requires analytics to be enabled. -->
  <!-- The coveoanalytics website database attribute value should match the published website database attribute value in order to allow Coveo Usage Analytics logging. -->
  <site patch:before="*[1]" name="coveoanalytics" virtualFolder="/coveo/rest/v6/analytics" enableTracking="true" database="web" domain="extranet" />
  <site patch:before="*[1]" name="coveo_website" virtualFolder="/sitecore modules/Web/Coveo" physicalFolder="/sitecore modules/Web/Coveo" rootPath="/sitecore/content" startItem="/home" language="en" content="web" domain="sitecore" loginPage="/identity/login/admin/SitecoreIdentityServer" />

After making this change everything started working properly.

Happy Sitecoring!





Add comment