Capture click events
Capture click events
This is for:
Developer
The Event Protocol and Relay library are currently in early access. If you’re interested in using the Event Protocol and Relay library, reach out to your Customer Success Manager (CSM). |
This article explains how to capture click events and send the information to Coveo Usage Analytics (Coveo UA) using the Relay library.
When to capture a click event
A click event should be captured when a visitor clicks a product from a search results page, Product Listing Page (PLP), or a recommendations carousel. Tracking click events is a requirement for Coveo Machine Learning (Coveo ML) and usage analytics reporting.
Capture a click event using Relay
When a user clicks on a product, you can run the following code to capture the click event and send the information to Coveo UA.
const relay = createRelay({...});
relay.emit('ec.productClick', {
currency: 'USD',
position: 1,
responseId: '35009a79-1a05-49d7-b876-2b884d0f825b',
product: {
productId: 'SP03929_00014',
name: 'Blue Bottle',
price: 16,
},
});
Initialize a Relay instance. | |
Use the emit function to send an event with Relay, specifying the event name.
In this example, the value is ec.productClick since it’s tracking a click event. |
|
Include the necessary event data, as outlined in the reference documentation. |
For a detailed description of the functions offered by the library, see the Relay documentation.
Note
When sending events with Relay, you don’t need to include the |
Validating the click event
It’s important to verify that your event is valid and contains the correct payload. Relay seamlessly integrates with Coveo Explorer, which can be used for event validation.
For more details on using Coveo Explorer to validate events, see Validating events.