algolia / algoliasearch-client-php

⚡️ A fully-featured and blazing-fast PHP API client to interact with Algolia.
https://www.algolia.com/doc/api-client/php/getting-started/
MIT License
671 stars 116 forks source link

ClickAnalytics ignored on searches endpoint #689

Closed WillyReyno closed 2 years ago

WillyReyno commented 2 years ago

Description

When using the /2/searches endpoint, I want to retrieve click analytics data such as CTR, conversion rate etc. I passed clickAnalytics => true parameter as specified in the documentation, but I'm still only getting search, nbHits & count data.

Here are the parameters I pass :

[
    "index" => "my_index",
    "clickAnalytics" => true,
    "limit" => 5,
]

Here is the result from the API :

{
   "searches":[
      {
         "search":"",
         "count":7285,
         "nbHits":13309
      },
      {
         "search":"laravel",
         "count":194,
         "nbHits":164
      },
      {
         "search":"symfony",
         "count":130,
         "nbHits":16
      },
      {
         "search":"vuejs",
         "count":82,
         "nbHits":100
      },
      {
         "search":"react",
         "count":58,
         "nbHits":80
      }
   ]
}

The option array is correctly read since the limit is applied, but clickAnalytics seems to be ignored.

DevinCodes commented 2 years ago

Hi @WillyReyno ,

Thank you for reporting this. Could you please show us the code you use to call the endpoint? This could help us debug the issue.

Thank you in advance!

WillyReyno commented 2 years ago

Here is my code, I'm using Laravel's Http client :


use Illuminate\Support\Facades\Http;

Http::withHeaders([
            'X-Algolia-API-Key' => 'my-api-key',
            'X-Algolia-Application-Id' => 'my-app-id',
        ])->get('https://analytics.us.algolia.com/2/searches', [
            'index' => 'my-index',
            'clickAnalytics' => true,
            'limit' => 5,
            'startDate' => '2021-09-27',
            'endDate' => '2021-10-03',
        ]);
DevinCodes commented 2 years ago

If you change 'clickAnalytics' => true to 'clickAnalytics' => 'true' this should work. The HTTP client in Laravel converts true to 1 in the URL, but the Algolia API expects true.

I'm also closing this issue since this isn't using the Algolia API client, but the HTTP client in Laravel. The change I explained above should solve your issue though 🙂