UMP(User Messaging Platform)SDKは、GDPR(一般データ保護規則)およびCCPA(カリフォルニア消費者プライバシー法)準拠のために、パーソナライズド広告に対するユーザーの同意を管理します。
UMP連携にはadrop-ads-backfillモジュールが必要です。はじめにのインストールガイドを先に完了してください。
基本的な使い方
Adrop初期化後にConsent Managerを使用してユーザーの同意を要求します。
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) |
Adrop.consentManager.requestConsentInfoUpdate((result) {
if (result.error != null) {
debugPrint('同意エラー: ${result.error}');
return;
}
debugPrint('ステータス: ${result.status}');
debugPrint('広告リクエスト可能: ${result.canRequestAds}');
debugPrint('パーソナライズド広告表示可能: ${result.canShowPersonalizedAds}');
});
追加メソッド
同意ステータスと広告リクエスト可否を個別に照会することもできます:
// 現在の同意ステータスを取得
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同意フローをテストしてください:
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 | 非規制地域テスト |
デバッグ設定は開発中のみ使用してください。本番リリース前に削除または無効化してください。
完全な例
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('同意をリセット'),
),
],
),
),
);
}
}
ベストプラクティス
早期リクエスト
SDK初期化直後、アプリライフサイクルの早い段階で同意を要求してください。
エラー処理
同意エラーを適切に処理し、フォールバック動作を提供してください。
全シナリオテスト
リリース前にデバッグ設定を使用してすべての同意シナリオをテストしてください。
ユーザー選択の尊重
同意を得たり拒否された後は、ユーザーの選択を尊重し、繰り返し要求しないでください。
関連ドキュメント