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

  1. Navigate to the file where you will update SDK keys and values.
    1. .Net Native iOS: otsdk.dotnet.iOS/OneTrustSDK/MainUI/Views/MainAppView.cs
    2. .Net Native Android: otsdk.dotnet.android/OneTrustSDK/MainUI/Views/MainAppView.cs
    3. MAUI: MAUI_With_UI/OneTrustSDK/Helpers/OTSDKHelper.cs
  2. Look for the comment ENTER YOUR ONETRUST SDK KEYS HERE.
  3. Update the values for each required key.
  4. Update the values for each non-required key based on your use case.
.Net Native iOS

.Net Native iOS

.Net Native Android

.Net Native Android

MAUI

MAUI


SDK Keys

KeyDescriptionRequired
domaindata_urlThe URL of the application, which is always https://mobile-data.onetrust.io/bannersdk/v2/applicationdataYes
storageLocationThe CDN location for the JSON that the SDK fetches (usually, but not always, cdn.cookielaw.org).Yes
domainIdentifierThe application guid (retrieved from the OneTrust Admin console).Yes
languageCode2-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
apiVersionThe version of the scripts that have been published in OneTrust (eg. 6.11.0).Yes
countryCodeOverrideTwo-letter ISO 3166-2 country code.No
regionCodeOverrideTwo-letter state code, used alongside countryCode, typically used for CCPA use cases when providing an experience for California-based US citizens.No
identifierSets the identifier value used to create a user profile server-side.No
syncProfileTells initSDKData to attempt Cross Device Consent profile syncing.No
syncProfileAuthUse 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 NameDescription
OTUI_OnCloseFires whenever the UI should be dismissed. It is up to the application to actually dismiss the Frame with the OneTrustContentViewer.
OTUI_OnShowingBannerFires 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_OnShowingOtherFires 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_ClickedOnURLFires 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_DataIsReadyFires 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

  1. Once completed the steps above, run the MAUI / .Net application.
  2. Look at the console for any errors.
  3. Confirm the SDK has loaded properly. You will see !!! OT SDK READY !!! in the console log if everything is configured correctly.
  4. Once confirmed, go to the Displaying User Interfaces section for more information on showing Banner and Preference Center views.