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).
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.
How to capture a click event
Capturing a click event depends on your implementation approach.
-
If you’re using Headless, capture the event using the Headless controllers.
-
If you’re not using Headless, use the Relay library directly to capture the event.
Capture a click event using Headless
If you’re using the Headless library, you can capture a click event by using the InteractiveProduct
sub-controller for the solution you’re building.
For more details, see Displaying Products.
Capture a click event using Relay
If you’re using Relay library directly, 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.
For 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.