Info
Content

Integrating the SDK v3 into your mobile app

Introduction

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.

Installation

iOS (Native)

Option 1: CocoaPods

Add the following line to your Podfile:

pod 'cm-sdk-ios-v3', '3.0.0'

Then run:

pod install
Option 2: XCFramework
  1. Download the latest XCFramework from our GitHub releases page.
  2. Drag and drop the XCFramework into your Xcode project.
  3. In your target's settings, go to "General" > "Frameworks, Libraries, and Embedded Content" and ensure the framework is set to "Embed & Sign".

Android (Native)

Using Maven Central

Add the following to your app's build.gradle.kts:

dependencies {
implementation "net.consentmanager.sdkv3:cmsdkv3:3.0.0"
}

React Native

We have developed a bridge to our native implementations of the SDK, which can be found on our GitHub releases page. Use npm or yarn as usual to install the dependencies. 

Flutter

Run this command:

With Flutter:

flutter pub add cmp_sdk

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

dependencies:  
cmp_sdk: ^3.0.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:

Unity

  • Download the latest release of the plugin.
  • Import the package into your Unity project using Assets > Import Package > Custom Package.

Basic Usage

Below you can find code snippets for basic implementations of the SDK. For complete demo app containing calls to all of the methods made available, check the respective demo apps in the sections below. Please note that you'll need to implement a delegate class provided by us, that concentrates all the events in response to the consent management:

  • didReceiveConsent(consent: String, jsonObject: [String : Any]) 
    This is triggered when the consent layer was closed after the user updating his/her consents OR when invoking methods that cause changes in the consents, like acceptAll, rejectAll, acceptVendors, rejectVendors, etc. It means that the user accepted of rejected some of all of the consents, and that those were correctly saved in the device.
  • didShowConsentLayer
    This is triggered when the consent layer was actually displayed. It means that there was not a consent valid in the device, so a new one should be collected.
  • didCloseConsentLayer
    This is triggered when the SDK checked the need for a consent, but it was not needed and the layer was not displayed. It means that there is already a valid in the device, so a new one is not necessary and tue consent layer will not be displayed.
  • didReceiveError
    This is triggered when the SDK faced any error.

iOS (Native)

Complete Demo app available here

import cm_sdk_ios_v3

class YourViewController: UIViewController, CMPManagerDelegate {
	override func viewDidLoad() {
	super.viewDidLoad()

	let cmpManager = CMPManager.shared

    cmpManager.setUrlConfig(UrlConfig(
    id: "your_id_here",                   	// example: a000aaaaa1a 
    domain: "your_domain_here",				// usually, delivery.consentmanager.net 
    language: "your_language_here",			// example: DE
    appName: "Your App Name"))				// example: testApp

    cmpManager.setWebViewConfig(ConsentLayerUIConfig(
    position: .fullScreen,
    backgroundStyle: .dimmed(.black, 0.5),
    cornerRadius: 5,
    respectsSafeArea: true,
    allowsOrientationChanges: true))

    cmpManager.setPresentingViewController(self)
    cmpManager.delegate = self

    cmpManager.checkWithServerAndOpenIfNecessary { error in
        if let error = error {
            print("Error initializing consent: \(error)")
        } else {
            print("ConsentManager initialized successfully")
        }
    }
}

 

Android Native - Kotlin

Complete Demo app available here, under the folder Kotlin. 

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        val urlConfig = UrlConfig(
            id = "your_code_id_here",					// Example: a10aaaaaaaa01
            domain = "your_domain_here",				// Usually, "delivery.consentmanager.net"
            language = "your_language_here",			// Example: "DE"
            appName = "your_app_name_here"				// Example: "Android Native Demo App"
        )

        val webViewConfig = ConsentLayerUIConfig(
            position = ConsentLayerUIConfig.Position.HALF_SCREEN_BOTTOM,
            backgroundStyle = ConsentLayerUIConfig.BackgroundStyle.dimmed(Color.BLACK, 0.5f),
            cornerRadius = 10f,
            respectsSafeArea = true,
            isCancelable = false
        )

        cmpManager = CMPManager.getInstance(
            context = this,
            urlConfig = urlConfig,
            webViewConfig = webViewConfig,
            delegate = this
        )

        cmpManager.setActivity(this)

        checkAndOpenConsentLayer()
    }

    private fun checkAndOpenConsentLayer() {
        cmpManager.checkWithServerAndOpenIfNecessary { result ->
            result.onSuccess {
                showCMPDemoScreen()
            }.onFailure { error ->
                Log.e("DemoApp", "Check and open consent layer failed with error: $error")
            }
        }
    }

 

Android Native - Java

Complete Demo app available here, under the folder Java. 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cmp_demo);

        UrlConfig urlConfig = new UrlConfig(
                "you_code_id_here",					// Example: a10aaaaaaaaaa01
                "your_url_here",					// Usually, "delivery.consentmanager.net
                "your_language_here",				// Example, "DE"
                "your_app_name_here"				// Example, "Demo App Java"
        );

        ConsentLayerUIConfig webViewConfig = new ConsentLayerUIConfig(
                ConsentLayerUIConfig.Position.HALF_SCREEN_BOTTOM,
                ConsentLayerUIConfig.BackgroundStyle.dimmed(Color.BLACK, 0.5f),
                10f,
                true,
                false
        );

        JavaCMPManager cmpManager = JavaCMPManager.getInstance(this, urlConfig, webViewConfig, this);
        cmpManager.setActivity(this);

        cmpManager.checkWithServerAndOpenIfNecessary(result -> {
            if (result.isSuccess()) {
                showCMPDemoScreen();
            } else {
                Log.e("JavaDemoAp", "Initialize method failed with error: " + result.exceptionOrNull());
            }
            return null;
        });
    }

    private void showCMPDemoScreen() {
        Intent intent = new Intent(this, CMPDemoActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void didShowConsentLayer() {
        Log.d("CMP JavaDemoAp", "Consent Layer open message received.");
    }

    @Override
    public void didCloseConsentLayer() {
        Log.d("CMP JavaDemoAp", "Consent Layer close message received.");
    }

    @Override
    public void didReceiveError(@NonNull String error) {
        Log.e("CMP JavaDemoAp", "SDK error: " + error);
    }

    @Override
    public void didReceiveConsent(@NonNull String consent, @NonNull JsonObject jsonObject) {
        Log.d("CMP JavaDemoAp", "Consent received: " + consent);
    }

 

React Native

Below you can find a basic code snippet. For our complete Demo App, please refer to our GitHub releases page, under the example folder. 

import React, { useEffect } from 'react';
import { View, Text } from 'react-native';
import ConsentManager, { Position, BackgroundStyle } from 'react-native-consent-manager';

const App = () => {
useEffect(() => {
  const initializeConsent = async () => {
  try {
    ConsentManager.setUrlConfig({
      id: 'your_id_here',				// Example: a10aaaaaaaaaa01
      domain: 'your_domain_here',		// Usually, "delivery.consentmanager.net"
      language: 'your_language_here',	// Example: "DE"
      appName: 'Your App Name'
    });

    ConsentManager.setWebViewConfig({
      position: Position.FullScreen,
      backgroundStyle: BackgroundStyle.Dimmed,
      cornerRadius: 5,
      respectsSafeArea: true,
      allowsOrientationChanges: true
    });

    await ConsentManager.checkWithServerAndOpenIfNecessary();
    console.log('ConsentManager initialized successfully');
    } catch (error) {
  		console.error('Error initializing consent:', error);
    }
  };

    initializeConsent();
  }, []);

  return (
    <View>
    <Text>Your app content here</Text>
    </View>
    );
};

export default App;

Flutter

late CMPmanager _cmpSdkPlugin;

String _consentStatus = '';
String _callbackLogs = '';
String _cmpString = '';
String _idString = '1';
String get consentStatus => _consentStatus;
String get callbackLogs => _callbackLogs;
String get cmpString => _cmpString;
String get idString => _idString;

void setCmpString(String value) {
  _cmpString = value;
  notifyListeners();
}

void setIdString(String value) {
  _idString = value;
  notifyListeners();
}

void initCmp() async {
  try {
    _cmpSdkPlugin = CMPmanager.instance;
    await _cmpSdkPlugin.setUrlConfig(
      appName: "Test",
      id: "YOUR_CODE_ID_HERE",
      language: "de",
      domain: "delivery.consentmanager.net",
    );

    addEventListeners();

  } catch (e) {
    if (kDebugMode) {
      print("Error initializing CMP: $e");
    }
  }
}

void addEventListeners() {
  _cmpSdkPlugin.addEventListeners(didShowConsentLayer: () {
    logCallback('Consent layer opened');
  }, didCloseConsentLayer: () {
    logCallback('Consent layer closed');
  }, didReceiveError: (error) {
    logCallback('Consent layer error $error');
  }, didReceiveConsent: (consent, jsonObject) {
    logCallback('Consent Received: $consent - $jsonObject');
  }, didChangeATTStatus: (oldStatus, newStatus, last) {
    logCallback('ATT changed: $oldStatus , $newStatus, $last');
  });

}

Future<void> setWebViewConfig(ConsentLayerUIConfig config) async {
  await _cmpSdkPlugin.setWebViewConfig(config);
  notifyListeners();
}

void logCallback(String message) {
  _callbackLogs += "$message\n";
  notifyListeners();
}

void acceptAll() async {
  await _cmpSdkPlugin.acceptAll();
  Fluttertoast.showToast(msg: 'Accepted Consent by acceptAll API');
}

void rejectAll() async {
  await _cmpSdkPlugin.rejectAll();
  Fluttertoast.showToast(msg: 'Rejected Consent by rejectAll API');
}

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

void disableVendors() async {
  if (_idString.isEmpty) {
    Fluttertoast.showToast(msg: 'ID is empty');
    return;
  }

  await _cmpSdkPlugin.rejectVendors([_idString]);
  Fluttertoast.showToast(msg: 'disabled Vendor');
  notifyListeners();

}

void enableVendors() async {
  if (_idString.isEmpty) {
    Fluttertoast.showToast(msg: 'ID is empty');
    return;
  }

  await _cmpSdkPlugin.acceptVendors([_idString]);
  Fluttertoast.showToast(msg: 'enabled Vendor');
  notifyListeners();
}

void disablePurposes() async {
  if (_idString.isEmpty) {
    Fluttertoast.showToast(msg: 'ID is empty');
    return;
  }

  await _cmpSdkPlugin.rejectPurposes([_idString]);
  Fluttertoast.showToast(msg: 'disabled Purpose');
  notifyListeners();
}

void enablePurposes() async {
  if (_idString.isEmpty) {
    Fluttertoast.showToast(msg: 'ID is empty');
    return;
  }

  await _cmpSdkPlugin.acceptPurposes([_idString]);
  Fluttertoast.showToast(msg: 'enabled Purpose');
  notifyListeners();
}

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

Future<bool> checkIfConsentIsRequired() async {
  return await _cmpSdkPlugin.checkIfConsentIsRequired();
}

void resetConsent() async {
  await _cmpSdkPlugin.resetConsentManagementData();
  Fluttertoast.showToast(msg: 'Reset consent data');
  notifyListeners();
}

Unity

private static void CheckConsentWithServer(){     
	CmpManager.Instance.CheckWithServerAndOpenIfNecessary();}
}  
    
private static void SetCmpUrlConfig() {
  	const string id = "id";           
  	const string domain = "domain";           
  	const string language = "en";           
  	const string appName = "AppName";           
  
  	CmpManager.Instance.SetUrlConfig(id, domain, language, appName);       
}         

private void OpenConsentLayer() {            
  	CmpManager.Instance.OpenConsentLayer();        
}        

private void JumpToSettings() {            
  	CmpManager.Instance.JumpToSettings();        
}        

private void HasVendorConsent(string vendorId) {            
  	var hasConsent = CmpManager.Instance.HasVendorConsent(vendorId);            
  	Debug.Log($"Has vendor consent: {hasConsent}");        
}        

private void HasPurposeConsent(string purposeId) {            
  	var hasConsent = CmpManager.Instance.HasPurposeConsent(purposeId);            
  	Debug.Log($"Has purpose consent: {hasConsent}");        
} 

 

 

Back to top