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
  • id: The ID of the vendor to check.
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();
Back to top