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

# Klaviyo Cohorts

> Import Klaviyo segments into Kameleoon to target visitors based on behavioral cohorts 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>

[Klaviyo](https://www.klaviyo.com/) is a marketing automation and customer relationship management platform that helps ecommerce and B2C brands personalize email, SMS, mobile, and customer engagement campaigns using real-time customer data and AI-powered insights. Businesses use it to automate marketing, segment audiences, analyze customer behavior, and drive retention, conversions, and revenue growth across digital channels.

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

The Kameleoon Klaviyo Cohorts integration automatically syncs segments from Klaviyo to Kameleoon.

## Key benefits

* **Seamless cohort sync:** Import user segments from Klaviyo 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 Klaviyo segments 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 Klaviyo cohorts for deeper insights.

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

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

Leverage Klaviyo'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 a Klaviyo Identifier

Use the Klaviyo JavaScript API to assign the Kameleoon visitor code:

```javascript theme={null}
// Ensure Klaviyo and Kameleoon are loaded before identifying the user
klaviyo.identify({
  // 'email' : 'george.washington@example.com',
  // 'first_name' : 'George',
  // 'last_name' : 'Washington',
  'kameleoon_visitor_code': Kameleoon.API.Visitor.code,
});
```

### Activate the integration in Kameleoon

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

To enable the integration:

1. Go to **Kameleoon Admin** > **Integrations**.
2. Click **Klaviyo Cohorts** and select **Install**.
3. Choose your project(s) and click **Validate**. You are redirected to Klaviyo to authorize data sharing with Kameleoon.
4. Grant Klaviyo permission to share data with Kameleoon.

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

Klaviyo segments are automatically synced with Kameleoon during the initial connection and refreshed every 4 hours thereafter.

## Leverage Klaviyo Cohorts in your Kameleoon campaigns

### Create custom data to target Klaviyo segments in your experiments

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

#### Retrieve Klaviyo segments for client-side experiments

1. Click **New custom data**.
2. Configure the custom data:
   * **Name:** Klaviyo Cohorts.
   * Select your project.
   * **Retrieval method:** Custom JavaScript code.

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

3. Insert this snippet into the dedicated field:

```javascript theme={null}
Kameleoon.API.Data.retrieveDataFromRemoteSource("KLAVIYO_COHORTS_" + Kameleoon.API.Visitor.code, function(data) {
  if (data?.cohorts) {
    data.cohorts.map(function(segment) {
      Kameleoon.API.Data.setCustomData("Klaviyo Cohorts", segment);
    });
  }
});

return { "value": null }
```

4. Set the remaining fields:
   * **Type:** List.
   * **Format:** String.
   * **Scope:** The scope may be set to **Page**, depending on your requirements. When the scope is Page, data is re-evaluated on every page load if the user is within a cohort identified by Klaviyo.

#### Retrieve Klaviyo segments for server-side experiments

1. Click **New custom data**.
2. Configure the custom data:
   * **Name:** Enter the name for the custom data that will contain your Klaviyo segments (for example, Klaviyo cohorts).
   * Select your project.
   * **Retrieval method:** Kameleoon SDK.
   * **Type:** List.
   * **Format:** String.
   * **Scope:** The scope may be set to **Page**, depending on your requirements. When the scope is Page, data is re-evaluated on every page load if the user is within a cohort identified by Klaviyo.

To use Klaviyo segments in server-side experiments or feature flags, see the guidelines in each SDK's documentation. For example, if you're using the [GO SDK](../../../../developer-docs/sdks/web-sdks/go-sdk#getremotedata), refer to its documentation for detailed instructions.

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

#### Fetch Klaviyo segment names in Kameleoon

1. In the last step of custom data creation, activate the **Save the values for the targeting condition associated with the custom data point** option.
2. Insert this snippet into the dedicated field and replace `{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=KLAVIYO_COMMON', false);
xhr.send(null);
if (xhr.status === 200) {
   const data = JSON.parse(xhr.responseText)
   var klaviyoSegments = [];
   if (
     data &&
     Object.prototype.hasOwnProperty.call(data, "cohorts") &&
     data.cohorts &&
     typeof data.cohorts === "object"
   ) {
     Object.entries(data.cohorts).forEach(function ([id, name]) {
       klaviyoSegments.push({
         value: id,
         label: name
       });
   });
   return klaviyoSegments;
   }
   return [];
} else {
   console.error("Error calling for existing custom data values");
   return [];
}
```

## Use Klaviyo segment IDs in a Kameleoon segment

After setting up the custom data for Klaviyo segment names, build segments using the Kameleoon segment builder by choosing the custom data and selecting **is among the values**. A list of every cohort ID from Klaviyo appears. Select one or multiple Klaviyo segments to enable targeting in personalizations and experiments.
