Info
Content

[Unity] 2. API Documentation

Initialize

Initializes the Consent Manager with the provided domain, code ID, app name, and language.

Parameters
Name Type Description
domain String The domain of the Consent Management Platform.
codeId String The code ID for the application.
appName String The name of the application.
language String The language code (e.g., "EN", "DE") for localization.
Example
       private void Awake()
        {
            _cmpManager = CmpManager.Instance;
        }

        private void Start()
        {
            _mainThread = Thread.CurrentThread;
            Debug.Log("Consentmanager SampleScene started");

#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
            var config = new CmpConfig(CodeId, Domain, AppName, Language);
            // Example of using a custom layout 
            // var customRect = new Rect(0,0, 300, 600);
            // config.SetCustomLayout(customRect);

            // alternative create the instance directly with the required parameters
            // _cmpManager.Initialize(Domain, CodeId, AppName, Language); 

            _cmpManager.Initialize(config);
            _cmpManager.Launch();
#endif
        }

AddEventListeners

Sets Android-specific callbacks for CMP events.

Example
_cmpManager.AddEventListeners(OnOpen, OnClose, OnNotOpened, OnCmpButtonClicked, OnError);

Launch

 Launches the CmpManager and shows the Consent Layer if needed

Example
_cmpManager.Launch();

HasConsent

Checks if the user has given consent.

Return

true if user has given consent, false otherwise.

Example
var hasConsent = _cmpManager.HasConsent();

OpenConsentLayer

Opens the Consent Layer to manage user's consent settings.

Example
_cmpManager.OpenConsentLayer();

 

OpenConsentLayerOnCheck

Opens the Consent Layer if necessary based on checks.

Example
_cmpManager.OpenConsentLayerOnCheck();

HasVendor

Checks if a vendor with the specified ID has been selected by the user.

Parameters
Name Type Description
id string The ID of the vendor to check. You can find the vendor IDs in your account under Menu > CMPs > Vendors.
Return Type

(bool) true if the vendor is selected, false otherwise.

Example
bool result = HasVendor("vendorId");

HasPurpose

Checks if a purpose with the specified ID has been selected by the user.

Parameters
  • id: The ID of the purpose to check.
Return Type

bool: True if the purpose is selected, false otherwise.

Example
bool result = _cmpManager.HasPurpose(purposeId);

CheckConsentIsRequired

Checks if the user need to give consent

Return Type

bool: True if consent is required

Example
var isRequired = await _cmpManager.CheckConsentIsRequired();

ExportCmpString

Return Type

string: The exported CMP settings as a string.

Example
string cmpSettings = ExportCmpString();

ImportCmpString

Parameters

string: The CMP string

Return Type

CmpImportResult: Result if the import was successfull

Example
 result = await _cmpManager.ImportCmpString(cmpString);

GetAllPurposes

Gets a list of all available purposes.

Return Type

List<string>: A list of purpose IDs.

Example
List<string> purposes = GetAllPurposes();

GetEnabledPurposes

Gets a list of enabled purposes.

Return Type

List<string>: A list of enabled purpose IDs.

Example
List<string> enabledPurposes = GetEnabledPurposes();

GetDisabledPurposes

Gets a list of disabled purposes.

Return Type

List<string>: A list of disabled purpose IDs.

Example
List<string> disabledPurposes = GetDisabledPurposes();

GetAllVendors

Gets a list of all available vendors.

Return Type

List<string>: A list of vendor IDs.

Example
List<string> allVendors = GetAllVendors();

GetEnabledVendors

Gets a list of enabled vendors.

Return Type

List<string>: A list of enabled vendor IDs.

Example
List<string> enabledVendors = GetEnabledVendors();

GetDisabledVendors

Gets a list of disabled vendors.

Return Type

List<string>: A list of disabled vendor IDs.

Example
List<string> disabledVendors = GetDisabledVendors();

GetGoogleAcString

Gets the Google Advertiser Consent string.

Return Type

string: The Google Advertiser Consent string.

Example
string googleAcString = GetGoogleAcString();

GetUsPrivacyString

Gets the US Privacy string.

Return Type

string: The US Privacy string.

Example
string usPrivacyString = GetUsPrivacyString();

 

Overview: 

 

Function Description Parameters
Initialize Initializes the CMP Manager with domain, code ID, app name, and language. domain, codeId, appName, language
Initialize Initializes the CMP Manager with a configuration object. config (CmpConfig)
HasConsent Checks if the user has given consent. None
HasVendor Checks if a vendor with the specified ID is selected by the user. id (string)
HasPurpose Checks if a purpose with the specified ID is selected by the user. id (string)
OpenConsentLayer Opens the Consent Layer for managing user consent settings. None
OpenConsentLayerOnCheck Opens the Consent Layer if necessary, based on a check with the backend. None
CheckConsentIsRequired Checks if opening the Consent Layer is necessary. None
AcceptAll Accepts all consent options. None
RejectAll Rejects all consent options. None
Launch Launches the CMP Manager and shows the Consent Layer if needed. None
Reset Resets the CMP settings. None
ExportCmpString Exports CMP settings as a string. None
ImportCmpString Imports CMP settings from a given string. cmp (string)
GetGoogleAcString Gets the Google Advertiser Consent string. None
GetUsPrivacyString Gets the US Privacy string. None
GetLastATTrackingRequestDate Gets the date of the last App Tracking Transparency request. None
GetGoogleConsentModeStatus Gets the current status of Google Consent Mode. None
GetAllPurposes Gets a list of all available purposes. None
GetEnabledPurposes Gets a list of enabled purposes. None
GetDisabledPurposes Gets a list of disabled purposes. None
GetAllVendors Gets a list of all available vendors. None
GetEnabledVendors Gets a list of enabled vendors. None
GetDisabledVendors Gets a list of disabled vendors. None
SetUIConfig Sets the UI configuration for the CMP UI. cmpUIConfig (CmpUIConfig)
RequestATTrackingPermission (iOS only) Requests App Tracking Transparency permission. None

CmpUIConfig Overview: 

 

Property/Method Description Type/Parameters
screenConfig Property to hold the chosen screen configuration. ScreenConfig enum
androidUiType (Android only) UI Type for Android devices. AndroidUiType enum
androidFragmentContainerId (Android only) Container ID for Android Fragment. int
isFocusable (Android only) If the UI should be focusable. bool
isOutsideTouchable (Android only) If the outside touch should be detected. bool
SetAndroidFragmentContainerId (Android only) Sets the container ID for the Android fragment. id (int)
SetAndroidUiType (Android only) Sets the UI type for Android. type (AndroidUiType)
CmpBridgeSetConsentManagerModalPresentationStyle (iOS only) Sets the modal presentation style via external call. modalPresentationStyle (int)
ConfigureModalPresentationStyle (iOS only) Configures the modal presentation style for iOS. style (CmpIOSModalPresentationStyle)

 

CmpConfig Overview:

 

Property/Method Description Type/Parameters
Constructor Initializes the CMP configuration with the necessary parameters. id, domain, appName, language, uiConfig (optional)
UIConfig Property to hold the UI configuration. CmpUIConfig
IdfaOrGaid Identifier for Advertisers or Google Advertising ID. string
Timeout Timeout for CMP operations. int
JumpToSettingsPage Whether to jump to the settings page automatically. bool
DesignId Optional design ID for CMP UI customization. int?
Debug Enables debug mode. bool
Id The unique identifier for the CMP instance. string (readonly)
Domain The domain associated with the CMP instance. string (readonly)
AppName The name of the application using CMP. string (readonly)
Language The language for CMP UI and operations. string (readonly)

 

 

 

 

Back to top