Track Events
The Track Events API is used to capture a user's interaction following a query, such as impressions, clicking on a search result, or adding an item to a cart.
Event Flow
The following sequence diagram illustrates the typical flow for tracking events:
In the diagram above,
Steps 1–6 are the typical flow for tracking queries.
Steps 7–12 illustrate the event flow for capturing four events:
- Search Result impressions presented to the user.
- A click on a search result
- A search result is added to the cart.
- The cart is checked out.
Steps 7, 8, and 9 are sent from the user's browser using JavaScript included in the page. Step 11 is sent from the Application server-side.
Events can be sent from client-side, server-side, or from both, from your application.
Event specification
The OpenAPI specification contains the JSON schema for the event type,
Event for the REST API.
The User Behavior Insights proto contains the proto messages for
the gRPC API: TrackEventsRequest and TrackEventsResponse.
The schema follows Version 1.3.0 of the UBI specification.
Example
The track event API accepts an array of events in a single request. A single event is sent as an array of one.
Here's an example request to the track event API:
{
"events": [
{
"application": "primary-search",
"action_name": "click",
"query_id": "01JE0VKZF8G03G7X16EDE6WNKJ",
"session_id": "01JE0VM6029EVZT2SGHN1VYNAS",
"client_id": "search_service",
"timestamp": "2024-12-01T00:00:00.0000000Z",
"user_query": "men's warm winter coat",
"event_attributes": {
"object": {
"object_id": "sku001",
"object_id_field": "sku"
},
"position": {
"ordinal": 1
}
}
}
]
}