Log view events with EP
Log view events with EP
This is for:
DeveloperYou can use Headless controllers to handle Search API requests and leverage Coveo Usage Analytics (Coveo UA). Headless-powered search UI components can automatically click events for user interactions in your search interfaces. These events let you track user interactions with your search interfaces so that you can optimize your Coveo solution. Search and click events provide the data to power most Coveo Machine Learning (Coveo ML) models, except for Content Recommendations (CR).
The output of a CR model depends on view events and the user’s action history. Headless doesn’t log these events for you, so you should ensure that you’re sending view events for each page that you want to be able to recommend.
The Relay library, which is included in Headless, lets you send EP view events to Coveo.
Leading practice
Start sending view events as soon as you can to gather data that your CR models can learn from. |
Send view events with Relay
Use the relay.emit
function on your Engine to send events to Coveo.
The emit
function accepts two parameters: the event type and the event payload.
The event type is the string
name of the event, in this case itemView
, and the event payload is a JSON object containing the data to be sent to Coveo.
export const searchEngine = buildSearchEngine({
configuration: {
// ...
analytics: {
trackingId: "sports",
analyticsMode: "next",
},
},
});
searchEngine.relay.emit('itemView', {
itemMetadata: {
uniqueFieldName: "permanentid",
uniqueFieldValue: "kayak-paddle-01",
author: "Barca Sports",
url: "https://www.mydomain.com/l/products/kayak-paddle-01",
title: "Bamboo Kayak Paddle"
},
});
Pass in the name of the event as the first parameter of the emit function. |
|
Pass in the event payload required for the itemview event.
No need to send the meta object, as it’s automatically handled by Relay. |
You can also use the Relay library directly to log view events on pages you want to be able to recommend but on which you don’t use Headless. See the Relay library documentation.