Send a click event
Every time a user clicks on a search result, your application must send aclick event to the POST /events endpoint:
Required and recommended fields
| Field | Required | Description |
|---|---|---|
eventType | Yes | Must be "click" |
eventName | Yes | A descriptive label, such as "Search Result Clicked" |
indexUid | Yes | The index containing the clicked document |
userId | Yes | An arbitrary string identifying the user who clicked |
objectId | Recommended | The primary key of the clicked document |
position | Recommended | The document’s rank in the search results (starting from 0) |
queryUid | Recommended | The UID of the original search query |
objectName | Optional | A human-readable description of the document |
queryUid links the click event to the original search request. You can find it in the metadata field present in search query responses. Including it ensures Meilisearch correctly computes click-through rate and average click position.
Capture clicks in a frontend application
In a typical web application, you fire a click event when the user clicks on a search result link. Here is a JavaScript example:position parameter should match the document’s zero-based index in the results list.
Best practices
- Include
queryUidwhenever possible. Without it, Meilisearch cannot associate the click with a specific search query. - Use consistent user IDs. The same user should have the same
userIdacross searches and events so analytics can track their full journey. - Send events in real time. Batching click events or sending them with a delay reduces the accuracy of your analytics.
- Track position accurately. If your UI displays results across multiple pages, account for pagination offset when calculating the position value.
Next steps
Getting started with analytics
Set up click and conversion tracking from scratch
Events endpoint reference
Full reference for the
/events endpoint fields and behaviorTrack conversion events
Record when users complete a desired action after searching
Bind events to a user
Learn how to associate analytics events with specific users