Recording Custom Events with Sitecore Analytics
Recording Custom Events with Sitecore Analytics
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
- The Coveo events are being sent to Sitecore Analytics. See Configuring Coveo events in Sitecore Analytics
- You understand how to create custom Coveo Analytics events. See Send your own UA events).
Steps
- Create two custom Coveo Analytics events using the Coveo JavaScript Framework, such as:
- Facet Collapsed
- Facet Expanded
- Open the Sitecore Content Editor.
- Navigate to the
/sitecore/System/Settings/Analytics/Page Events/Coveo/Facets
folder. - Insert two new
Page Event
items in the folder:- Facet Collapsed
- Facet Expanded
- Publish the new
Page Event
items. - Open the
Coveo.UI.Controls.Custom.config
patch file, if you don’t ave this file yet, create it. -
In the file, add the following patch :
patch:before="[@type='Coveo.SearchProvider.Processors.TrackAnalyticsEventProcessor, Coveo.SearchProviderBase']"
-
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 }; } }
-
Create a patch file and add your processor to the
coveoAnalyticsPipeline
element, right before the processor of typeTrackAnalyticsEventProcessor
.<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>
- Open your Coveo-powered search page on the published site.
-
Validate that your custom events are tracked by expanding/collapsing any facet and querying the
PageEvents
table of your analytics database.-
In the xDB database (Sitecore 7.5+ instances), you should see:
-
In the Sitecore DMS (Sitecore 7.2 instances), you should see:
-