> ## Documentation Index
> Fetch the complete documentation index at: https://developer.onetrust.com/llms.txt
> Use this file to discover all available pages before exploring further.

# When Consent Changes

You may subscribe to OneTrust SDK events to be notified when consent or another interaction occurs.

## Subscribe to Events

```c# C#
CMPSDK.sharedInstance.OneTrustEventsSubscription += SDK_Event_Handler;
```

## Example Event Handler

```c
// 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

[block:parameters]
{
  "data": {
    "h-0": "Event Name",
    "h-1": "Description",
    "0-0": "banner_reject_onClick",
    "0-1": "Activates when Banner > **Reject All** button is clicked.",
    "1-0": "banner_accept_onClick",
    "1-1": "Activates when Banner > **Accept All** button is clicked.",
    "2-0": "banner_closeButton_onClick",
    "2-1": "Activates when Banner > **Close** button is clicked.",
    "3-0": "vendor_rejectAll_onClick",
    "3-1": "Activates when Vendor List > **Reject All** button is clicked.",
    "4-0": "vendor_acceptAll_onClick",
    "4-1": "Activates when Vendor List > **Reject All **button is clicked.",
    "5-0": "vendor_saveChanges_onClick",
    "5-1": "Activates when Vendor List > **Confirm Choices** button is clicked.",
    "6-0": "prefCenter_rejectAll_onClick",
    "6-1": "Activates when Preference Center > **Reject All** button is clicked.",
    "7-0": "prefCenter_acceptAll_onClick",
    "7-1": "Activates when Preference Center > **Accept All **button is clicked.",
    "8-0": "prefCenter_saveChanges_onClick",
    "8-1": "Activates when Preference Center > **Confirm Choices** button is clicked.",
    "9-0": "cmp_vendorListDataAvail",
    "9-1": "Activates when vendor list data has downloaded successfully.",
    "10-0": "consentProfile_newValuesAvailable",
    "10-1": "Activates when the consent profile for the user has been updated.",
    "11-0": "cmp_uploadReceiptAvail",
    "11-1": "Activates when a consent receipt has been uploaded.<br><br> 📘** <span style=\"color:skyblue\">Note</span>**<br><br>This event is obsolete and will be removed in the future as the SDK is not saving the upload receipt.",
    "12-0": "cmp_unrecoverableError",
    "12-1": "Activates when a fatal error has occurred and five retries have taken place.",
    "13-0": "cmp_gotErrorButWillRetry",
    "13-1": "Activates when a network error has occurred but the SDK will attempt again.",
    "14-0": "cmp_TCFV2StringAvail",
    "14-1": "Activates when the **TCF v2** string has been updated.",
    "15-0": "cmp_IABTCF_AddtlConsentAvail",
    "15-1": "Activates when the **Google Additional Consent** string has been updated.",
    "16-0": "cmp_SDKConsentValuesChanged",
    "16-1": "Activates only when a user's interaction causes the SDK's consent status to change.",
    "17-0": "cmp_profileManagementWarning",
    "17-1": "Activates when any of the user profile conditions change."
  },
  "cols": 2,
  "rows": 18,
  "align": [
    null,
    null
  ]
}
[/block]

### SDKConsentValuesChanged Payload

```json JSON
{  
	"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

```json
{
  "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 provided 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** event handler.