> ## 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 Cohorts

> Import Amplitude cohorts into Kameleoon to target visitors based on behavioral segments and run precise A/B tests and personalizations.

<Note>
  This feature is in open beta and is in active development. Contact the [Kameleoon support team](https://www.kameleoon.com/en/contact) for support with this integration.
</Note>

[Amplitude](https://amplitude.com/) is a product analytics tool that helps businesses track user behavior, analyze data, and improve their digital products to boost engagement and growth.

The Kameleoon Amplitude Cohorts integration lets you sync cohorts from Amplitude to Kameleoon.

## Key benefits

* **Seamless cohort sync:** Import user segments from Amplitude into Kameleoon effortlessly.
* **Personalized targeting:** Deliver tailored experiences based on user behavior.
* **Enhanced experimentation:** Run precise A/B tests on specific audience groups.
* **Real-time updates:** Keep user segments up-to-date automatically.

## Use cases

### Optimize experiments with behavioral targeting

Sync Amplitude cohorts with Kameleoon to test variations on users based on their real-time behavior.

For example, run an A/B test on users who have viewed a product page multiple times but haven’t added anything to their cart. Test different incentives (for example, a limited-time offer vs. social proof messaging) to determine which strategy drives the most conversions.

### Analyze results with behavioral segmentation

Break down Kameleoon campaigns using Amplitude cohorts for deeper insights.

For example, if a test or personalization campaign shows a drop in conversions, analyze key Amplitude segments (for instance, high-value customers, churn-prone users) to identify patterns. Amplitude segments help you understand which experiences resonate best with different user groups and refine your strategy accordingly.

### Personalize experiences using Amplitude's rich user insights

Leverage Amplitude’s deep user data, such as behavior, lifecycle stage, or purchase history—to create highly relevant experiences in Kameleoon.

For example, identify frequent buyers, users who recently downgraded their subscription, or those who engage with specific content. Then, tailor messaging, promotions, or feature recommendations in Kameleoon to maximize engagement and conversions.

## Get started

### Store Kameleoon Visitor Code as an Amplitude User Property

Add this code to your Amplitude SDK immediately after the `amplitude.init()` function:

```javascript theme={null}
// Ensure the SDK is loaded before setting user properties
 const identifyEvent = new amplitude.Identify();
 identifyEvent.set('kameleoon_visitorcode', Kameleoon.API.Visitor.code); 
 amplitude.identify(identifyEvent);
```

You can then view the `kameleoon_visitorcode` property in Amplitude.

### Generate your Kameleoon API Key

<Note>
  Please note that you will need a [Kameleoon Client-Secret](../../../account-and-team-management/users-and-teams/api-credentials), which you can get from your Kameleoon Customer Success Manager.
</Note>

Open this URL in your browser and replace the placeholders with your [Kameleoon Client ID](../../../account-and-team-management/users-and-teams/api-credentials) and [Client Secret](../../../account-and-team-management/users-and-teams/api-credentials) to generate your Kameleoon API Key.

`https://customers.kameleoon.com/kameleoon/amplitude/getapikey?id=CLIENT ID&secret=CLIENT SECRET`

## Activate the Kameleoon integration in Kameleoon

Locate the Kameleoon Cohorts integration in your Amplitude account under **Data** > **Catalog** > **Destinations**.

### Connect to Kameleoon

* **Create a new Destination:** Click **Kameleoon Cohorts**.
* **Set up the integration:**
  * **Name:** Provide a name for the connection (for example, Kameleoon Cohorts).
  * **Kameleoon API Key:** Enter the Kameleoon API Key you generated earlier.
  * **Kameleoon Sitecode:** Input your [project sitecode](../../../faq#how-do-i-find-my-sitecode) here.
  * **Kameleoon Visitor Code:** Select the `kameleoon_visitorcode` user property. If you can’t find it, please refer to the “Store Kameleoon Visitor Code as an Amplitude User Property” section for guidance.
* **Save the integration:** Click **Save**.

### Activate Cohort Sync in Amplitude

Navigate to your Cohorts and begin creating the cohort sync. Select Kameleoon Cohorts, choose the API target for syncing, and set the sync frequency.

## Leverage Amplitude cohorts in your Kameleoon campaigns

### Create custom data to target Amplitude cohorts in your experiments

To create a segment based on Amplitude cohorts, set up a custom data in **Kameleoon** > **Configure** > **Custom data**.

#### Retrieve Amplitude cohorts for client-side experiments

* **Create a New Custom data:** Click **New custom data**.
* **Set up the Custom data:**
  * **Name:** Amplitude Cohorts.
  * Select your project.
  * **Choose the retrieval method:** Custom JavaScript code.

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

Insert this snippet into the dedicated field.

```javascript theme={null}
Kameleoon.API.Data.retrieveDataFromRemoteSource("AMPLITUDE_COHORTS_" + Kameleoon.API.Visitor.code, function (data) {
  if (data?.cohorts) {
  data.amplitude_cohorts.map(function (segment) {
 Kameleoon.API.Data.setCustomData("Amplitude Cohorts", segment);
 });
  }
 });
 return { "value": null}
```

* **Type:** List.
* **Format:** String.
* **Scope:** The scope may be set to **Page**, depending on the scope. When the scope is Page, data is re-evaluated on every page load, if the user is within a certain cohort identified by Amplitude.

#### Retrieve Amplitude cohorts for server-side experiments

* **Create a New Custom data:** Click **New custom data**.
* **Set up the Custom data:**
  * **Name:** Amplitude Cohorts.
  * Select your project.
  * **Choose the retrieval method:** Kameleoon SDK.
  * **Type:** List.
  * **Format:** String.
  * **Scope:** The scope may be set to **Page**, depending on the scope. When the scope is Page, data is re-evaluated on every page load, if the user is within a certain cohort identified by Amplitude.

To use Amplitude cohorts in server-side experiments or feature flags, you can consult the guidelines outlined in each SDK's documentation. For instance, if you’re using the [GO SDK](../../../../developer-docs/sdks/web-sdks/go-sdk#retrieving-data-from-a-remote-source), you can refer to its documentation for detailed instructions.

The GO SDK, like our other SDKs, employs the `getRemoteData()` method. This method fetches data stored by Amplitude on our servers and makes it accessible in your backend code.

#### Fetch Amplitude cohort names in Kameleoon

In the last step of custom data creation, activate the **Save the values for the targeting condition associated with the custom data point** option.

Insert this snippet into the dedicated field and replace the value `ADD_YOUR_SITECODE` with your project sitecode.

```javascript theme={null}
 var xhr = new XMLHttpRequest();
   xhr.open("GET", 'https://data.kameleoon.io/map/map?siteCode=ADD_YOUR_SITECODE&key=AMPLITUDE_common', false);
   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   var amplitudeSegments = [];
   xhr.onreadystatechange = function() { // Call a function when the state changes.
       if (this.readyState === XMLHttpRequest.DONE && this.status === 200)
       {
           var amplitude = JSON.parse(xhr.response);
           amplitude["cohorts"].forEach(function (segment) {
               
            amplitudeSegments.push({value: segment, label: segment});
               
           });
       }
   }
   xhr.send();
   return amplitudeSegments;
```

## Use Amplitude cohort IDs in a Kameleoon segment

After the custom data for the Amplitude cohort names has been set up, you can build segments using the Kameleoon segment builder by choosing the custom data and selecting **is among the values**, which will then show a list of every cohort ID from Amplitude. Selecting one or multiple Amplitude cohorts will enable targeting in personalizations and experiments.
