Send an event

Send an analytics event to Meilisearch.

Body

Name Type Required Description
eventType String Yes The event type: "click" or "conversion"
eventName String Yes A descriptive label for the event
indexUid String Yes The index containing the document the user interacted with
userId String Yes An arbitrary string identifying the user who performed the action
queryUid String Recommended The search query’s UID. Links the event to a specific search query
objectId String Recommended The document’s primary key value
position Integer Recommended The document’s position in the search result list (0-based). Only relevant for click events
objectName String No A human-readable description of the document
{
  "eventType": "click",
  "eventName": "Search Result Clicked",
  "indexUid": "products",
  "objectId": "0",
  "position": 0
}

You must provide a string identifying your user if you want Meilisearch to track conversion and click events. You may do that in two ways:

  • Specify the user ID in the payload, using the userId field
  • Specify the user ID with the X-MS-USER-ID header with your /events and search requests

Example

cURL

curl \
  -X POST 'https://PROJECT_URL/events' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer DEFAULT_SEARCH_API_KEY' \
  --data-binary '{
    "eventType": "click",
    "eventName": "Search Result Clicked",
    "indexUid": "products",
    "userId": "SEARCH_USER_ID",
    "queryUid": "019a01b7-a1c2-7782-a410-bb1274c81393",
    "objectId": "0",
    "objectName": "DOCUMENT_DESCRIPTION",
    "position": 0
  }'
Response: 201 Created

Next steps

Get started with analytics \ \ Set up analytics and start collecting search data.

Bind events to a user \ \ Associate analytics events with specific users for accurate tracking.

Track click events \ \ Configure your application to send click events to Meilisearch.