> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flipt.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Analytics

> This document describes various configuration mechanisms for controlling analytics for Flipt v2.

## Analytics

Flipt includes functionality for reporting analytical data to a configurable storage engine.

Currently, Flipt has support for collecting data into the following storage engines:

* [ClickHouse](https://clickhouse.com/)
* [Prometheus](https://prometheus.io/)

The data that gets collected currently includes:

* Flag Evaluation Count

Once a storage engine is configured, these analytics are viewable in the UI allowing users to visualize up to 24 hours of data for each metric.

<img src="https://mintcdn.com/flipt/s6nfJ4nOWcvmKHtt/v2/images/configuration/analytics/dashboard.png?fit=max&auto=format&n=s6nfJ4nOWcvmKHtt&q=85&s=b47d8c2742c6c3ae6834d67bb39a86e3" alt="Analytics Dashboard" width="2880" height="1800" data-path="v2/images/configuration/analytics/dashboard.png" />

The image above shows the past 30 minutes of the flag `summer-sale` evaluation counts.

### Origin

Analytics are currently only collected as they pass through the evaluation server. This means that analytics will be captured if you are using the REST or GRPC APIs via one of our [Server SDKs](/v2/integration/server/rest) or [GRPC SDKs](/v1/integration/server/grpc) for evaluations.

We have plans to support collecting analytics for [Client-Side](/v2/integration/client) evaluations in the future.

## ClickHouse

You can use a self-hosted ClickHouse instance or a [managed instance](https://clickhouse.com/cloud/) to store your analytics data.

We highly **recommend** using a separate database for analytics produced by Flipt. This ensures that Flipt analytic data can be logically isolated from the rest of your Clickhouse data.

<Note>
  The analytics database must be created before Flipt will be able to write
  analytical data and run any migrations. See our
  [migrate](/v2/cli/commands/migrate) command for more info.
</Note>

To create a database for Flipt analytics, you can use the following SQL:

```sql theme={null}
CREATE DATABASE IF NOT EXISTS flipt_analytics_v2;
```

See the [ClickHouse documentation](https://clickhouse.com/docs) for more information on how to get started with ClickHouse.

### Configuration

To configure Flipt to use ClickHouse for analytics, you will need to add the following configuration to your `config.yml` file or environment variables:

<Tabs>
  <Tab title="Environment Variables">
    ```bash theme={null}
    FLIPT_ANALYTICS_STORAGE_CLICKHOUSE_ENABLED=true
    FLIPT_ANALYTICS_STORAGE_CLICKHOUSE_URL=clickhouse://clickhouse:9000/flipt_analytics_v2
    ```
  </Tab>

  <Tab title="Configuration YAML">
    ```yaml theme={null}
    analytics:
      storage:
        clickhouse:
          enabled: true
          url: clickhouse://clickhouse:9000/flipt_analytics_v2
    ```
  </Tab>
</Tabs>

## Prometheus

You can use any [Prometheus](https://prometheus.io/docs/introduction/overview/) server to store your analytics data.

### Configuration

To configure Flipt to use Prometheus for analytics, you will need to add the following configuration to your `config.yml` file or environment variables:

<Tabs>
  <Tab title="Environment Variables">
    ```bash theme={null}
    FLIPT_ANALYTICS_STORAGE_PROMETHEUS_ENABLED=true
    FLIPT_ANALYTICS_STORAGE_PROMETHEUS_URL=http://prometheus:9090
    ```
  </Tab>

  <Tab title="Configuration YAML">
    ```yaml theme={null}
    analytics:
      storage:
        prometheus:
          enabled: true
          url: http://prometheus:9090
    ```
  </Tab>
</Tabs>

### Custom Headers

You can also add custom headers to the Prometheus requests by setting the `analytics.storage.prometheus.headers` configuration property. This can be useful if you are using a proxy or need to add additional authentication headers.

```yaml theme={null}
analytics:
  storage:
    prometheus:
      headers:
        "Authorization": "Bearer <token>"
```

### AWS SigV4 Authentication

If you are using [Amazon Managed Service for Prometheus (AMP)](https://aws.amazon.com/prometheus/), you can configure Flipt to authenticate requests using [AWS Signature Version 4 (SigV4)](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html).

<Tabs>
  <Tab title="Configuration YAML">
    ```yaml theme={null}
    analytics:
      storage:
        prometheus:
          enabled: true
          url: https://aps-workspaces.us-east-1.amazonaws.com/workspaces/<workspace-id>
          sigv4:
            enabled:  true
    ```
  </Tab>

  <Tab title="Environment Variables">
    ```bash theme={null}
    FLIPT_ANALYTICS_STORAGE_PROMETHEUS_ENABLED=true
    FLIPT_ANALYTICS_STORAGE_PROMETHEUS_URL=https://aps-workspaces.us-east-1.amazonaws.com/workspaces/<workspace-id>
    FLIPT_ANALYTICS_STORAGE_PROMETHEUS_SIGV4_ENABLED=true
    FLIPT_ANALYTICS_STORAGE_PROMETHEUS_SIGV4_REGION=us-east-1
    FLIPT_ANALYTICS_STORAGE_PROMETHEUS_SIGV4_ACCESS_KEY=<aws-access-key-id>
    FLIPT_ANALYTICS_STORAGE_PROMETHEUS_SIGV4_SECRET_KEY=<aws-secret-access-key>
    ```
  </Tab>
</Tabs>

If `access_key` and `secret_key` are not provided, Flipt falls back to the [default AWS credential chain](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials) (environment variables, shared credentials file, IAM instance profile, etc.).

You can also assume an IAM role by specifying `role_arn`:

```yaml theme={null}
analytics:
  storage:
    prometheus:
      enabled: true
      url: https://aps-workspaces.us-east-1.amazonaws.com/workspaces/<workspace-id>
      sigv4:
        enabled: true
        region: us-east-1
        role_arn: arn:aws:iam::<account-id>:role/<role-name>
```

| Property                                       | Description                                     | Default |
| ---------------------------------------------- | ----------------------------------------------- | ------- |
| analytics.storage.prometheus.sigv4.enabled     | Enable Prometheus SigV4 support                 | false   |
| analytics.storage.prometheus.sigv4.region      | AWS region for SigV4 signing                    |         |
| analytics.storage.prometheus.sigv4.access\_key | AWS access key ID                               |         |
| analytics.storage.prometheus.sigv4.secret\_key | AWS secret access key                           |         |
| analytics.storage.prometheus.sigv4.profile     | AWS credentials profile name                    |         |
| analytics.storage.prometheus.sigv4.role\_arn   | ARN of an IAM role to assume for authentication |         |
