Purchased object IDs after search
This method is only available for JavaScript.
Required API Key:
any key with the
search
ACL
Only available for JavaScript
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 conversion event related to an Algolia request to capture when users purchase items.
Use this event to track when users make a purchase after a previous Algolia request.
If you use Algolia to build your category pages,
you’ll also use the purchasedObjectIDsAfterSearch
event.
Sending this event is useful for:
- NeuralSearch
- Recommend
- Personalization
- Dynamic Re-Ranking
- Query Categorization
- Search analytics
- Revenue analytics
- A/B Testing
Related methods:
purchasedObjectIDs
: track conversion purchase events not related to Algolia requests.sendEvents
: if you don’t want to send real-time events.
Examples
Read the Algolia CLI documentation for more information.
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
// This requires the `search-insights` library
aa('purchasedObjectIDsAfterSearch', {
userToken: 'anonymous-123456', // required for Node.js
authenticatedUserToken: 'user-123456',
eventName: 'your_event_name',
index: 'your_index_name',
objectIDs: ['objectID-1', 'objectID-2'],
objectData: [
{
queryID: 'queryID-1',
price: 19.99,
discount: 3.99,
quantity: 3
}, // This item was purchased as the result of a query
{
price: 59.99,
discount: 10,
quantity: 2
} // This item isn't associated with a query and won't be included in revenue analytics
],
value: 179.95,
currency: 'USD'
});
Some purchase event objects may be associated with a query, while others may not.
Only objects with a queryID
are included in revenue analytics.
For more information, see Revenue transactions.
Parameters
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 |
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. |
indexName
|
type: string
Required
Name of the Algolia index. Format: same as the index name used by the search engine. Some API clients use |
objectIDs
|
type: array
items: string
Required
List of object identifiers for items of an Algolia index. You can include up to 20 |
objectData
|
type: array
items: ObjectData
Required
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
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
If you include pricing information in 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.