> ## 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/react-native/overview)のインストールガイドを先に完了してください。
</Note>

***

## 基本的な使い方

Adrop初期化後にAdropConsentモジュールを使用してユーザーの同意を要求します。

```typescript theme={null}
import { AdropConsent } from 'adrop-ads-react-native'

// Adrop.initialize()の後に呼び出し
const requestConsent = async () => {
  const result = await AdropConsent.requestConsentInfoUpdate()
  if (result.error) {
    console.error('Consent error:', result.error)
  }
}
```

***

## AdropConsentResult

`requestConsentInfoUpdate()`は以下の結果タイプを返します：

```typescript theme={null}
interface AdropConsentResult {
  status: AdropConsentStatus
  canRequestAds: boolean
  canShowPersonalizedAds: boolean
  error?: string
}
```

| フィールド                    | タイプ                  | 説明                   |
| ------------------------ | -------------------- | -------------------- |
| `status`                 | `AdropConsentStatus` | 現在の同意ステータス           |
| `canRequestAds`          | `boolean`            | 広告リクエストが可能かどうか       |
| `canShowPersonalizedAds` | `boolean`            | パーソナライズド広告を表示できるかどうか |
| `error`                  | `string`             | エラーメッセージ（ある場合）       |

***

## AdropConsentStatus

```typescript theme={null}
enum AdropConsentStatus {
  UNKNOWN = 0,
  REQUIRED = 1,
  NOT_REQUIRED = 2,
  OBTAINED = 3,
}
```

| ステータス          | 値   | 説明                  |
| -------------- | --- | ------------------- |
| `UNKNOWN`      | `0` | 同意ステータスがまだ決定されていない  |
| `REQUIRED`     | `1` | 同意が必要（ポップアップが表示される） |
| `NOT_REQUIRED` | `2` | 同意は不要（非GDPR地域）      |
| `OBTAINED`     | `3` | すでに同意を取得済み          |

***

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

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

```typescript theme={null}
import {
  AdropConsent,
  AdropConsentDebugGeography,
} from 'adrop-ads-react-native'

// 同意リクエスト前にデバッグ地域を設定
// デバイスIDは自動的に検出される
AdropConsent.setDebugSettings(AdropConsentDebugGeography.EEA)  // GDPRテスト

// テスト用に同意をリセット
AdropConsent.reset()
```

### デバッグ地域

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

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

***

## 追加メソッド

### getConsentStatus

```typescript theme={null}
static getConsentStatus(): Promise<AdropConsentStatus>
```

現在の同意ステータスを返します。

### canRequestAds

```typescript theme={null}
static canRequestAds(): Promise<boolean>
```

現在広告リクエストが可能かどうかを返します。

***

## 完全な例

```typescript theme={null}
import React, { useEffect, useState } from 'react'
import { View, Text, Button } from 'react-native'
import {
  Adrop,
  AdropConsent,
  AdropConsentStatus,
  AdropConsentDebugGeography,
} from 'adrop-ads-react-native'

const App = () => {
  const [consentStatus, setConsentStatus] = useState<AdropConsentStatus>(
    AdropConsentStatus.UNKNOWN
  )

  useEffect(() => {
    initializeConsent()
  }, [])

  const initializeConsent = async () => {
    // まずAdropを初期化
    Adrop.initialize(false)

    // 開発環境でデバッグ設定
    if (__DEV__) {
      AdropConsent.setDebugSettings(AdropConsentDebugGeography.EEA)
    }

    // 同意情報更新をリクエスト
    const result = await AdropConsent.requestConsentInfoUpdate()
    if (result.error) {
      console.error('同意エラー:', result.error)
    } else {
      setConsentStatus(result.status)
    }
  }

  const resetConsent = async () => {
    AdropConsent.reset()
    await initializeConsent()
  }

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>同意ステータス: {AdropConsentStatus[consentStatus]}</Text>
      {__DEV__ && (
        <Button title="同意をリセット" onPress={resetConsent} />
      )}
    </View>
  )
}

export default App
```

***

## ベストプラクティス

<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/react-native/targeting">
    ユーザーおよびコンテキストターゲティング設定
  </Card>

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

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