Info
Content

[Unity] 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.

In terms of compatibility, we have:

  • Unity 20XX.X.X or later
  • iOS (via DllImport)
  • Android (via JNI)

1. Importing the SDK package

In just two steps you can have all set up.

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

Config JSON

In the CmpSdkConfig.json you can set the native SDK Version for iOS and Android which will be used for the build process: 

Find the compatible native SDK Versions here

{
  "displayName": "Consentmanager SDK",
  "name": "CmpSdk",
  "androidBasePath": "net.consentmanager.sdk",
  "version": "3.0.0",
  "androidLibraryVersion": "x.xx.x",
  "iosLibraryVersion": "x.xx.x",
  "description": "Unity plugin helps you to use native Consentmanager functionality on Android and iOS."
}

Build Settings

To change the build settings go to Window -> CmpSdk 

pluginwindow-unity.png

iOS Build Settings

  • Enable iOS Build Script: Toggle this to enable or disable the build script responsible for integrating the iOS SDK into the Unity project.
  • xcFramework Path: Specify the path to the xcFramework directory. This path can be edited directly or browsed to using the accompanying button.
  • Include Version Tag: When enabled, appends the iOS SDK version to the xcFramework path, allowing for version-specific configurations.
  • Resulting Framework Path: Displays the fully resolved path to the xcFramework, including the SDK version if the version tag is included.
  • Enable App Tracking Transparency: Toggle this to enable the App Tracking Transparency feature for iOS, which is necessary for user consent under iOS privacy guidelines.
  • App Tracking Transparency Consent Message: A text field to input the custom message displayed to users when requesting consent for tracking. This message should be clear and concise, explaining why the consent is needed.

Android Build Settings

  • Enable Android Build Script: Toggle to enable or disable the build script for integrating the Android SDK into the Unity project. 
  • Integrate Custom Layout: When enabled, this allows the use of a custom layout for the consent layer for the fragment UIView.

    If you are willing to use a custom layout with fragments, make sure that your Unity Project adds the appcompat dependency. Add a custom main Template: 
    Assets/Plugins/Android/mainTemplate.gradle
    and add the dependency:
    implementation 'androidx.appcompat:appcompat:1.x.x'

2. Using the SDK

Check the example below to see an illustration of use of our SDK. For further information, please refer to the full API Reference.

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 Script

    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}");        
    }

    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