Skip to main content

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).
UMP integration requires the adrop-ads-backfill module. Make sure you have completed the Getting Started installation guide first.

Basic Usage

Use the Consent Manager to request user consent after initializing Adrop.
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}');
  }
});

The consent manager returns one of the following statuses:
StatusDescription
unknownConsent status not yet determined
requiredConsent required (popup will be shown)
notRequiredConsent not required (non-GDPR region)
obtainedConsent already obtained

The requestConsentInfoUpdate callback returns an AdropConsentResult object with the following properties:
PropertyTypeDescription
statusAdropConsentStatusCurrent consent status
canRequestAdsboolWhether ads can be requested
canShowPersonalizedAdsboolWhether personalized ads can be shown
errorString?Error message (null if no error)
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:
// 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
}
MethodReturn TypeDescription
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:
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

GeographyDescription
disabledUse actual device location
eeaTest GDPR (European Economic Area)
regulatedUSStateTest CCPA (California, etc.)
otherTest non-regulated regions
Debug settings should only be used during development. Remove or disable them before releasing to production.

Complete Example

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

Request Early

Request consent as early as possible in your app lifecycle, ideally right after SDK initialization.

Handle Errors

Always handle consent errors gracefully and provide fallback behavior.

Test All Scenarios

Use debug settings to test all consent scenarios (required, not required, obtained) before release.

Respect User Choice

Once consent is obtained or declined, respect the user’s choice and don’t repeatedly ask.

Targeting

Set up user and context targeting

Getting Started

SDK installation and setup guide

Reference

Types, methods, and error codes