---
title: "Mixpanel"
description: "Adapty と Mixpanel を連携して、強力なサブスクリプション分析を実現しましょう。"
---

[Mixpanel](https://mixpanel.com/home/) は強力なプロダクト分析サービスです。イベントドリブンのトラッキングソリューションにより、プロダクトチームはさまざまなプラットフォームにおけるユーザー獲得・コンバージョン・リテンション戦略について深い知見を得ることができます。

この連携により、Adapty のすべてのイベントを Mixpanel に送信できます。その結果、サブスクリプションビジネスとユーザー行動をより包括的に把握できるようになります。Adapty はストアからの[サブスクリプションイベント](events)を一か所で追跡できる完全なデータセットを提供します。Adapty を使えば、サブスクライバーの行動を簡単に把握し、好みを理解し、その情報をもとにターゲットを絞った効果的なコミュニケーションを行えます。

## Mixpanel 連携の設定方法 \{#how-to-set-up-mixpanel-integration\}

1. Adapty ダッシュボードで [Integrations -> Mixpanel](https://app.adapty.io/integrations/mixpanel) ページを開きます。
2. トグルを有効にして **Mixpanel Token** を入力します。すべてのプラットフォームに対してトークンを指定するか、特定のプラットフォームからのみデータを受け取りたい場合はプラットフォームを絞り込むこともできます。
3. **Mixpanel Data Residency** を Mixpanel プロジェクトに合わせて設定します。このフィールドは必須で、デフォルトは **US** です。`api.mixpanel.com` エンドポイントを使用する場合は **US** を、`api-eu.mixpanel.com` を使用する場合は **Europe** を選択してください。

:::warning
Mixpanel プロジェクトが EU データレジデンシーを使用している場合、**Mixpanel Data Residency** を **Europe** に設定する必要があります。EU プロジェクトから US エンドポイントに送信されたイベントは Mixpanel によって破棄されます。
:::

  <img src="/assets/shared/img/mixpanel.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

### Mixpanel トークンの確認方法 \{#finding-your-mixpanel-token\}

**Mixpanel Token** を取得するには:

1. [Mixpanel ダッシュボード](https://mixpanel.com/settings/project/)にログインします。
2. **Settings** を開き、**Organization Settings** を選択します。

  <img src="/assets/shared/img/mixpanel-settings.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

3. 左サイドバーから **Projects** に移動し、プロジェクトを選択します。

  <img src="/assets/shared/img/mixpanel-project-id.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

## 連携の仕組み \{#how-the-integration-works\}

Adapty は、ユーザー ID や売上などの関連イベントプロパティを[Mixpanel ネイティブプロパティ](https://docs.mixpanel.com/docs/data-structure/user-profiles)に自動的にマッピングします。これにより、サブスクリプション関連イベントの正確なトラッキングとレポーティングが実現されます。

また、Adapty はユーザーごとに売上データを蓄積し、`subscription state` や `subscription product ID` などの[ユーザープロファイルプロパティ](https://docs.mixpanel.com/docs/data-structure/user-profiles)を更新します。イベントを受信すると、Mixpanel は対応するフィールドをリアルタイムで更新します。

## イベントとタグ \{#events-and-tags\}

認証情報の下には、Adapty から Mixpanel に送信できるイベントが 3 つのグループに分かれています。必要なものをオンにするだけです。Adapty が提供するイベントの完全な一覧は[こちら](events)をご確認ください。

  <img src="/assets/shared/img/mixpanel-events.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

Adapty が提供するデフォルトのイベント名を使用することをお勧めします。ただし、必要に応じてイベント名を変更することも可能です。

## SDK の設定 \{#sdk-configuration\}

`.setIntegrationIdentifier()` メソッドを使用して `mixpanelUserId` を設定します。設定しない場合、Adapty はユーザー ID（`customerUserId`）を使用し、それが null の場合は Adapty ID を使用します。アプリから Mixpanel にデータを送信する際に使用するユーザー ID と、Adapty に送信するユーザー ID が同じであることを確認してください。

---
no_index: true
---

import Callout from '../../../components/Callout.astro';

<Callout type="note">
サードパーティSDKはユーザーIDを非同期で生成します。`Adapty.activate()` の実行時にIDがまだ準備できていない場合があります。**Customer User ID** がこれらのSDKのいずれかから取得される場合は、IDなしで `Adapty.activate()` を呼び出してください。IDが取得できたら、`setIntegrationIdentifier()` を呼び出し、次にCUIDで `identify()` を呼び出してください。
</Callout>

<Tabs groupId="current-os" queryString>
<TabItem value="swift" label="iOS (Swift)" default>

```swift showLineNumbers

do {
    try await Adapty.setIntegrationIdentifier(
        key: "mixpanel_user_id",
        value: Mixpanel.mainInstance().distinctId
    )
} catch {
    // handle the error
}
```
</TabItem>
<TabItem value="swift-callback" label="iOS (Swift-Callback)" default>

```swift showLineNumbers

let builder = AdaptyProfileParameters.Builder()
            .with(mixpanelUserId: Mixpanel.mainInstance().distinctId)

Adapty.updateProfile(params: builder.build())
```
</TabItem>
<TabItem value="kotlin" label="Android (Kotlin)" default>

```kotlin showLineNumbers
Adapty.setIntegrationIdentifier("mixpanel_user_id", mixpanelAPI.distinctId) { error ->
    if (error != null) {
        // handle the error
    }
}
```
</TabItem>
<TabItem value="flutter" label="Flutter (Dart)" default>

```javascript showLineNumbers

final mixpanel = await Mixpanel.init("Your Token", trackAutomaticEvents: true);
final distinctId = await mixpanel.getDistinctId();

try {
    await Adapty().setIntegrationIdentifier(
        key: "mixpanel_user_id",
        value: distinctId,
    );
} on AdaptyError catch (adaptyError) {
    // handle the error
} catch (e) {
    // handle the error
}
```
</TabItem>
<TabItem value="unity" label="Unity (C#)" default>

```csharp showLineNumbers
using AdaptySDK;

var distinctId = Mixpanel.DistinctId;

if (distinctId != null) {
  Adapty.SetIntegrationIdentifier(
    "mixpanel_user_id",
    distinctId,
    (error) => {
    // handle the error
  });
}
```
</TabItem>
<TabItem value="rn" label="React Native (TS)" default>

```typescript showLineNumbers

// If you already have a shared Mixpanel instance in your app, use that instance instead.
const trackAutomaticEvents = true;
const mixpanel = new Mixpanel('YOUR_PROJECT_TOKEN', trackAutomaticEvents);
await mixpanel.init();

// This is Mixpanel's current distinct_id (auto-generated, or set via mixpanel.identify(...))
const mixpanelUserId = await mixpanel.getDistinctId();

try {
    await adapty.setIntegrationIdentifier("mixpanel_user_id", mixpanelUserId);
} catch (error) {
    // handle `AdaptyError`
}
```
</TabItem>
</Tabs>

## Mixpanel イベントの構造 \{#mixpanel-event-structure\}

Adapty は `track` メソッドを使用して Mixpanel にイベントを送信します。イベントプロパティの構造は次のとおりです:

```json
{
  "event": "subscription_renewed",
  "properties": {
    "ip": 0,
    "time": 1709294400,
    "$insert_id": "123e4567-e89b-12d3-a456-426614174000",
    "vendor_product_id": "yearly.premium.6999",
    "original_transaction_id": "GPA.3383...",
    "currency": "USD",
    "environment": "Production",
    "store": "app_store",
    "purchase_date": "2024-03-01T12:00:00.000000+0000"
  }
}
```

各パラメータの説明:

| パラメータ                               | 型       | 説明                                              |
|:-------------------------------------|:--------|:--------------------------------------------------|
| `event`                              | String  | イベント名（Adapty イベントからマッピング）。        |
| `properties`                         | Object  | イベントプロパティ。                               |
| `properties.ip`                      | Integer | IP アドレス（サーバー間通信では 0 として送信）。    |
| `properties.time`                    | Long    | イベントの UNIX タイムスタンプ（秒単位）。          |
| `properties.$insert_id`              | String  | 重複排除用のユニークイベント ID（UUID）。           |
| `properties.vendor_product_id`       | String  | ストアのプロダクト ID。                            |
| `properties.original_transaction_id` | String  | 元のトランザクション ID。                          |
| `properties.currency`                | String  | 通貨コード。                                      |
| `properties.store`                   | String  | ストア名（例：「app_store」）。                    |
| `properties.environment`             | String  | 環境（「Sandbox」または「Production」）。          |

### ユーザープロファイルの更新 \{#user-profile-updates\}

Adapty は `people_set` を使用して、以下のプロパティで Mixpanel ユーザープロファイルも更新します:

| パラメータ                    | 型      | 説明                                                   |
|:--------------------------|:-------|:------------------------------------------------------|
| `subscription_state`      | String | 現在のサブスクリプション状態（例：「subscribed」）。       |
| `subscription_product_id` | String | アクティブなサブスクリプションプロダクトの ID。            |