When Consent Changes
You may subscribe to OneTrust SDK events to be notified when consent or another interaction occurs.
Subscribe to Events
CMPSDK.sharedInstance.OneTrustEventsSubscription += SDK_Event_Handler;
Example Event Handler
// optional onetrust global event handlers
private void SDK_Event_Handler(object sender, OneTrustEventArgs e)
{
switch (e.eventName)
{
case OneTrustEvent.EventNamesEnum.banner_reject_onClick: { } break;
case OneTrustEvent.EventNamesEnum.banner_accept_onClick: { } break;
case OneTrustEvent.EventNamesEnum.banner_closeButton_onClick: { } break;
case OneTrustEvent.EventNamesEnum.vendor_rejectAll_onClick: { } break;
case OneTrustEvent.EventNamesEnum.vendor_acceptAll_onClick: { } break;
case OneTrustEvent.EventNamesEnum.vendor_saveChanges_onClick: { } break;
case OneTrustEvent.EventNamesEnum.prefCenter_rejectAll_onClick: { } break;
case OneTrustEvent.EventNamesEnum.prefCenter_acceptAll_onClick: { } break;
case OneTrustEvent.EventNamesEnum.prefCenter_saveChanges_onClick: { } break;
case OneTrustEvent.EventNamesEnum.cmp_vendorListDataAvail: { } break;
case OneTrustEvent.EventNamesEnum.consentProfile_newValuesAvailable:
{
// Examples of some methods to call once this event fires (optional)
System.Diagnostics.Debug.WriteLine("***** UPDATED PROFILE ******");
JArray profile = CMPSDK.sharedInstance.getSavedConsentProfile();
System.Diagnostics.Debug.WriteLine(profile.ToString(Newtonsoft.Json.Formatting.Indented));
System.Diagnostics.Debug.WriteLine("***** IABUSPrivacy_String ******");
string ccpaString = Xamarin.Essentials.Preferences.Get("IABUSPrivacy_String", "");
System.Diagnostics.Debug.WriteLine("IABUSPrivacy_String: " + ccpaString);
System.Diagnostics.Debug.WriteLine("***** OneTrust_lastConsentDate UTC ******");
string OneTrust_lastConsentDate = Xamarin.Essentials.Preferences.Get("OneTrust_lastConsentDate", "0");
DateTime lastConsentDate = new DateTime(long.Parse(OneTrust_lastConsentDate));
System.Diagnostics.Debug.WriteLine(lastConsentDate.ToUniversalTime().ToString("F"));
}
break;
case OneTrustEvent.EventNamesEnum.cmp_uploadReceiptAvail: { } break;
case OneTrustEvent.EventNamesEnum.cmp_unrecoverableError:
{
//System.Diagnostics.Debug.WriteLine(e.exception.ToString());
//System.Diagnostics.Debug.WriteLine(e.eventPropertybag.ToString());
}
break;
case OneTrustEvent.EventNamesEnum.cmp_gotErrorButWillRetry:
{
//System.Diagnostics.Debug.WriteLine(e.exception.ToString());
//System.Diagnostics.Debug.WriteLine(e.eventPropertybag.ToString());
}
break;
case OneTrustEvent.EventNamesEnum.cmp_TCFV2StringAvail:
{
System.Diagnostics.Debug.WriteLine("***** TCFV2 String ******");
System.Diagnostics.Debug.WriteLine(e.eventPropertybag.ToString());
}
break;
case OneTrustEvent.EventNamesEnum.cmp_IABTCF_AddtlConsentAvail:
{
System.Diagnostics.Debug.WriteLine("***** cmp_IABTCF_AddtlConsent String ******");
System.Diagnostics.Debug.WriteLine(e.eventPropertybag.ToString());
}
break;
case OneTrustEvent.EventNamesEnum.cmp_SDKConsentValuesChanged:
{
JObject SDKsThatChanged = e.eventPropertybag;
System.Diagnostics.Debug.WriteLine("***** cmp_SDKConsentValuesChanged event ******");
System.Diagnostics.Debug.WriteLine(SDKsThatChanged.ToString(Newtonsoft.Json.Formatting.Indented));
}
break;
case OneTrustEvent.EventNamesEnum.cmp_profileManagementWarning:
{
// MSG ID's for Multi-profile
// 1000: Multi Profile Consent is disabled.Please enable Multi Profile Consent from OneTrust Admin.
// 1001: Max number of profiles already created. Please delete one of the profiles to be able to add a new one
// 1003: Deleted Active Profile for DSID, now switching to anonymous profile.
// 1004: Deleted Stored Profile for DSID.
// 1005: Stored Profile for DSID not found.Nothing to delete.
// 1006: Loading anonymous profile: DSID.
// 1007: Loading known user profile: DSID.
// 1008: Anonymous profile NOT found. Please pass a valid user ID to update.
// 1009: Two users cannot have the same user ID. Thus, pass a unique user ID.
// 1010: No user profile found with ID XXX.Please pass a valid user ID to update.
// 1011: Successfully renamed profile from DSID to DSID;
System.Diagnostics.Debug.WriteLine(e.eventPropertybag.ToString(Newtonsoft.Json.Formatting.Indented));
}
break;
default:
break;
}
}
Event Types
Event Name | Description |
---|---|
banner_reject_onClick | Activates when Banner > Reject All Button is tapped |
banner_accept_onClick | Activates when Banner > Accept All Button is tapped |
banner_closeButton_onClick | Activates when Banner > Close Button is tapped |
vendor_rejectAll_onClick | Activates when Vendor List > Reject All Button is tapped |
vendor_acceptAll_onClick | Activates when Vendor List > Reject All Button is tapped |
vendor_saveChanges_onClick | Activates when Vendor List > Confirm Choices Button is tapped |
prefCenter_rejectAll_onClick | Activates when Preference Center > Reject All Button is tapped |
prefCenter_acceptAll_onClick | Activates when Preference Center > Accept All Button is tapped |
prefCenter_saveChanges_onClick | Activates when Preference Center > Confirm Choices Button is tapped |
cmp_vendorListDataAvail | Activates when vendor list data has downloaded successfully |
consentProfile_newValuesAvailable | Activates when the consent profile for the user has been updated |
cmp_uploadReceiptAvail | Activates when a consent receipt has been uploaded |
cmp_unrecoverableError | Activates when a fatal error has occurred and we've re-tried 5 times |
cmp_gotErrorButWillRetry | Activates when a network error has occurred, but the SDK will attempt again |
cmp_TCFV2StringAvail | Activates when the TCF v2 string has been updated |
cmp_IABTCF_AddtlConsentAvail | Activates when the Google Additional Consent string has been updated |
cmp_SDKConsentValuesChanged | Activates only when a user's interaction causes SDK's consent status to change |
cmp_profileManagementWarning | Activates when any of the user profile conditions change. |
SDKConsentValuesChanged Payload
{
"sdk_status_changes": [
{
"sdk_SdkId": "04fdbe70-2650-401b-95d7-4ac00ed57c39",
"sdk_Name": "nsdk1",
"sdk_Description": "test",
"sdk_status": "active",
"parent_OptanonGroupId": "C0001",
"parent_GroupNameMobile": "Strictly Necessary Cookies",
"parent_Status": "active"
},
{
"sdk_SdkId": "f7359c72-17bf-4466-8977-64bef9e855f6",
"sdk_Name": "sdk114",
"sdk_Description": "TEST 1",
"sdk_status": "active",
"parent_OptanonGroupId": "C0001",
"parent_GroupNameMobile": "Strictly Necessary Cookies",
"parent_Status": "active"
}
]
}
profileManagementWarning Payload
{
"id": 1000,
"message": "Multi Profile Consent is disabled. Please enable Multi Profile Consent from OneTrust Admin."
}
profileManagmentWarning Message Codes
Id | Message |
---|---|
1000 | Multi Profile Consent is disabled.Please enable Multi Profile Consent from OneTrust Admin. |
1001 | Max number of profiles already created. Please delete one of the profiles to be able to add a new one |
1003 | Deleted Active Profile for DSID, now switching to anonymous profile. |
1004 | Deleted Stored Profile for DSID. |
1005 | Stored Profile for DSID not found. Nothing to delete. |
1006 | Loading anonymous profile: DSID. |
1007 | Loading known user profile: DSID. |
1008 | Anonymous profile NOT found. Please pass a valid user ID to update. |
1009 | Two users cannot have the same user ID. Thus, pass a unique user ID. |
1010 | No user profile found with ID XXX.Please pass a valid user ID to update. |
1011 | Successfully renamed profile from DSID to DSID; |
Querying for Consent
Use the following method to query for consent:
Method Name | Description |
---|---|
CMPSDK.sharedInstance.getConsentStatusForCategory(String categoryId); | Returns the consent status for the inputted category |
When querying for consent status, the status will be returned as an integer:
Value | Meaning |
---|---|
1 | Consent is given (An end user interacts with the SDK and gives consent. |
0 | Consent is not given (An end user interacts and does not give consent. |
-1 | Consent has not been collected (The SDK is not yet initialized for the end user OR there are no SDKs associated to this category) |
Listen for Consent Updates
To listen for consent updates, simply include the querying function inside of the consentProfile_newValuesAvailable
callback.
Updated 12 months ago