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

# Amplitude Event Streaming

> Automatically stream Kameleoon experiment exposure events to Amplitude from the server side, enabling enriched user behavior analysis by variation.

The Amplitude Event Streaming integration automatically sends events to your Amplitude account whenever a Kameleoon experiment exposes visitors. This integration enables enriched analytics in Amplitude, providing insights on experiment exposure to help you better understand user behavior and engagement.

<Frame>
  ![](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/integrations/as-a-destination/analytics/amplitude/setting-up-amplitude/amplitude.png)
</Frame>

This integration uses Kameleoon’s event dispatcher to send server side events to your Amplitude account in batches using the `/import` endpoint of the [Amplitude HTTP API](https://amplitude.com/docs/apis/analytics/http-v2).

## Key benefits

* **Precise behavior insights:** The integration sends specific events to third-party tools for visitors exposed to web experiments and feature flags on SDK-based projects, such as apps. This detailed tracking enables a clearer view of how different variations impact user actions. For example, you can observe which variation drives more clicks, conversions, or other desired outcomes, helping you determine the most effective approach.
* **Real-time decision-making:** The integration provides data in real time, enabling on-the-fly decision-making. Armed with up-to-date insights into ongoing experiments, you can swiftly adjust strategies if a variation isn't performing as expected.
* **Effortless setup:** Enable third-party integrations directly from the Kameleoon app with no need for custom code or SDK changes.

## Considerations

* **Event delivery timing:** Kameleoon servers dispatch events with a minimum 30-minute delay.

## Prerequisites

To configure this integration, you need the following information:

* **Amplitude API key:** The API key unique to one of your Amplitude projects (as documented [here](https://amplitude.com/docs/apis/authentication))
* **Server residency:** Specify whether your Amplitude account uses the standard hosting region or EU hosting.
* **Amplitude plan:** Select the type of customer plan you have purchased with Amplitude.

You must also install the **Kameleoon SDK** on your server-side project.

## Set up

You can activate this integration for **Web Experimentation** and **Feature Experimentation**.

### For web experiments

Enable the integration from the Integrations page.

<Frame>
  ![](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/integrations/as-a-destination/analytics/amplitude/amplitude-event-streaming/Capture-decran-2024-11-04-a-15.28.41-1536x932.png)
</Frame>

Add the integration while finalizing your web experiment.

<Frame>
  ![](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/integrations/as-a-destination/analytics/amplitude/amplitude-event-streaming/Capture-decran-2024-11-13-a-16.39.57-1536x494.png)
</Frame>

### For feature experiments

Set up the integration in the feature flag environment in the integrations section. Enable it for the environments where you want it active.

<Frame>
  ![](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/integrations/as-a-destination/analytics/amplitude/amplitude-event-streaming/Capture-decran-2024-11-14-a-17.35.44-1536x770.png)
</Frame>

Once you activate the integration and your experiment is live, Kameleoon automatically sends experiment events to Amplitude whenever your experiment exposes a visitor. Each event includes key details, such as:

* The Kameleoon visitor code (sent both as a custom property and the default value for the `device_id` field)
* Exposure timestamp
* Kameleoon experiment ID
* Kameleoon variation ID

### Event payload example

Kameleoon sends events to Amplitude in the following format:

```json theme={null}
{
    "event_type": "$identify",
    "user_properties":
    {
        "$set":
        {
            "KAM_EXPERIMENT_12345": "KAM_VARIATION_15685",
            "KAM_VISITOR_CODE": "rjfloel55ug9fg"
        }
    },
    "device_id": "rjfloel55ug9fg" // also Kameleoon visitor code
    "time": 1730194985000
}
```

By default, **`user_id`** contains the visitor's Kameleoon visitor code. If you set up Kameleoon cross-device history reconciliation, Kameleoon uses the identifier placed in the cross-device reconciliation custom data instead of the visitor code.

#### Payload customization for user\_id, device\_id, and session\_id

By default, Kameleoon identifies users by the `device_id` field, which contains Kameleoon’s visitor code. However, you can customize the content of these payloads by creating and populating custom data in Kameleoon. You can define any or all of the following custom data:

* **Cross-device identification (`user_id`)**:
  * If you create a custom data field and enable it for cross-device identification, Kameleoon sends its value in the Amplitude `user_id` field when present during a visit. This custom data is ideal for “logged-in” identifiers associated with your users.
* **Device identifier (`device_id`)**:
  * If you create a custom data field called `amplitude_device_id`, its value replaces the Kameleoon visitor code in the `device_id` field of the payload when present. Use this custom data for “anonymous” identifiers tied to user devices. Kameleoon still includes the original Kameleoon visitor code in your payloads under the custom property `KAMELEOON_VISITOR_CODE`, regardless of whether you set this custom data.
* **Session identifier (`session_id`):**
  * If you create a custom data field called `amplitude_session_id`, Kameleoon sends its value in the Amplitude `session_id` field when present. Set this value to match the Amplitude session ID.

<Important>
  Use the visit scope when configuring these custom data, use the exact names: `amplitude_device_id` and `amplitude_session_id`.
</Important>

#### Event payload example

```json theme={null}
{
    "event_type": "$identify",
    "user_properties":
    {
        "$set":
        {
            "KAM_EXPERIMENT_12345": "KAM_VARIATION_15685",
            "KAM_VISITOR_CODE": "rjfloel55ug9fg"
        }
    },
    "device_id": "dfkslj47h9"
    "user_id": "xf54dd2thdd5",
    "session_id": 1396381378123
    "time": 1730194985000
}
```

Kameleoon doesn't include any custom data specific to your business in the events it sends from the server, even if that data typically appears in your Amplitude events. If you need to enrich the payload with data not tracked natively by Kameleoon, and you have a Kameleoon account, you can submit a [feature request](https://feedback.kameleoon.com/)
