Skip to main content
Required ACL: search Sending multiple events in a batch can be useful when: You can include up to 1,000 events in a single request. When you’re sending historical events, make sure to set correct timestamps for all events, or else every event has the same timestamp. For sending real-time events, use the dedicated methods instead: For more information, see Get started with events.

Examples

The following example sends three events for the same user: one click event, one view event, and one conversion event. For more information about initializing the JavaScript Insights client aa, see Initialize the Insights client.
JavaScript
aa("sendEvents", [
  // `clickedObjectIDsAfterSearch`
  {
    userToken: "anonymous-123456",
    authenticatedUserToken: "user-123456",
    eventType: "click",
    eventName: "Example Clicked",
    index: "YourIndexName",
    queryID: "queryID",
    objectIDs: ["objectID-1", "objectID-2"],
    positions: [17, 19],
  },
  // `viewedObjectIDs`
  {
    userToken: "anonymous-123456",
    authenticatedUserToken: "user-123456",
    eventType: "view",
    eventName: "Example Viewed",
    index: "YourIndexName",
    objectIDs: ["objectID-1", "objectID-2"],
  },
  // `convertedObjectIDsAfterSearch`
  {
    userToken: "anonymous-123456",
    authenticatedUserToken: "user-123456",
    eventType: "conversion",
    eventSubtype: "purchase",
    eventName: "Example Converted",
    index: "YourIndexName",
    objectIDs: ["objectID-1", "objectID-2"],
    objectData: [
      {
        queryID: "object1-query",
        price: "1.50",
        quantity: 2,
      },
      {
        queryID: "object2-query",
        price: "2.00",
        quantity: 1,
      },
    ],
    value: 5.0,
    currency: "USD",
  },
]);

Parameters

events
object[]
required
An array of event objects
additionalParams
object
JavaScript only: Additional parameters for the search-insights library.Example:
JavaScript
aa(
  "sendEvents",
  [
    // …
  ],
  {
    headers: {
      "X-Algolia-Application-Id": "YourApplicationID",
      "X-Algolia-API-Key": "YourSearchOnlyAPIKey",
    },
    inferQueryID: true,
  },
);
discount
number | string
Absolute value of the discount in effect for this object, measured in currency.Must be a decimal number with no more than 16 characters (including non-digit characters).
price
number | string
The price of the item. This should be the final price, including any discounts.Must be a decimal number with no more than 16 characters (including non-digit characters).
quantity
number
The quantity of the purchased or added-to-cart item. The total value of a purchase is the sum of quantity multiplied by the price of each purchased item.
queryID
string
ID of the query that this specific record is attributable to. Used to track purchase events with multiple items originating from different searches.Objects without a query ID aren’t included in revenue analytics. For more information, see Revenue transactions.See also: Keep track of query IDs
I