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

> Integrate Google UMP for GDPR/CCPA compliance in Flutter.

## Overview

The User Messaging Platform (UMP) SDK helps you manage user consent for personalized advertising in compliance with GDPR (General Data Protection Regulation) and CCPA (California Consumer Privacy Act).

<Note>
  UMP integration requires the `adrop-ads-backfill` module. Make sure you have completed the [Getting Started](/sdk/flutter/overview) installation guide first.
</Note>

***

## Basic Usage

Use the Consent Manager to request user consent after initializing Adrop.

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

// Call after Adrop.initialize()
Adrop.consentManager.requestConsentInfoUpdate((result) {
  if (result.error != null) {
    debugPrint('Consent error: ${result.error}');
  }
});
```

***

## Consent Status

The consent manager returns one of the following statuses:

| Status        | Description                            |
| ------------- | -------------------------------------- |
| `unknown`     | Consent status not yet determined      |
| `required`    | Consent required (popup will be shown) |
| `notRequired` | Consent not required (non-GDPR region) |
| `obtained`    | Consent already obtained               |

***

## Consent Result

The `requestConsentInfoUpdate` callback returns an `AdropConsentResult` object with the following properties:

| Property                 | Type                 | Description                           |
| ------------------------ | -------------------- | ------------------------------------- |
| `status`                 | `AdropConsentStatus` | Current consent status                |
| `canRequestAds`          | `bool`               | Whether ads can be requested          |
| `canShowPersonalizedAds` | `bool`               | Whether personalized ads can be shown |
| `error`                  | `String?`            | Error message (null if no error)      |

```dart theme={null}
Adrop.consentManager.requestConsentInfoUpdate((result) {
  if (result.error != null) {
    debugPrint('Consent error: ${result.error}');
    return;
  }

  debugPrint('Status: ${result.status}');
  debugPrint('Can request ads: ${result.canRequestAds}');
  debugPrint('Can show personalized ads: ${result.canShowPersonalizedAds}');
});
```

***

## Additional Methods

You can also query the consent status and ad request availability independently:

```dart theme={null}
// Get the current consent status
final status = await Adrop.consentManager.getConsentStatus();
debugPrint('Current status: $status');

// Check if ads can be requested
final canRequest = await Adrop.consentManager.canRequestAds();
if (canRequest) {
  // Load ads
}
```

| Method                               | Return Type                  | Description                                                   |
| ------------------------------------ | ---------------------------- | ------------------------------------------------------------- |
| `requestConsentInfoUpdate(listener)` | `Future<void>`               | Request consent info update and show consent form if required |
| `getConsentStatus()`                 | `Future<AdropConsentStatus>` | Get the current consent status                                |
| `canRequestAds()`                    | `Future<bool>`               | Check if ads can be requested                                 |
| `setDebugSettings(geography)`        | `Future<void>`               | Set debug geography for testing                               |
| `reset()`                            | `Future<void>`               | Reset consent information                                     |

***

## Debug Settings (Test Mode)

Test GDPR/CCPA consent flows during development:

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

// Set debug geography before requesting consent
// Device ID is automatically applied
await Adrop.consentManager.setDebugSettings(AdropConsentDebugGeography.eea);  // Test GDPR

// Reset consent for testing
await Adrop.consentManager.reset();
```

### Debug Geographies

| Geography          | Description                        |
| ------------------ | ---------------------------------- |
| `disabled`         | Use actual device location         |
| `eea`              | Test GDPR (European Economic Area) |
| `regulatedUSState` | Test CCPA (California, etc.)       |
| `other`            | Test non-regulated regions         |

<Warning>
  Debug settings should only be used during development. Remove or disable them before releasing to production.
</Warning>

***

## Complete Example

```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 {
    // Initialize Adrop first
    await Adrop.initialize(false);

    // Set debug settings in debug mode
    const bool isDebug = bool.fromEnvironment('dart.vm.product') == false;
    if (isDebug) {
      await Adrop.consentManager.setDebugSettings(AdropConsentDebugGeography.eea);
    }

    // Request consent info update
    Adrop.consentManager.requestConsentInfoUpdate((result) {
      if (result.error != null) {
        debugPrint('Consent error: ${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('Consent Status: $_consentStatus'),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: _resetConsent,
              child: const Text('Reset Consent'),
            ),
          ],
        ),
      ),
    );
  }
}
```

***

## Best Practices

<CardGroup cols={2}>
  <Card title="Request Early" icon="clock">
    Request consent as early as possible in your app lifecycle, ideally right after SDK initialization.
  </Card>

  <Card title="Handle Errors" icon="triangle-exclamation">
    Always handle consent errors gracefully and provide fallback behavior.
  </Card>

  <Card title="Test All Scenarios" icon="vial">
    Use debug settings to test all consent scenarios (required, not required, obtained) before release.
  </Card>

  <Card title="Respect User Choice" icon="user-check">
    Once consent is obtained or declined, respect the user's choice and don't repeatedly ask.
  </Card>
</CardGroup>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Targeting" icon="bullseye" href="/sdk/flutter/targeting">
    Set up user and context targeting
  </Card>

  <Card title="Getting Started" icon="rocket" href="/sdk/flutter/overview">
    SDK installation and setup guide
  </Card>

  <Card title="Reference" icon="book" href="/sdk/flutter/reference">
    Types, methods, and error codes
  </Card>
</CardGroup>
