API Reference / API Parameters / analytics
Jan. 14, 2019
Type: boolean
Engine default: true
Parameter syntax
'analytics' => true|false

Can be used in these methods:

About this parameter

Whether the current query will be taken into account in the Analytics.

Usage notes:

  • Algolia captures analytics on every search. This is the default setting. Therefore, this setting’s primary use is to turn analytics off for a given query.

Examples

1
2
3
$results = $index->search('query', [
  'analytics' => false
]);

Enable analytics for the current search and forward IP

1
2
3
4
5
6
7
8
9
10
11
/*
'94.228.178.246' should be replaced with your end user IP.
Depending on your stack there are multiple ways to get this information.
*/

$ip = '94.228.178.246';
$client->setExtraHeader('X-Forwarded-For', $ip);

$results = $index->search('query', [
  'analytics' => true
]);

Note: in the above example, the IP was forwarded. This line of code is actually only useful when doing backend search.

The analytics feature relies on enduser IPs of search requests to:

  • find the location of the queries
  • compute some metrics like number of searches per IP

Therefore, when doing backend search, you need to forward the IP of the end user. Otherwise Algolia will see the queries coming from only one IP: the IP of your backend server.

Did you find this page helpful?