analytics
true
'analytics' => true|false
Can be used in these methods:
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
searchAsync,
browseAsync,
searchForFacetValues
Search,
Browse,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
BrowseObjects,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
browse index,
search into facet values,
generateSecuredApiKey,
add key,
update key
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
Disable analytics for the current search
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.