Query aggregation and processing
To ensure relevant analytics data, search queries are aggregated in the search analytics.
For example, if a user types “beatles”:
The search engine runs seven search queries: “b”, “be”, “bea”, “beat”, “beatl”, beatle”, and “beatles”.
The analytics engine counts only the last query, “beatles”.
Algolia aggregates search queries based on:
- Edit distance
- Timestamp (queries within 30 s are aggregated)
- User ID
By default, the user ID is the user’s IP address. For more accurate analytics, explicitly set a user token
Query aggregation and backend search
If you make search requests from your backend, the user ID for all searches would be your server’s IP address, which leads to inaccurate analytics. To obtain accurate analytics, you must provide unique user IDs.
To provide unique user IDs, select one of these options:
- Set a user token for analytics
- Forward user IP addresses
Forward user IP addresses
If you make search requests from your backend servers,
and you don’t want to explicitly set user tokens,
you can add the X-Forwarded-For
header to forward your users’ IP addresses to Algolia.
1
2
3
4
$res = $index->search('', [
// Replace `XX.XXX.XXX.XXXX` with your user's IP address
'X-Forwarded-For' => 'XX.XXX.XXX.XXX',
]);
Revenue transactions
To track revenue associated with a search, events must include the following properties:
eventSubtype
with the valueaddToCart
orpurchase
objectData
queryID
Events without the eventSubtype
or queryID
properties,
or events with query IDs that don’t correspond to searches
won’t be included in revenue metrics.
For more information, see the Insights API reference.
All items in the objectData
array of a single event are part of a single transaction, even if they have different query IDs.
The revenue associated with each item in the objectData
array will be associated with a search according to the item-level query ID.
or with the event-level query ID if none is provided for an item.
The following event would be included in the Average order value,
Purchase Rate,
and Revenue charts,
as well as the respective search or hit in the Searches or
Results tables for the given queryID
or objectIDs
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"eventType": "conversion",
"objectIDs": ["black-t-shirt-xxl", "pink-jeans-xl"],
"eventSubtype": "purchase"
"objectData": [
{
// revenue data for 'black-t-shirt-xxl'
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7", // optional
"price": 19.99, // required (the sale price is the per item list price minus discount)
"discount": 4.01, // optional (defaults to 0)
"quantity": 2 // optional (defaults to 1)
},
{
// revenue data for 'pink-jeans-xl'
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
"price": 39.99,
"discount": 10.01,
"quantity": 1
}
],
"currency": "USD" // required
// ...
}