Send events
This is documentation for v3 of the PHP API clients, which is not the latest version. To see the documentation for the latest version, see PHP v4.
This is documentation for v2 of the Ruby API clients, which is not the latest version. To see the documentation for the latest version, see Ruby v3.
This is documentation for v4 of the JavaScript API clients, which is not the latest version. To see the documentation for the latest version, see JavaScript v5.
This is documentation for v3 of the Python API clients, which is not the latest version. To see the documentation for the latest version, see Python v4.
This is documentation for v8 of the Swift API clients, which is not the latest version. To see the documentation for the latest version, see Swift v9.
This is documentation for v2 of the Kotlin API clients, which is not the latest version. To see the documentation for the latest version, see Kotlin v3.
This is documentation for v6 of the C# API clients, which is not the latest version. To see the documentation for the latest version, see C# v7.
This is documentation for v3 of the Java API clients, which is not the latest version. To see the documentation for the latest version, see Java v4.
This is documentation for v3 of the Go API clients, which is not the latest version. To see the documentation for the latest version, see Go v4.
This is documentation for v1 of the Scala API clients, which is not the latest version. To see the documentation for the latest version, see Scala v2.
Required API Key:
any key with the
search
ACL
You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.
About this method
Send a list of events in a single request.
Sending multiple events in a batch can be useful when:
- Importing historical data
- Sending events from your backend,
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 will have the same timestamp.
For sending real-time events, use the dedicated methods instead:
Examples
Read the Algolia CLI documentation for more information.
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 Insights client aa
,
see Initialize the Insights client.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$insights = Algolia\AlgoliaSearch\InsightsClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$response = $insights->sendEvents(array(
// `clickedObjectIDsAfterSearch`
array(
'eventType' => 'click',
'eventName' => 'Example Clicked',
'index' => 'YourIndexName',
'userToken' => 'user-123456',
'objectIDs' => array('objectID-1', 'objectID-2'),
'timestamp' => 1733148214403,
'queryID' => 'queryID'
),
// `viewedObjectIDs`
array(
'eventType' => 'view',
'eventName' => 'Example Viewed',
'index' => 'YourIndexName',
'userToken' => 'user-123456',
'objectIDs' => array('objectID-1', 'objectID-2'),
'timestamp' => 1733148214403
),
// `convertedObjectIDsAfterSearch`
array(
'eventType' => 'conversion',
'eventName' => 'Example Converted',
'index' => 'YourIndexName',
'userToken' => 'user-123456',
'objectIDs' => array('objectID-1', 'objectID-2'),
'timestamp' => 1733148214403,
'queryID' => 'queryID'
),
)
);
Parameters
events
|
An array of event objects |
||
additionalParams
|
since: v2.4.0
type: { headers?: Record<string, string>, inferQueryID?: boolean }
default: undefined
Optional
Additional parameters to forward to the Insights library.
This lets multiple search clients use different credentials for each request,
or to infer the
Copy
|
events ➔ event
eventType
|
type: click | conversion | view
Required
Type of the event, either See also: Event types |
eventSubtype
|
type: addToCart | purchase
Optional
This parameter is only supported in the following languages: PHP, Ruby, JavaScript, Python, and Go. Subtype of the event. For Used to enable Algolia to provide more detailed analytics reports. |
eventName
|
type: string
pattern:
[\x20-\x7E]{1,64}
Required
Name of the specific event. Format: 1-64 ASCII characters, except control characters. To maximize the impact of your events, use consistent event names and consistent formatting—for example, “Product Added To Cart” (always in title case). For example, you can adopt Segment’s object-action framework. |
index
|
type: string
Required
Name of the Algolia index. Format: same as the index name used by the search engine. |
userToken
|
type: string
pattern:
[A-Za-z0-9_=+/-]{1,129}
Required
Anonymous user identifier. See also: User Token |
authenticatedUserToken
|
type: string
pattern:
[A-Za-z0-9_=+/-]{1,129}
Optional
Pseudonymous identifier for authenticated users. Never include personally identifiable information in user tokens. See also: User Token |
timestamp
|
type: int64
default: now()
Optional
Time of the event in milliseconds in Unix epoch time. By default, the Insights API uses the time it receives an event as its timestamp. If you’re not sending events in real time—for example, if you’re doing backend search, it’s important to set correct timestamps. If you’re sending events in batches and you’re not including a timestamp, all events will have the same timestamp.
|
queryID
|
type: string
pattern:
[a-f0-9]{32}
Optional
Unique identifier for a search query. A If you add See also: Keep track of query IDs |
objectIDs
|
type: array
items: string
Optional
List of object identifiers for items of an Algolia index. You can include up to 20 A single event must not include both |
objectData
|
type: array
items: ObjectData
Optional
This parameter is only supported in the following languages: PHP, Ruby, JavaScript, Python, and Kotlin. Extra information about the records involved in the event—for example, to add price and quantities of purchased products. If provided, must be the same length as If you include pricing information, you must also specify the |
value
|
type: number | string
Optional
This parameter is only supported in the following languages: PHP, Ruby, JavaScript, and Python. The monetary value of the event, measured in If you assign a Must be a decimal number with no more than 16 characters (including non-digit characters). |
currency
|
type: string
Optional
This parameter is only supported in the following languages: PHP, Ruby, JavaScript, and Python. If you include pricing information in the |
filters
|
type: array
items: string
pattern:
${attr}:${value}
Optional
List of facet filters. You can include up to 10 filters. Format: A single event must not include both |
positions
|
type: array
items: uint
Optional
Positions of the clicked objects in the search results.
This property is required for click events with You must provide one Algolia uses this parameter to calculate the average click position. The position is absolute, and not relative, to any results page.
For example, if there are 10 results per page,
the position of the third record of the second results page is 13.
Since If you’re using InstantSearch, you can get the position through the |
ObjectData
queryID
|
type: string
pattern:
[a-f0-9]{32}
Optional
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 |
price
|
type: number | string
Optional
The price of the item. This should be the final price, inclusive of any discounts in effect. Must be a decimal number with no more than 16 characters (including non-digit characters). |
quantity
|
type: number
Optional
The quantity of the purchased or added-to-cart item.
The total value of a purchase is the sum of |
discount
|
type: number | string
Optional
Absolute value of the discount in effect for this object, measured in
Must be a decimal number with no more than 16 characters (including non-digit characters). |
Response
This method doesn't return a response.