Initialize the SDK
The OneTrust SDK retrieves an object that contains all the data needed to present a UI to a user to collect consent for the SDKs used in your application. The data returned is determined by the configurations made in the OneTrust Admin console.
Update the SDK Keys
- Navigate to the file where you will update SDK keys and values.
- .Net Native iOS: otsdk.dotnet.iOS/OneTrustSDK/MainUI/Views/MainAppView.cs
- .Net Native Android: otsdk.dotnet.android/OneTrustSDK/MainUI/Views/MainAppView.cs
- MAUI: MAUI_With_UI/OneTrustSDK/Helpers/OTSDKHelper.cs
- Look for the comment ENTER YOUR ONETRUST SDK KEYS HERE.
- Update the values for each required key.
- Update the values for each non-required key based on your use case.

.Net Native iOS

.Net Native Android

MAUI
SDK Keys
Key | Description | Required |
---|---|---|
domaindata_url | The URL of the application, which is always https://mobile-data.onetrust.io/bannersdk/v2/applicationdata | Yes |
storageLocation | The CDN location for the JSON that the SDK fetches (usually, but not always, cdn.cookielaw.org). | Yes |
domainIdentifier | The application guid (retrieved from the OneTrust Admin console). | Yes |
languageCode | 2-digit or 4-digit (in the case of advanced languages) ISO language code used to return content in a specific language. 📘 Note Any language code format which is not listed in the OneTrust environment will be considered as invalid input. 📘 Note If the languageCode passed by your application is valid, but does not match with a language configuration for your template, then the SDK will return content in the default language configured in the OneTrust environment (usually, but not always, English). | Yes |
apiVersion | The version of the scripts that have been published in OneTrust (eg. 6.11.0). | Yes |
countryCodeOverride | Two-letter ISO 3166-2 country code. | No |
regionCodeOverride | Two-letter state code, used alongside countryCode , typically used for CCPA use cases when providing an experience for California-based US citizens. | No |
identifier | Sets the identifier value used to create a user profile server-side. | No |
syncProfile | Tells initSDKData to attempt Cross Device Consent profile syncing. | No |
syncProfileAuth | Use this to pass the pre-signed JWT auth token required to perform Cross Device. | No |
Override Geolocation
If you would like to explicitly set a geolocation of your choice instead of using OneTrust's computed geolocation value, set the countryCodeOverride
and regionCodeOverride
values accordingly.
static string countryCodeOverride = "US";
static string regionCodeOverride = "CA";
Override Data Subject Identifier
The SDK has a setting that will send consent receipts to the OneTrust application for reporting, metrics, and dashboards. By default, the OneTrust SDK will generate its own random identifier to index this consent receipt.
This setting will allow you to override the default random identifier with one that your developers can provide. This can be done before initialization or after initialization.
Before Initialization
// Update the "identifier" key in the OneTrustContentView.xaml.cs file
static string identifier = "myUserId";
After Initialization
// Set the property on the CMPSDK shared object
CMPSDK.sharedInstance.dataSubjectID = "myUserId";
Configure OneTrust UI Event Handlers
You will then need to configure a set of UI event handlers in the code behind (.cs file) in order for the application to show/hide OneTrust views and build out the application logic.
UI Events
Event Name | Description |
---|---|
OTUI_OnClose | Fires whenever the UI should be dismissed. It is up to the application to actually dismiss the Frame with the OneTrustContentViewer . |
OTUI_OnShowingBanner | Fires whenever the Banner should be shown. It is up to the application to make the Frame with the OneTrustContentViewer visible to display a Banner UI. It is also up to the application to decide to listen to the banner layout setting for 1/3, 1/2, 2/3, or full screen and apply that to the Frame. |
OTUI_OnShowingOther | Fires whenever any non-Banner UI screen should be shown. The reason this is made available is because these views are expected to always show as full screen, whereas Banner size is configurable. It is up to the application to make the Frame with the OneTrustContentViewer full screen to display a non-Banner UI. |
OTUI_ClickedOnURL | Fires whenever the end-user taps on a web link within the OneTrust UI. It is up to the application to pass this to the operating system. |
OTUI_DataIsReady | Fires whenever the SDK finishes initializing. When this fires, all the data is ready and available to display UIs and work with the SDK. In the OneTrust sample app, this is where we check for shouldShowBanner . |
See the MAUI_With_UI/OneTrustSDK/Helpers/OTSDKHelper.cs file in the sample app for example event handlers of the above events. It is important to read through this file, study it, and understand how to apply it to your specific use case. The application developer has a lot of control on how to proceed with the rest of the implementation.
Run the App
- Once completed the steps above, run the MAUI / .Net application.
- Look at the console for any errors.
- Confirm the SDK has loaded properly. You will see !!! OT SDK READY !!! in the console log if everything is configured correctly.
- Once confirmed, go to the Displaying User Interfaces section for more information on showing Banner and Preference Center views.
Updated about 2 months ago