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

# UMP連携

> GDPR/CCPA準拠のためのGoogle UMP連携

## 概要

UMP（User Messaging Platform）SDKは、GDPR（一般データ保護規則）およびCCPA（カリフォルニア消費者プライバシー法）準拠のために、パーソナライズド広告に対するユーザーの同意を管理します。

<Note>
  UMP連携には`adrop-ads-backfill`モジュールが必要です。[はじめに](/ja/sdk/flutter/overview)のインストールガイドを先に完了してください。
</Note>

***

## 基本的な使い方

Adrop初期化後にConsent Managerを使用してユーザーの同意を要求します。

```dart theme={null}
import 'package:adrop_ads_flutter/adrop_ads_flutter.dart';

// Adrop.initialize()の後に呼び出し
Adrop.consentManager.requestConsentInfoUpdate((result) {
  if (result.error != null) {
    debugPrint('Consent error: ${result.error}');
  }
});
```

***

## 同意ステータス

Consent Managerは次のステータスのいずれかを返します：

| ステータス         | 説明                  |
| ------------- | ------------------- |
| `unknown`     | 同意ステータスがまだ決定されていない  |
| `required`    | 同意が必要（ポップアップが表示される） |
| `notRequired` | 同意は不要（非GDPR地域）      |
| `obtained`    | すでに同意を取得済み          |

***

## 同意結果

`requestConsentInfoUpdate`のコールバックは、以下のプロパティを持つ`AdropConsentResult`オブジェクトを返します：

| プロパティ                    | 型                    | 説明                      |
| ------------------------ | -------------------- | ----------------------- |
| `status`                 | `AdropConsentStatus` | 現在の同意ステータス              |
| `canRequestAds`          | `bool`               | 広告リクエストが可能かどうか          |
| `canShowPersonalizedAds` | `bool`               | パーソナライズド広告の表示が可能かどうか    |
| `error`                  | `String?`            | エラーメッセージ（エラーがない場合はnull） |

```dart theme={null}
Adrop.consentManager.requestConsentInfoUpdate((result) {
  if (result.error != null) {
    debugPrint('同意エラー: ${result.error}');
    return;
  }

  debugPrint('ステータス: ${result.status}');
  debugPrint('広告リクエスト可能: ${result.canRequestAds}');
  debugPrint('パーソナライズド広告表示可能: ${result.canShowPersonalizedAds}');
});
```

***

## 追加メソッド

同意ステータスと広告リクエスト可否を個別に照会することもできます：

```dart theme={null}
// 現在の同意ステータスを取得
final status = await Adrop.consentManager.getConsentStatus();
debugPrint('現在のステータス: $status');

// 広告リクエストが可能か確認
final canRequest = await Adrop.consentManager.canRequestAds();
if (canRequest) {
  // 広告を読み込む
}
```

| メソッド                                 | 戻り値の型                        | 説明                             |
| ------------------------------------ | ---------------------------- | ------------------------------ |
| `requestConsentInfoUpdate(listener)` | `Future<void>`               | 同意情報の更新をリクエストし、必要に応じて同意フォームを表示 |
| `getConsentStatus()`                 | `Future<AdropConsentStatus>` | 現在の同意ステータスを取得                  |
| `canRequestAds()`                    | `Future<bool>`               | 広告リクエストが可能か確認                  |
| `setDebugSettings(geography)`        | `Future<void>`               | テスト用のデバッグ地域を設定                 |
| `reset()`                            | `Future<void>`               | 同意情報をリセット                      |

***

## デバッグ設定（テストモード）

開発中にGDPR/CCPA同意フローをテストしてください：

```dart theme={null}
import 'package:adrop_ads_flutter/adrop_ads_flutter.dart';

// 同意リクエスト前にデバッグ地域を設定
// デバイスIDは自動的に適用される
await Adrop.consentManager.setDebugSettings(AdropConsentDebugGeography.eea);  // GDPRテスト

// テスト用に同意をリセット
await Adrop.consentManager.reset();
```

### デバッグ地域

| 地域                 | 説明                 |
| ------------------ | ------------------ |
| `disabled`         | 実際のデバイス位置を使用       |
| `eea`              | GDPRテスト（欧州経済領域）    |
| `regulatedUSState` | CCPAテスト（カリフォルニアなど） |
| `other`            | 非規制地域テスト           |

<Warning>
  デバッグ設定は開発中のみ使用してください。本番リリース前に削除または無効化してください。
</Warning>

***

## 完全な例

```dart theme={null}
import 'package:flutter/material.dart';
import 'package:adrop_ads_flutter/adrop_ads_flutter.dart';

class ConsentExample extends StatefulWidget {
  const ConsentExample({super.key});

  @override
  State<ConsentExample> createState() => _ConsentExampleState();
}

class _ConsentExampleState extends State<ConsentExample> {
  String _consentStatus = 'unknown';

  @override
  void initState() {
    super.initState();
    _initializeConsent();
  }

  Future<void> _initializeConsent() async {
    // まずAdropを初期化
    await Adrop.initialize(false);

    // デバッグモードでデバッグ設定
    const bool isDebug = bool.fromEnvironment('dart.vm.product') == false;
    if (isDebug) {
      await Adrop.consentManager.setDebugSettings(AdropConsentDebugGeography.eea);
    }

    // 同意情報更新をリクエスト
    Adrop.consentManager.requestConsentInfoUpdate((result) {
      if (result.error != null) {
        debugPrint('同意エラー: ${result.error}');
      } else {
        setState(() {
          _consentStatus = result.status.toString();
        });
      }
    });
  }

  Future<void> _resetConsent() async {
    await Adrop.consentManager.reset();
    await _initializeConsent();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('同意ステータス: $_consentStatus'),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: _resetConsent,
              child: const Text('同意をリセット'),
            ),
          ],
        ),
      ),
    );
  }
}
```

***

## ベストプラクティス

<CardGroup cols={2}>
  <Card title="早期リクエスト" icon="clock">
    SDK初期化直後、アプリライフサイクルの早い段階で同意を要求してください。
  </Card>

  <Card title="エラー処理" icon="triangle-exclamation">
    同意エラーを適切に処理し、フォールバック動作を提供してください。
  </Card>

  <Card title="全シナリオテスト" icon="vial">
    リリース前にデバッグ設定を使用してすべての同意シナリオをテストしてください。
  </Card>

  <Card title="ユーザー選択の尊重" icon="user-check">
    同意を得たり拒否された後は、ユーザーの選択を尊重し、繰り返し要求しないでください。
  </Card>
</CardGroup>

***

## 関連ドキュメント

<CardGroup cols={2}>
  <Card title="ターゲティング" icon="bullseye" href="/ja/sdk/flutter/targeting">
    ユーザーおよびコンテキストターゲティング設定
  </Card>

  <Card title="はじめに" icon="rocket" href="/ja/sdk/flutter/overview">
    SDKインストールおよび設定ガイド
  </Card>

  <Card title="リファレンス" icon="book" href="/ja/sdk/flutter/reference">
    タイプ、メソッド、エラーコード
  </Card>
</CardGroup>
