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:
                {
                    //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 = Microsoft.Maui.Storage.Preferences.Get(OTCoreConstants.CCPA_Key, "");
                    System.Diagnostics.Debug.WriteLine("IABUSPrivacy_String: " + ccpaString);

                    System.Diagnostics.Debug.WriteLine("***** OneTrust_lastConsentDate UTC ******");
                    string OneTrust_lastConsentDate = Microsoft.Maui.Storage.Preferences.Get("OneTrust_lastConsentDate", "0");
                    DateTime lastConsentDate = new DateTime(long.Parse(OneTrust_lastConsentDate));                  System.Diagnostics.Debug.WriteLine(lastConsentDate.ToUniversalTime().ToString("F"));               if (Microsoft.Maui.Storage.Preferences.ContainsKey("IABGPP_HDR_GppString"))
                    {
                        System.Diagnostics.Debug.WriteLine("***** IABGPP_HDR_GppString ******");
                        string gppString = Microsoft.Maui.Storage.Preferences.Get("IABGPP_HDR_GppString", "");
                        System.Diagnostics.Debug.WriteLine("IABGPP_HDR_GppString: " + gppString);

                        System.Diagnostics.Debug.WriteLine("***** IABGPP_HDR_Version ******");
                        int gppHdr = Microsoft.Maui.Storage.Preferences.Get("IABGPP_HDR_Version", 0);
                        System.Diagnostics.Debug.WriteLine("IABGPP_HDR_Version: " + gppHdr);

                        System.Diagnostics.Debug.WriteLine("***** IABGPP_HDR_Sections ******");
                        string gppHdrSections = Microsoft.Maui.Storage.Preferences.Get("IABGPP_HDR_Sections", "");
                        System.Diagnostics.Debug.WriteLine("IABGPP_HDR_Sections: " + gppHdrSections);

                        System.Diagnostics.Debug.WriteLine("***** IABGPP_GppSID ******");
                        string gppActiveSections = Microsoft.Maui.Storage.Preferences.Get("IABGPP_GppSID", "");
                        System.Diagnostics.Debug.WriteLine("IABGPP_GppSID: " + gppActiveSections);

                        var usnatString = Microsoft.Maui.Storage.Preferences.Get("IABGPP_7_String", null);
                        if (!string.IsNullOrEmpty(usnatString))
                        {
                            System.Diagnostics.Debug.WriteLine("***** IABGPP_7_String ******");
                            System.Diagnostics.Debug.WriteLine("IABGPP_7_String: " + usnatString);
                        }
                        var uscaString = Microsoft.Maui.Storage.Preferences.Get("IABGPP_8_String", null);
                        if (!string.IsNullOrEmpty(uscaString))
                        {
                            System.Diagnostics.Debug.WriteLine("***** IABGPP_8_String ******");
                            System.Diagnostics.Debug.WriteLine("IABGPP_8_String: " + uscaString);
                        }
                        var usvaString = Microsoft.Maui.Storage.Preferences.Get("IABGPP_9_String", null);
                        if (!string.IsNullOrEmpty(usvaString))
                        {
                            System.Diagnostics.Debug.WriteLine("***** IABGPP_9_String ******");
                            System.Diagnostics.Debug.WriteLine("IABGPP_9_String: " + usvaString);
                        }
                        var uscoString = Microsoft.Maui.Storage.Preferences.Get("IABGPP_10_String", null);
                        if (!string.IsNullOrEmpty(uscoString))
                        {
                            System.Diagnostics.Debug.WriteLine("***** IABGPP_10_String ******");
                            System.Diagnostics.Debug.WriteLine("IABGPP_10_String: " + uscoString);
                        }
                        var usutString = Microsoft.Maui.Storage.Preferences.Get("IABGPP_11_String", null);
                        if (!string.IsNullOrEmpty(usutString))
                        {
                            System.Diagnostics.Debug.WriteLine("***** IABGPP_11_String ******");
                            System.Diagnostics.Debug.WriteLine("IABGPP_11_String: " + usutString);
                        }
                        var usctString = Microsoft.Maui.Storage.Preferences.Get("IABGPP_12_String", null);
                        if (!string.IsNullOrEmpty(usctString))
                        {
                            System.Diagnostics.Debug.WriteLine("***** IABGPP_12_String ******");
                            System.Diagnostics.Debug.WriteLine("IABGPP_12_String: " + usctString);
                        }
                    }

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

            default:
                break;
        }
    } 

Event Types

Event NameDescription
banner_reject_onClickActivates when Banner > Reject All button is clicked.
banner_accept_onClickActivates when Banner > Accept All button is clicked.
banner_closeButton_onClickActivates when Banner > Close button is clicked.
vendor_rejectAll_onClickActivates when Vendor List > Reject All button is clicked.
vendor_acceptAll_onClickActivates when Vendor List > Reject All button is clicked.
vendor_saveChanges_onClickActivates when Vendor List > Confirm Choices button is clicked.
prefCenter_rejectAll_onClickActivates when Preference Center > Reject All button is clicked.
prefCenter_acceptAll_onClickActivates when Preference Center > Accept All button is clicked.
prefCenter_saveChanges_onClickActivates when Preference Center > Confirm Choices button is clicked.
cmp_vendorListDataAvailActivates when vendor list data has downloaded successfully.
consentProfile_newValuesAvailableActivates when the consent profile for the user has been updated.
cmp_uploadReceiptAvailActivates when a consent receipt has been uploaded.
cmp_unrecoverableErrorActivates when a fatal error has occurred and a five retries have taken place.
cmp_gotErrorButWillRetryActivates when a network error has occurred and the SDK will attempt again.
cmp_TCFV2StringAvailActivates when the TCF v2 string has been updated.
cmp_IABTCF_AddtlConsentAvailActivates when the Google Additional Consent string has been updated.
cmp_SDKConsentValuesChangedActivates only when a user's interaction causes the SDK's consent status to change.
cmp_profileManagementWarningActivates 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

IdMessage
1000Multi Profile Consent is disabled. Please enable Multi Profile Consent from OneTrust Admin.
1001Max number of profiles already created. Please delete one of the profiles to be able to add a new one.
1003Deleted Active Profile for DSID, now switching to anonymous profile.
1004Deleted Stored Profile for DSID.
1005Stored Profile for DSID not found. Nothing to delete.
1006Loading anonymous profile: DSID.
1007Loading known user profile: DSID.
1008Anonymous profile NOT found. Please pass a valid user ID to update.
1009Two users cannot have the same user ID. Thus, pass a unique user ID.
1010No user profile found with ID XXX. Please pass a valid user ID to update.
1011Successfully renamed profile from DSID to DSID.

Querying for Consent

Use the following method to query for consent:

Method NameDescription
CMPSDK.sharedInstance.getConsentStatusForCategory(String categoryId);Returns the consent status for the provided category.

When querying for consent status, the status will be returned as an integer:

ValueMeaning
1Consent is given (An end-user interacts with the SDK and gives consent.)
0Consent is not given (An end-user interacts and does not give consent.)
-1Consent 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 event handler.