Guides / Search analytics / Concepts

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

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:

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 meet the following requirements:

  • The event must have an eventSubtype with the value addToCart or purchase
  • the event must include an objectData array.

All items in the objectData array of a single event are considered part of a single transaction, even if they have different queryIDs. The revenue associated with each item in the objectData array will be associated with a search according to the item-level queryID , or with the event-level queryID if none is provided for an item.

Only revenue data that can be associated with a search using a queryID and coming from transactions with a purchase subtype are included in the revenue metrics. Events without an eventSubtype, without queryIDs, or with non-existent queryIDs are ignored.

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
24
{
  // {...}
  "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
  // {...}
}
Did you find this page helpful?