# Analytics APIs

Using the API keys within the platform it's possible to use code to create assets such as Responses, Intents, Entities, Builds and many more things. In addition you can also use that API key to be able to fetch the analytics programmatically.&#x20;

## API keys

To get an API key, click on the profile button in the bottom left of the screen, and then `Edit Profile`. From the resulting page you'll see the section for API keys, and from there you can create a new Key. Existing keys will look something like the view below.&#x20;

<figure><img src="https://292592888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8n7b8WayyGW9wX1onxly%2Fuploads%2FGhAK0ImSrIhglsftOMcS%2Fimage.png?alt=media&#x26;token=ee1b3398-72e2-420b-804e-fcce7b24f995" alt=""><figcaption></figcaption></figure>

Please note that when creating a key you'll be given a `prefix` along with an `api key`. While the prefix will always be visible, the API key will only be shown to you once so make a note of it in a safe place.&#x20;

To fetch Analytics data, you'll need to ensure you have `Fetch Analytics` selected in the list of permissions.&#x20;

## Accessing APIs

There are a number of APIs for various pieces of data, and accessing them is generally all the same. For example, if using NodeJS, the following will work..&#x20;

```javascript
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://backend.logicdialog.ai/api/agent/analytics/nlp',
  qs: {
    dateFrom: '2024-04-16T10:57:12.873Z',
    dateTo: '2024-05-15T10:57:12.873Z',
    client: 'afeltham',
    resolution: 'day'
  },
  headers: {
    accept: 'application/json',
    authorization: 'Bearer <prefix>_<apiKey>',
    origin: 'https://portal.logicdialog.ai',
    'wbb-client': 'afeltham'
  }
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log("Analytics Data", body);
});

```

Each API request has a number of common parameters that appear on the `query string` of the URL. These are :&#x20;

`dateFrom` - the start date for the analytics.&#x20;

`dateTo` - the end date for the returned analytics

`client` - the workspace name to fetch analytics for.&#x20;

`resolution` - this represents the granularity of the data returned. The value can be either `hour`, `day`, `week`, `month` or `quarter`. Note that when this resolution is used, it'll modify the `dateFrom` to be the start of that resolution. For example, if `dateFrom` is `2024-04-16T10:57:12.873Z` but the resolution is set to `month`, then for the purpose of the returned data, `dateFrom` will end up being `2024-04-01T00:00:00.000Z` - ie, the start of the month.&#x20;

## Available APIs

The following table lists out all the APIs that are available to be used.&#x20;

| API                                                           | Description                                                                                                                                                                                                                                                          |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| api/agent/analytics/user                                      | The number of users created, and active within the selected time period. Note, this filters out conversations that have not interacted with the bot at all.                                                                                                          |
| api/agent/analytics/nlp                                       | The number of natural language inputs that have had a success, and those that have not been able to match an intent for the provided time period.                                                                                                                    |
| api/agent/analytics/message                                   | The number of chat messages sent by the users in the selected time period.                                                                                                                                                                                           |
| api/agent/analytics/active-channel                            | The channel used by the users within the time period specified.                                                                                                                                                                                                      |
| api/agent/analytics/message-groups                            | The identified topic the user was asking about for the days within the time period.                                                                                                                                                                                  |
| api/agent/analytics/sentiment                                 | The number of positive, negative and neutral conversations for the given time period.                                                                                                                                                                                |
| api/agent/analytics/events                                    | A count of the number of times each event in the workspace has been called during the given time period.                                                                                                                                                             |
| api/agent/analytics/user/detail                               | Pie chart data for channel, country, language and rating for the users in the selected time period.                                                                                                                                                                  |
| api/agent/analytics/response                                  | The responses used to handle user queries within the time period specified. Each entry will identify the number of views, likes and dislikes for each response, along with an indication of if that response was triggered by a button, or through natural language. |
| api/agent/analytics/urlTracking                               | The counts of the links clicked on within the responses within the time period specified.                                                                                                                                                                            |
| api/agent/analytics/blocks                                    | A breakdown of which response was shown to the user by date within the time period selected.                                                                                                                                                                         |
| api/agent/analytics/intervention                              | The number of interventions to live agents in the selected time period.                                                                                                                                                                                              |
| api/agent/analytics/intervention/average-time-by-agent-series | The average time for a conversation that has been handed over to a live agent within the time period specified.                                                                                                                                                      |
| api/agent/analytics/intervention-detail                       | The channel, topic and outcome of any live agent interventions started within the time period specified.                                                                                                                                                             |
| api/agent/analytics/intervention/average-time                 | The average time and duration for the the interventions within the time period specified.                                                                                                                                                                            |
| api/agent/analytics/active-user-language                      | Returns the language used by the user for the given time period.                                                                                                                                                                                                     |

Please note, this is not an exhaustive list and is subject to change as new information is added to the platform. For a more up to date view, please use the Network tab within the developer console in a browser. Go to the Analytics page within Logicdialog and filter for "analytics". This will show you all the available analytics endpoints and examples of the data they return.&#x20;

<figure><img src="https://292592888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8n7b8WayyGW9wX1onxly%2Fuploads%2FptpYcm9NFGACl04f8fki%2Fimage.png?alt=media&#x26;token=e73db4c9-5632-4bf8-805f-572912d12ca0" alt=""><figcaption></figcaption></figure>
