You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, Meilisearch uses IP addresses to identify users and calculate the total user metrics. This guide shows you how to use the `X-MS-USER-ID` HTTP header to manually link analytics events to specific users.
11
-
12
-
This is useful if you're searching from your back end, as all searches would otherwise appear to come from your server's IP address, making it difficult to accurately track the number of individual users.
10
+
This guide shows you how to to manually link analytics events to specific users.
13
11
14
12
## Requirements
15
13
16
-
- A Meilisearch Cloud project with analytics and monitoring enabled
17
-
- A working pipeline for submitting analytics events
14
+
- A Meilisearch Cloud project
15
+
- A method for identifying users
16
+
- A pipeline for submitting analytics events
18
17
19
-
## Add `X-MS-USER-ID`to your search query
18
+
## Assign user IDs to search requests
20
19
21
-
Include the `X-MS-USER-ID` header in your search requests:
20
+
You can assign user IDs to search requests by including an `X-MS-USER-ID` header with your query:
22
21
23
22
<CodeSamplesAnalyticsEventBindSearch1 />
24
23
25
-
Replace `MEILISEARCH_USER_ID` with any value that uniquely identifies that user. This may be an authenticated user's ID when running searches from your own back end, or a hash of the user's IP address.
24
+
Replace `SEARCH_USER_ID` with any value that uniquely identifies that user. This may be an authenticated user's ID when running searches from your own back end, or a hash of the user's IP address.
25
+
26
+
<Note>
27
+
Assigning user IDs to search requests is optional. If a Meilisearch Cloud search request does not have an ID, Meilisearch will automaticalle generate one.
28
+
</Note>
26
29
27
-
## Add `X-MS-USER-ID`to the analytics event
30
+
## Assign user IDs to analytics events
28
31
29
-
Next, submit your analytics event to the analytics endpoint. Send the same header and value in your API call:
32
+
You can assign a user ID to analytics `/events` in two ways: HTTP headers or including it in the event payload.
33
+
34
+
If using HTTP headers, include an `X-MS-USER-ID` header with your query:
30
35
31
36
<CodeSamplesAnalyticsEventBindEvent1 />
32
37
38
+
If you prefer to the event in your payload, include a `userId` field with your request:
39
+
40
+
<CodeSamplesAnalyticsEventBindEvent2 />
41
+
42
+
Replace `SEARCH_USER_ID` with any value that uniquely identifies that user. This may be an authenticated user's ID when running searches from your own back end, or a hash of the user's IP address.
43
+
44
+
<Warning>
45
+
It is mandatory to specify a user ID when sending analytics events.
46
+
</Warning>
47
+
33
48
## Conclusion
34
49
35
-
In this guide you have seen how to bind analytics events to specific users by specifying the same HTTP header for both the search request and the analytics event.
50
+
In this guide you have seen how to bind analytics events to specific users by specifying an HTTP header for the search request, and either an HTTP header or a `userId` field for the analytics event.
This reference describes `/events`, the endpoint you should use to submit analytics events to Meilisearch Cloud. It also describes the accepted event objects and the data you must include in them.
9
+
Use `/events`to submit analytics events such as `click`and `conversion` to Meilisearch Cloud.
10
10
11
-
## The `/events` endpoint
11
+
## Send an event
12
12
13
-
The `/events` endpoint is only available for Meilisearch Cloud projects with analytics and monitoring activated.
13
+
<RouteHighlightermethod="POST"path="/events" />
14
14
15
-
### Send an event
15
+
Send an analytics event to Meilisearch Cloud.
16
16
17
-
```http
18
-
POST https://edge.meilisearch.com/events
19
-
```
20
-
21
-
Send an analytics event to Meilisearch Cloud. Accepts [`click`](#the-click-event-object) and [`conversion`](#the-conversion-event-object) events.
22
-
23
-
<Tip>
24
-
By default, Meilisearch associates analytics events with the most recent search of the user who triggered them. Include the same `X-MS-USER-ID` header in your search and event requests to manually [bind analytics events to a user](/learn/analytics/bind_events_user).
25
-
</Tip>
26
-
27
-
#### Example
28
-
29
-
<CodeSamplesAnalyticsEventClick />
30
-
31
-
##### Response: `201 Created`
32
-
33
-
### The `click` event object
17
+
### Body
34
18
35
-
The `click` event must deliver an object with the following fields:
0 commit comments