Info
Content

[Flutter] 1. consentmanager SDK Integration

On this document, you'll find general information on how to integrate our SDK to your project. For further details, please refer to our API Reference documentation. 

1. Installation

consentmanager SDK is a comprehensive solution for managing user consent in mobile applications. Designed to handle GDPR compliance, user privacy preferences, and ad tracking transparency, this SDK provides a seamless integration for iOS and Android platforms. Additionally, it offers wrapper plugins/bridges for React Native, Flutter, and Unity, making it versatile across various development environments.

Steps - High Level Description

  1. Integration and Configuration:

    • Integrate the SDK into your app.
    • Configure the SDK settings according to your needs.
  2. Creating an Instance and displaying the Consent Layer:

    • On app startup, create an instance of the CMPManager class. This instance will handle the consent process.
    • The SDK will automatically display the consent screen if needed.
  3. Processing user's consent data:

    • Once consents are collected, info is stored and is available for querying through different properties and methods exposed by our SDK. You'll have information about rejected or accepted consents, vendors and purposes.

1.1 Integration and Configuration

The wrapper library for Flutter is available on pub.dev. On the command-line or terminal windows, run:

flutter pub add cmp_sdk_v3

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:  
	cmp_sdk: ^2.9.0

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import

Now in your Dart code, you can use:

import 'package:cmp_sdk/cmp_sdk.dart';

1.2 Creating an instance and displaying consent layer

Within your code, you must create an instance of class CMPManager. You'll need to set up two objects that will be passed to the getInstance method: UrlConfig, which handles your CMP configuration, like Code-ID and default language, and ConsentLayerUIConfig. which will configure the looks of the WebView that will display the consent layer. After that, you're ready to use the method checkWithServerAndOpenIfNecessary() to automatically fetch the necessary data from our server and determine if the consent screen needs to be shown or not. If so, the SDK will automatically show the consent screen at this point, via a WebView created by our SDK, which will display the consent layer with the text and buttons according to your CMP configurations (chosen via the Code-ID of your CMP), collect the data and persist the consent information in the NSUserDefaults/UserPreferences area of the device, so the app can display the targeted ads accordingly. 

Please note that the functionalities related to determining whether the consent is needed or not, as well as the display of the consent layer, depend on a reliable network connection. If there is no connection available or if the mechanism of retry fails to reach our server, the didReceiveError event will return a timeout error, and so the SDK will be totally unable to determine the need for a consent, as it will be totally unable to display the consent layer. Please ensure your logic takes this into account.

Example:

final CMPmanager cmpSdkPlugin = CMPmanager.instance;

CMPmanager.instance.setUrlConfig(
  id: testId,
  domain: testDomain,
  appName: testAppName,
  language: testLanguage);
});

void checkWithServerAndOpenIfNecessary() async {
  await _cmpSdkPlugin.checkWithServerAndOpenIfNecessary();
  notifyListeners();
}

1.3 Processing users' consent data

Checking users's consents

Our SDK offer different methods to check and retrieve consent information. The main methods are displayed in the example below:

// On the example below retrieved from our Demo App, we have some examples 
// of how to check consents from the user, either accepted or rejected. 

Future<void> checkVendorConsent() async {
  if (_idString.isEmpty) {
    Fluttertoast.showToast(msg: 'Vendor ID is empty');
    return;
  }
  final hasConsent = await _cmpSdkPlugin.hasVendorConsent(_idString);
  Fluttertoast.showToast(
    msg: hasConsent
    ? 'Consent for vendor exists $_idString'
    : 'No consent for vendor: $_idString');
}

Future<void> checkPurposeConsent() async {
  if (_idString.isEmpty) {
    Fluttertoast.showToast(msg: 'Purpose ID is empty');
    return;
  }
  final hasConsent = await _cmpSdkPlugin.hasPurposeConsent(_idString);
  Fluttertoast.showToast(
    msg: hasConsent
    ? 'Consent for purpose exists $_idString'
    : 'No consent for purpose: $_idString');
}

For further information about the other methods, pleae refer to our full API Documentation

Reopening the Consent Layer to check the users' choices

In order to allow the user to verify or change their choices, you can simply call openConsentLayer()

void openConsentLayer() async {
  await _cmpSdkPlugin.openConsentLayer();
  notifyListeners();
}

This method will display the consent layer via the same WebView instance created in the previous steps. 

In some cases an native app might contain webviews in order to display information, like advertising or content. In order to transmit the consent information from the SDK to the webview, you can retrieve the consent string using:

_cmpSdkPlugin.exportCMPInfo

This will export the consent information and all further data that is needed by the CMP. You can then pass this information to the CMP that is in your webview by adding it to the URL that is called in the webview.

If, otherwise, you need to import the consent string using the SDK, you can use the example below:

await _cmpSdkPlugin.importCMPInfo(
          'Q1FERkg3QVFERkg3QUFmR01CSVRCQkVnQUFBQUFBQUFBQWlnQUFBQUFBQUEjXzUxXzUyXzUzXzU0XzU1XzU2XyNfczI3ODlfczI3OTBfczI3OTFfczI2OTdfczk3MV9VXyMxLS0tIw'
      )

Integration with Apple Tracking Transparency (ATT)

In case you are using tracking or analytics in your app, we recommend to read the guide on ATT implementation here.

Creating a custom layout

To create a customized view of the WKWebView, like changing its positioning or background, for example, you can change the configuration passed to the ConsentLayerUIConfig object like below:

ConsentLayerUIConfig(
    position: .halfScreenTop,
    backgroundStyle: .dimmed(.grey, 0.75),
    cornerRadius: 20,
    respectsSafeArea: false,
    allowsOrientationChanges: true)

Logging

When using our iOS SDK, you may find the need to debug or analyze log information for various purposes. The logs generated by our SDK are tagged under "CMP", allowing you to easily filter and view only the relevant logs. For further information, please refer to this section of our documentation.

 

 

Back to top