Track events in an external database

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 Platform relevance features with the Coveo Atomic library.

The analytics component automatically tracks the JS Search Framework events in the Sitecore Analytics module. However, you can alter this behavior and track the analytics into your own database, therefore bypassing the Sitecore Analytics module entirely. The current tutorial shows you how to override the default behavior and track events in an external database.

Steps

  1. Create a new C# class that inherits from the Coveo.Analytics.IEventTracker interface. This class is responsible for logging the analytics data in your external database.

     /// <summary>
     /// Tracks analytics events inside an external database.
     /// </summary>
     public class ExternalDatabaseTracker : IEventTracker
     {
         /// <summary>
         /// Gets whether the tracker is enabled. You could, for example, return the value of
         /// the enableTracking parameter for the coveoanalytics site instead of returning
         /// always true.
         /// </summary>
         public bool IsActive
         {
             get
             {
                 return true;
             }
         }
         /// <summary>
         /// Tracks the analytics data into the external database.
         /// </summary>
         /// <param name="p_EventData">The page event data.</param>
         public void Track(PageEventData p_EventData)
         {
             if (IsActive) {
                 // Insert your custom logic to insert the page event data into your external database.
             }
         }
     }
    • The event tracker is responsible for taking the PageEventData object and inserting it into your analytics database. In the Track method, you should open a connection with your database provider and insert the data contained in the PageEventData object into the appropriate table.

  2. Create a new C# class and add the following method. This processor is responsible for changing the default event tracker for the one you created in step 1.

     /// <summary>
     /// A <see cref="CoveoAnalyticsPipelineArgs"/> processor. This method is
     /// responsible for changing the default event tracker.
     /// </summary>
     /// <param name="p_Args">The <see cref="CoveoAnalyticsPipelineArgs"/>.</param>
     public void Process(CoveoAnalyticsPipelineArgs p_Args)
     {
         p_Args.EventTracker = new ExternalDatabaseTracker();
     }
  3. Open your Coveo.UI.Controls.Custom.config configuration file. If it doesn’t exist, create it. Add your processor in the <coveoAnalyticsPipeline> XML tag, right before the 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.CustomAnalyticsEventProcessor, CustomAnalyticsProcessing" />
    
       <processor mode="on" type="Coveo.SearchProvider.Processors.TrackAnalyticsEventProcessor, Coveo.SearchProviderBase" />
     </coveoAnalyticsPipeline>
    Note

    There are many other ways to define processors in configuration files. For example, you can define this processor in your own configuration file, as long as it’s located under the App_Config/Include directory of your website. See the All About Web.config Include Files with the Sitecore ASP.NET CMS article for more information.

  4. Browse to your Coveo-powered search page and perform a new query.

  5. Validate that the processor was executed correctly by querying your external database.