Record Custom Events

In this article
Warning
Legacy feature

This article pertains to achieving relevance with the Coveo Hive framework. Coveo Hive is now in maintenance mode.

See Achieve relevance for guidance on leveraging Coveo relevance features with the Coveo Atomic library.

The analytics component logs the most common analytics events related to the search interface. However, there may be no analytics event for some user actions. For example, collapsing or expanding a facet doesn’t trigger any analytics event. The analytics component provides custom events to handle such cases. The current tutorial shows you how to handle specific user actions and log custom events for each of them in the analytics database.

Requirements

  1. The Coveo events are being sent to Sitecore Analytics (see Configure Coveo Events in Sitecore Analytics).

  2. You understand how to create custom Coveo Analytics events (see Send your own UA events).

Steps

  1. Create two custom Coveo Analytics events using the Coveo JavaScript Framework, such as:

    • Facet Collapsed

    • Facet Expanded

  2. Open the Sitecore Content Editor.

  3. Navigate to the /sitecore/System/Settings/Analytics/Page Events/Coveo/Facets folder.

  4. Insert two new Page Event items in the folder:

    • Facet Collapsed

    • Facet Expanded

    37555655
  5. Publish the new Page Event items.

  6. Open the Coveo.UI.Controls.Custom.config patch file, if you don’t have this file yet, create it.

  7. In the file, add the following patch : patch:before="[@type='Coveo.SearchProvider.Processors.TrackAnalyticsEventProcessor, Coveo.SearchProviderBase']"

  8. Create a new C# class and add the following code to track your custom events.

     public class CustomEventHandlerProcessor : Coveo.SearchProvider.Processors.HandleCustomEventProcessor
     {
       protected override void HandleCustomEvent(CoveoAnalyticsPipelineArgs p_Args, CustomEvent p_CustomEvent)
       {
         p_Args.EventData = new PageEventData(p_CustomEvent.ActionType) {
           DataKey = p_CustomEvent.ActionType,
           Data = p_CustomEvent.ActionCause,
           ItemId = p_CustomEvent.SitecoreItemId
         };
       }
     }
  9. Create a patch file and add your processor to the coveoAnalyticsPipeline element, right before the processor of type TrackAnalyticsEventProcessor.

     <coveoAnalyticsPipeline>
       <processor mode="on" type="Coveo.SearchProvider.Processors.HandleSearchEventProcessor, Coveo.SearchProviderBase" />
       <processor mode="on" type="Coveo.SearchProvider.Processors.HandleDocumentViewEventProcessor, Coveo.SearchProviderBase" />
    
       <!-- Our custom analytics processor is defined here -->
       <processor mode="on" type="CustomAnalyticsProcessing.CustomEventHandlerProcessor, CustomAnalyticsProcessing" />
    
       <processor mode="on" type="Coveo.SearchProvider.Processors.TrackAnalyticsEventProcessor, Coveo.SearchProviderBase" />
     </coveoAnalyticsPipeline>
  10. Open your Coveo-powered search page on the published site.

  11. Validate that your custom events are tracked by expanding/collapsing any facet and querying the PageEvents table of your xDB database. You should see:

    38142193