# Reference

This section is a comprehensive reference of the methods and events exposed by the Unity SDK that you can leverage in your application.

Always use `Didomi.GetInstance()` to get a reference to the Didomi SDK. Also make sure to always call the SDK after it is fully initialized (see [OnReady](https://developers.didomi.io/cmp/mobile-sdk/unity-sdk/reference#onready))

## AddEventListener

Add an event listener to catch events triggered by the SDK. Events listeners allow you to react to different events of interest. This function is safe to call before the `Ready` event has been triggered.

{% hint style="warning" %}
At the moment, on iOS, only one event listener is supported at the same time. If additional callbacks are required, they should be appended to the event handlers as in the example below.
{% endhint %}

**Requires SDK to be initialized**

No.

**Parameters**

| Name          | Type                  | Description                                                                                                                  |
| ------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| eventListener | `DidomiEventListener` | The event listener. An instance or a subclass of `DidomiEventListener`. Contains handlers for the different possible events. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

<pre class="language-java"><code class="lang-java">   
    private void RegisterEventHandlers()
    {
        DidomiEventListener eventListener = new DidomiEventListener();
        eventListener.ConsentChanged += EventListener_ConsentChanged;
        eventListener.Ready += EventListener_Ready;
        eventListener.ShowNotice += EventListener_ShowNotice;
        eventListener.HideNotice += EventListener_HideNotice;
        eventListener.NoticeClickAgree += EventListener_NoticeClickAgree;
        eventListener.NoticeClickMoreInfo += EventListener_NoticeClickMoreInfo;
        eventListener.NoticeClickViewSPIPurposes += EventListener_NoticeClickViewSPIPurposes;
        eventListener.PreferencesClickAgreeToAll += EventListener_PreferencesClickAgreeToAll;
        eventListener.PreferencesClickDisagreeToAll += EventListener_PreferencesClickDisagreeToAll;
        eventListener.PreferencesClickViewVendors += EventListener_PreferencesClickViewVendors;
        eventListener.PreferencesClickViewSPIPurposes += EventListener_PreferencesClickViewSPIPurposes;
        eventListener.PreferencesClickSaveChoices += EventListener_PreferencesClickSaveChoices;
        eventListener.PreferencesClickPurposeAgree += EventListener_PreferencesClickPurposeAgree;
        eventListener.PreferencesClickPurposeDisagree += EventListener_PreferencesClickPurposeDisagree;
        eventListener.PreferencesClickCategoryAgree += EventListener_PreferencesClickCategoryAgree;
        eventListener.PreferencesClickCategoryDisagree += EventListener_PreferencesClickCategoryDisagree;
        eventListener.PreferencesClickSPIPurposeAgree += EventListener_PreferencesClickSPIPurposeAgree;
        eventListener.PreferencesClickSPIPurposeDisagree += EventListener_PreferencesClickSPIPurposeDisagree;
        eventListener.PreferencesClickSPICategoryAgree += EventListener_PreferencesClickSPICategoryAgree;
        eventListener.PreferencesClickSPICategoryDisagree += EventListener_PreferencesClickSPICategoryDisagree;
        eventListener.PreferencesClickSPIPurposeSaveChoices += EventListener_PreferencesClickSPIPurposeSaveChoices;
        eventListener.PreferencesClickVendorAgree += EventListener_PreferencesClickVendorAgree;
        eventListener.PreferencesClickVendorDisagree += EventListener_PreferencesClickVendorDisagree;
        eventListener.PreferencesClickVendorSaveChoices += EventListener_PreferencesClickVendorSaveChoices;
        eventListener.HidePreferences += EventListener_HidePreferences;
        eventListener.ShowPreferences += EventListener_ShowPreferences;
        eventListener.SyncReady += EventListener_SyncReady;
<strong>        eventListener.SyncDone += EventListener_SyncDone;
</strong>        eventListener.SyncError += EventListener_SyncError;
        eventListener.LanguageUpdated += EventListener_LanguageUpdated;
        eventListener.LanguageUpdateFailed += EventListener_LanguageUpdateFailed;

        Didomi.GetInstance().AddEventListener(eventListener);
    }

    private void EventListener_ConsentChanged(object sender, ConsentChangedEvent e)
    {
        // The consent status of the user has changed
    }
    
    private void EventListener_Ready(object sender, ReadyEvent e)
    {
        // The Didomi SDK is ready
    }

    private void EventListener_ShowNotice(object sender, ShowNoticeEvent e)
    {
        // The notice is being shown or needs to be shown
    }
    
   private void EventListener_HideNotice(object sender, HideNoticeEvent e)
    {
        // The notice is being hidden
    }
    
    private void EventListener_NoticeClickAgree(object sender, NoticeClickAgreeEvent e)
    {
        // Click on agree on notice
    }

    private void EventListener_NoticeClickMoreInfo(object sender, NoticeClickMoreInfoEvent e)
    {
        // Click on learn more on notice
    }
    
    private void EventListener_NoticeClickViewSPIPurposes(object sender, NoticeClickViewSPIPurposesEvent e)
    {
        // Click on "Limit the use of my Sensitive Personal Information" on notice
    }
    
    private void EventListener_PreferencesClickAgreeToAll(object sender, PreferencesClickAgreeToAllEvent e)
    {
        // Click on agree to all on preferences popup
    }
    
    private void EventListener_PreferencesClickDisagreeToAll(object sender, PreferencesClickDisagreeToAllEvent e)
    {
        // Click on disagree to all on preferences popup
    }
  
    private void EventListener_PreferencesClickViewSPIPurposes(object sender, PreferencesClickViewSPIPurposesEvent e)
    {
        // Click on "Limit the use of my Sensitive Personal Information" on preferences screen
    }
      
    private void EventListener_PreferencesClickViewVendors(object sender, PreferencesClickViewVendorsEvent e)
    {
        // Click view vendors on purposes view on preferences popup
    }
    
    private void EventListener_PreferencesClickSaveChoices(object sender, PreferencesClickSaveChoicesEvent e)
    {
        // Click on save on the purposes view on preferences popup
    }
    
    private void EventListener_PreferencesClickPurposeAgree(object sender, PreferencesClickPurposeAgreeEvent e)
    {
        // Click on agree to a purpose on preferences popup
    }
    
    private void EventListener_PreferencesClickPurposeDisagree(object sender, PreferencesClickPurposeDisagreeEvent e)
    {
        // Click on disagree to a purpose on preferences popup
    }
    
    private void EventListener_PreferencesClickCategoryAgree(object sender, PreferencesClickCategoryAgreeEvent e)
    {
        // Click on agree to a purposes category on preferences popup
    }
    
    private void EventListener_PreferencesClickCategoryDisagree(object sender, PreferencesClickCategoryDisagreeEvent e)
    {
        // Click on disagree to a purposes category on preferences popup
    }
    
    private void EventListener_PreferencesClickSPIPurposeAgree(object sender, PreferencesClickSPIPurposeAgreeEvent e)
    {
        // Click on agree to a purpose on sensitive personal information screen
    }
    
    private void EventListener_PreferencesClickSPIPurposeDisagree(object sender, PreferencesClickSPIPurposeDisagreeEvent e)
    {
        // Click on disagree to a purpose on sensitive personal information screen
    }
    
    private void EventListener_PreferencesClickSPICategoryAgree(object sender, PreferencesClickSPICategoryAgreeEvent e)
    {
        // Click on agree to a purposes category on sensitive personal information screen
    }
    
    private void EventListener_PreferencesClickCategoryDisagree(object sender, PreferencesClickSPICategoryDisagreeEvent e)
    {
        // Click on disagree to a purposes category on sensitive personal information screen
    }
    
    private void EventListener_PreferencesClickSPIPurposeSaveChoices(object sender, PreferencesClickSPIPurposeSaveChoicesEvent e)
    {
        // Click on save on the sensitive personal information screen
    }

    private void EventListener_PreferencesClickVendorAgree(object sender, PreferencesClickVendorAgreeEvent e)
    {
        // Click on agree to a vendor on preferences popup
    }

    private void EventListener_PreferencesClickVendorDisagree(object sender, PreferencesClickVendorDisagreeEvent e)
    {
        // Click on disagree to a vendor on preferences popup
    }
    
    private void EventListener_PreferencesClickVendorSaveChoices(object sender, PreferencesClickVendorSaveChoicesEvent e)
    {
        // Click on save on the vendors view on preferences popup
    }
    
    private void EventListener_ShowPreferences(object sender, ShowPreferencesEvent e)
    {
        // The preferences screen is being shown
    }
    
    private void EventListener_HidePreferences(object sender, HidePreferencesEvent e)
    {
        // The preferences screen is being hidden
    }
    
    private void EventListener_SyncReady(object sender, SyncReadyEvent e)
    {
        // Synchronization process is complete
    }
    
    private void EventListener_SyncDone(object sender, SyncDoneEvent e)
    {
        // Synchronization was done successfully
    }
    
    private void EventListener_SyncError(object sender, SyncErrorEvent e)
    {
        // An error occurred during synchronization
    }
    
    private void EventListener_LanguageUpdated(object sender, LanguageUpdatedEvent e)
    {
        // Language update was completed
    }
    
    private void EventListener_LanguageUpdateFailed(object sender, LanguageUpdateFailedEvent e)
    {
        // Language update was not completed
    }

    
</code></pre>

{% endtab %}
{% endtabs %}

**Event types**

The following events are supported by the Didomi SDK:

| Event                                      | Description                                                                                                                                                                                                  |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ConsentChangedEvent                        | When a consent is given or withdrawn by the user. Only triggered when the consent status actually changes (ie if the user saves consents without adding/removing any consent then this does not get called). |
| HideNoticeEvent                            | When the consent notice is hidden. If you have disabled our default consent notice to replace it with your own, you need to hide your custom notice when this event gets triggered.                          |
| ShowNoticeEvent                            | When the consent notice gets displayed. If you have disabled our default consent notices to replace them with your own, you need to show your custom notice when this event gets triggered.                  |
| NoticeClickAgreeEvent                      | When user clicks on agree on the notice                                                                                                                                                                      |
| NoticeClickMoreInfoEvent                   | When user clicks on learn more on the notice                                                                                                                                                                 |
| NoticeClickViewSPIPurposesEvent            | When user clicks on "Limit the use of my personal information" on the notice                                                                                                                                 |
| PreferencesClickAgreeToAllEvent            | When user clicks on agree to all on the preferences popup                                                                                                                                                    |
| PreferencesClickDisagreeToAllEvent         | When user clicks on disagree to all on the preferences popup                                                                                                                                                 |
| PreferencesClickPurposeAgreeEvent          | When user agrees to a purpose on the preferences popup. (`purposeId` provided as a parameter)                                                                                                                |
| PreferencesClickPurposeDisagreeEvent       | When user disagrees to a purpose on the preferences popup. (`purposeId` provided as a parameter)                                                                                                             |
| PreferencesClickCategoryAgreeEvent         | When user agrees to a purposes category on the preferences popup. (`categoryId` provided as a parameter)                                                                                                     |
| PreferencesClickCategoryDisagreeEvent      | When user disagrees to a purposes category on the preferences popup. (`categoryId` provided as a parameter)                                                                                                  |
| PreferencesClickViewSPIPurposesEvent       | When user clicks on "Limit the use of my personal information" on the preferences popup                                                                                                                      |
| PreferencesClickViewVendorsEvent           | When user clicks on view vendors on the preferences popup                                                                                                                                                    |
| PreferencesClickSaveChoicesEvent           | When user saves his choice on the preferences popup                                                                                                                                                          |
| PreferencesClickSPIPurposeAgreeEvent       | When user agrees to a purpose on the sensitive personal information screen. (`purposeId` provided as a parameter)                                                                                            |
| PreferencesClickSPIPurposeDisagreeEvent    | When user disagrees to a purpose on the sensitive personal information screen. (`purposeId` provided as a parameter)                                                                                         |
| PreferencesClickSPICategoryAgreeEvent      | When user agrees to a purposes category on the sensitive personal information screen. (`categoryId` provided as a parameter)                                                                                 |
| PreferencesClickSPICategoryDisagreeEvent   | When user disagrees to a purposes category on the sensitive personal information screen. (`categoryId` provided as a parameter)                                                                              |
| PreferencesClickSPIPurposeSaveChoicesEvent | When user saves his choice on the sensitive personal information screen                                                                                                                                      |
| PreferencesClickVendorAgreeEvent           | When user agrees to a vendor on the preferences popup. (`vendorId` provided as a parameter)                                                                                                                  |
| PreferencesClickVendorDisagreeEvent        | When user disagrees to a vendor on the preferences popup. (`vendorId` provided as a parameter)                                                                                                               |
| PreferencesClickVendorSaveChoicesEvent     | When user saves his choice on the vendors view on the preferences popup                                                                                                                                      |
| HidePreferencesEvent                       | When preferences screen is hidden                                                                                                                                                                            |
| ShowPreferencesEvent                       | When preferences screen is shown                                                                                                                                                                             |
| SyncReadyEvent                             | <p>When synchronization is complete.</p><p>Provides the methods <code>GetOrganizationUserId</code>, <code>IsStatusApplied</code> and <code>SyncAcknowledged</code> (see below)</p>                           |
| `SyncReadyEvent.OrganizationUserId`        | `organizationUserId` of the user that was synchronized                                                                                                                                                       |
| `SyncReadyEvent.IsStatusApplied`           | `bool` indicating whether the user status was applied                                                                                                                                                        |
| `SyncReadyEvent.SyncAcknowledged`          | Function that triggers a `sync.acknowledged` API event when called. It returns `true` if the API event was sent successfully.                                                                                |
| SyncDoneEvent                              | <p><strong>Deprecated, use <code>SyncReady</code> instead.</strong></p><p>When synchronization is complete (synchronized <code>organizationUserId</code> provided as parameter)</p>                          |
| SyncErrorEvent                             | When synchronization encountered an error (`errorMessage` provided as parameter)                                                                                                                             |
| LanguageUpdatedEvent                       | When selected language update was completed (selected `languageCode` provided as parameter)                                                                                                                  |
| LanguageUpdateFailedEvent                  | When language selection update was not able to complete (`reason` provided as parameter)                                                                                                                     |

## addVendorStatusListener <a href="#addvendorstatuslistener" id="addvendorstatuslistener"></a>

Listen for changes on the user status linked to a specific vendor.

{% hint style="warning" %}
At the moment, on iOS, only one listener per vendor is supported at the same time. If additional callbacks are required, they should be appended to the vendor status listener handler, as in the example below.
{% endhint %}

**Requires SDK to be initialized**

No.

**Parameters**

| Name                 | Type                         | Description                                                                                                                                                                                                                           |
| -------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| vendorId             | `string`                     | <p>The ID of the vendor for which we want to start listening for changes.</p><p>This ID should be the ID provided by Didomi, which doesn't contain prefixes.</p>                                                                      |
| vendorStatusListener | `DidomiVendorStatusListener` | <p>An instance or a subclass of <code>DidomiVendorStatusListener</code>. Contains a handler called when vendor status is changed.</p><p>When this callback is executed, the status linked to the specified vendor will be passed.</p> |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

<pre class="language-csharp"><code class="lang-csharp"><strong>private void RegisterVendorStatusListener()
</strong><strong>{
</strong>    DidomiVendorStatusListener vendorStatusListener = new DidomiVendorStatusListener();
    vendorStatusListener.VendorStatusChanged += VendorStatusListener_VendorStatusChanged;
    Didomi.GetInstance().AddVendorStatusListener("vendor1", vendorStatusListener);
}

private void VendorStatusListener_VendorStatusChanged(object sender, CurrentUserStatus.VendorStatus status)
{
    Debug.Log(status.Id + "status has changed: " + status.Enabled);
}
</code></pre>

{% endtab %}
{% endtabs %}

## removeVendorStatusListener <a href="#removevendorstatuslistener" id="removevendorstatuslistener"></a>

Stop listening for changes on the user status linked to a specific vendor.

**Requires SDK to be initialized**

No.

**Parameters**

| Name     | Type     | Description                                                                                                                                                     |
| -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| vendorId | `string` | <p>The ID of the vendor for which we want to stop listening for changes.</p><p>This ID should be the ID provided by Didomi, which doesn't contain prefixes.</p> |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```csharp
Didomi.GetInstance().RemoveVendorStatusListener("vendor1");
```

{% endtab %}
{% endtabs %}

## DisableMockUI

Disable or enable the mock UI when testing in Unity Editor.

{% hint style="warning" %}
**Android and iOS platform builds**

This function has no effect for iOS or Android platform builds. It can safely be called in all environments and will only impact the Unity Editor.
{% endhint %}

**Requires SDK to be initialized**

No

**Parameters**

| Name    | Type      | Description                   |
| ------- | --------- | ----------------------------- |
| disable | `boolean` | `true` to disable the mock UI |

**Returns**

No return value

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().DisableMockUI(true);
```

{% endtab %}
{% endtabs %}

## GetJavaScriptForWebView

Get JavaScript to embed into a WebView to pass the consent status from the app to the Didomi Web SDK embedded into the WebView.

Inject the returned tag into a WebView with `evaluateJavaScript`.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

| Type     | Description                           |
| -------- | ------------------------------------- |
| `string` | JavaScript code to embed in a WebView |

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetJavaScriptForWebView();
```

{% endtab %}
{% endtabs %}

## GetPurpose

Get a purpose based on its ID.

{% hint style="warning" %}
**Not available for IOS platform builds**

This function is only exposed to Unity Android platform builds. It cannot be called from Unity IOS platform builds.
{% endhint %}

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name      | Type     | Description                       |
| --------- | -------- | --------------------------------- |
| purposeId | `string` | ID of the purpose we want to get. |

**Returns**

| Type      | Description                                                              |
| --------- | ------------------------------------------------------------------------ |
| `Purpose` | A `Purpose` with ID `purposeId` found in the array of required purposes. |

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetPurpose("purpose-id");
```

{% endtab %}
{% endtabs %}

## GetRequiredPurposes

Get the list of purpose that are required (automatically determined from the list of required vendors).

{% hint style="warning" %}
**Not available for IOS platform builds**

This function is only exposed to Unity Android platform builds. It cannot be called from Unity IOS platform builds.
{% endhint %}

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

| Type            | Description                                               |
| --------------- | --------------------------------------------------------- |
| `ISet<Purpose>` | A set of type `Purpose` containing the required purposes. |

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetRequiredPurposes();
```

{% endtab %}
{% endtabs %}

## GetRequiredPurposeIds

Get the list of purpose IDs that are required (automatically determined from the list of required vendors).

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

| Type           | Description                                                     |
| -------------- | --------------------------------------------------------------- |
| `ISet<string>` | A set of type `string` containing the IDs of required purposes. |

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetRequiredPurposeIds();
```

{% endtab %}
{% endtabs %}

## GetRequiredVendors

Get the list of vendors that are required (determined from the configuration).

{% hint style="warning" %}
**Not available for IOS platform builds**

This function is only exposed to Unity Android platform builds. It cannot be called from Unity IOS platform builds.
{% endhint %}

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

| Type           | Description                                             |
| -------------- | ------------------------------------------------------- |
| `ISet<Vendor>` | A set of type `Vendor` containing the required vendors. |

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetRequiredVendors();
```

{% endtab %}
{% endtabs %}

## GetRequiredVendorIds

Get the list of vendor IDs that are required (determined from the configuration).

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

| Type           | Description                                                    |
| -------------- | -------------------------------------------------------------- |
| `ISet<string>` | A set of type `string` containing the IDs of required vendors. |

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetRequiredVendorIds();
```

{% endtab %}
{% endtabs %}

## GetText

Method used to get a dictionary/map based on the key being passed. These keys and texts are extracted from the notice content, preferences content and the `texts` property specified in the `didomi_config.json` file as described here <https://developers.didomi.io/cmp/mobile-sdk/consent-notice/customize-the-theme#translatable-texts-for-custom-notices>.

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name | Type   | Description                                           |
| ---- | ------ | ----------------------------------------------------- |
| key  | string | key associated to the dictionary that we want to get. |

**Returns**

| Type                        | Description                                                                                                                                             |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| IDictionary\<string,string> | Dictionary containing the translations for an specific key in different languages, with the form { "en:" "text in English", "fr": "texte en Français" } |

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetText("key");
```

{% endtab %}
{% endtabs %}

## GetTranslatedText

Method used to get a translated text based on the key being passed.

The language and the source of this translated text will depend on the availability of the translation for the specific key.

The language being used will be either the selected language of the SDK (based on device Locale and other parameters) or the language specified by app developers as the default language being used by the SDK. The source can be either the `didomi_config.json` file, which can be either local or remote, or a file that is bundled within the SDK.

These are the attempts performed by the SDK to try to find a translation for the specific key:

* Get translated value in user locale (selected language) from `didomi_config.json` (either local or remote).
* Get translated value in default locale (from the config) from `didomi_config.json` (either local or remote).
* Get translated value in user locale (selected language) from the Didomi-provided translations (bundled within the Didomi SDK).
* Get translated value in default locale (from the config) from the Didomi-provided translations (bundled within the Didomi SDK).

If no translation can be found after these 4 attempts, the key will be returned.

App developers can provide these translated texts through the `didomi_config.json` file (locally or remotely) in 3 different ways:

* Custom texts for the consent notice: <https://developers.didomi.io/cmp/mobile-sdk/consent-notice/customize-the-notice#texts>
* Custom texts for the preferences: <https://developers.didomi.io/cmp/mobile-sdk/consent-notice/customize-the-preferences-popup#text>
* Custom texts for custom notices: <https://developers.didomi.io/cmp/mobile-sdk/consent-notice/customize-the-theme#translatable-texts-for-custom-notices>

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name | Type   | Description                                                |
| ---- | ------ | ---------------------------------------------------------- |
| key  | string | key associated to the text that we want to get translated. |

**Returns**

Translated text.

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetTranslatedText("key");
```

{% endtab %}
{% endtabs %}

## GetCurrentUserStatus

Exposes the user status for the current regulation that applies.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameters.

**Returns**

The user status containing the computed global status for Vendors and purposes:

* A vendor's global status is enabled, if and only if:
  * the vendor is enabled directly in the vendors layer in all legal basis
  * **AND** all its related purposes are enabled or essential.
* A purpose's global status is enabled in one of the two conditions:
  * the purpose is enabled for all the legal basis that it is configured for.
  * **OR** when the purpose is essential.

| Parameter         | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ----------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| didomiDcs         | `string` | Didomi Consent String that stores end-user choices for custom and Google ATP vendors, and custom and global purposes across all regulations. [Click here](/cmp/didomi-consent-string.md) for more information.                                                                                                                                                                                                                          |
| Vendors           | `object` | <ul><li>Dictionary that maps the ID of a vendor to an object representing its status.</li><li>The IDs used in this dictionary correspond to the Didomi IDs i.e.: without the <code>c:</code> or any other prefix.</li><li>Vendors with undefined user status are included in the response with <code>enabled: false.</code></li><li>Vendors with ONLY essential purposes are automatically set with <code>enable: true</code></li></ul> |
| Purposes          | `object` | <ul><li>Dictionary that maps the ID of a purpose to an object representing its status.</li><li>Purposes with undefined user status are included in the response with <code>enabled: false.</code></li><li>Essential purposes are automatically set with <code>enable: true</code></li></ul>                                                                                                                                             |
| Regulation        | `String` | <ul><li>Representation of the current regulation as a <code>Regulation</code> enum value, such as <code>GDPR</code>, <code>CCPA</code>, <code>CPRA</code>, or <code>NONE</code>.</li><li>Note that some regulations present as enum values are not available yet.</li></ul>                                                                                                                                                             |
| UserId            | `String` | Didomi user id.                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Created           | `String` | User choices creation date.                                                                                                                                                                                                                                                                                                                                                                                                             |
| Updated           | `String` | User choices update date.                                                                                                                                                                                                                                                                                                                                                                                                               |
| ConsentString     | `String` | TCF consent as string                                                                                                                                                                                                                                                                                                                                                                                                                   |
| AdditionalConsent | `String` | Additional consent.                                                                                                                                                                                                                                                                                                                                                                                                                     |
| GppString         | `String` | GPP string.                                                                                                                                                                                                                                                                                                                                                                                                                             |

**Throws**

<table data-header-hidden><thead><tr><th width="334">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>Type</strong></td><td>Description</td></tr><tr><td>DidomiNotReadyException</td><td>Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the <code>onReady</code> method.</td></tr></tbody></table>

**Example**

{% tabs %}
{% tab title="C#" %}

```csharp
Didomi.GetInstance().GetCurrentUserStatus();
```

{% endtab %}
{% endtabs %}

## GetVendor

Get a vendor based on its ID.

{% hint style="warning" %}
**Not available for IOS platform builds**

This function is only exposed to Unity Android platform builds. It cannot be called from Unity IOS platform builds.
{% endhint %}

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name     | Type     | Description                      |
| -------- | -------- | -------------------------------- |
| vendorId | `string` | ID of the vendor we want to get. |

**Returns**

| Type     | Description                                                           |
| -------- | --------------------------------------------------------------------- |
| `Vendor` | A `Vendor` with ID `vendorId` found in the array of required vendors. |

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().GetVendor("vendor-id");
```

{% endtab %}
{% endtabs %}

## HideNotice

Hide the consent notice.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().HideNotice();
```

{% endtab %}
{% endtabs %}

## HidePreferences

Hide the preferences popup.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().HidePreferences();
```

{% endtab %}
{% endtabs %}

## Initialize

Initialize the SDK. The initialization runs on a background thread to avoid blocking your UI. Use the [onReady](/cmp/mobile-sdk/ios/reference/api.md#onready) function to know when the initialization is done and the SDK is ready to be used.

**Parameters**

<table data-header-hidden><thead><tr><th width="319">Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Description</td></tr><tr><td>initializeParameters</td><td>DidomiInitializeParameters</td><td>Object containing the application parameters, see below</td></tr></tbody></table>

The **DidomiInitializeParameters** object contains all the information needed to initialize the SDK.

{% hint style="warning" %}
The parameter `disableDidomiRemoteConfig` is deprecated, we strongly suggest you to create your notice from the console (see [Setup from the Console](/cmp/mobile-sdk/unity-sdk/setup.md#from-the-console-recommended) for more information).
{% endhint %}

| Name                                       | Type   | Optional | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------------------------------ | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| apiKey                                     | string | No       | Your API key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| localConfigurationPath                     | string | Yes      | The path to your local config file in your `assets/` folder. Defaults to `didomi_config.json` if null.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| remoteConfigurationURL                     | string | Yes      | The URL to a remote configuration file to load during initialization. When provided, the file at the URL will be downloaded and cached to be used instead of the local `assets/didomi_config.json`. If there is no Internet connection available and no previously cached file, the local file will be used as fallback.                                                                                                                                                                                                                                                 |
| providerId                                 | string | Yes      | Your provider ID (if any). A provider ID is assigned when you work with Didomi through a third-party. If are not sure if you have one, set this to `null`.                                                                                                                                                                                                                                                                                                                                                                                                               |
| disableDidomiRemoteConfig (deprecated)     | bool   | Yes      | <p>Prevent the SDK from loading a remote configuration from the Didomi Console. Defaults to <code>false</code> (allows loading remote config).</p><p>Set this parameter to <code>false</code> to use a remote consent notice configuration loaded from the Didomi Console.</p><p>Set this parameter to <code>true</code> to disable loading configurations from the Didomi Console.</p>                                                                                                                                                                                  |
| languageCode                               | string | Yes      | Language in which the consent UI should be displayed. By default, the consent UI is displayed in the language configured in the device settings. This property allows you to override the default setting and specify a language to display the UI in. String containing the language code e.g.: `"es"`, `"fr"`, `"en-US"`*,* `"zh-HK"`, etc.                                                                                                                                                                                                                            |
| noticeId                                   | string | Yes      | Notice ID to load the configuration from. If provided, the SDK bypasses the app ID targeting and directly loads the configuration from the notice ID.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| tvNoticeId (only used on Android TV        | string | Yes      | TV notice ID to load the configuration from. If provided and SDK is initialized on Android TV, the SDK bypasses the app ID targeting and directly loads the configuration from the notice ID.                                                                                                                                                                                                                                                                                                                                                                            |
| androidTvEnabled (only used on Android TV) | bool   | Yes      | <p>Enable the Android TV SDK. Defaults to <code>false</code> (Android TV is not enabled).</p><p>This parameter will be checked if sdk is initialized from a TV device.</p><p>If set to <code>false</code>, the sdk initialization will fail with an error.</p><p>If set to <code>true</code>, the sdk will try to initialize in TV mode, using the API key and the optional <code>tvNoticeId</code> parameter.</p><p>Please note that the TV notice option must be enabled on Didomi side. Please reach out to your dedicated customer success manager to know more.</p> |
| countryCode                                | string | Yes      | <p>Override user country code when determining the privacy regulation to apply.</p><p>Keep <code>null</code> to let the Didomi SDK determine the user country.</p>                                                                                                                                                                                                                                                                                                                                                                                                       |
| regionCode                                 | string | Yes      | <p>Override user region code when determining the privacy regulation to apply.</p><p>Keep <code>null</code> to let the Didomi SDK determine the user region.</p><p>Ignored if countryCode is not set.</p>                                                                                                                                                                                                                                                                                                                                                                |
| isUnderage                                 | bool   | Yes      | Whether the user is underage or not. Defaults to `False`. This parameters can only be used if the Underage feature has been configured in your notice. (Underage is currently in beta version).                                                                                                                                                                                                                                                                                                                                                                          |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
 Didomi.GetInstance().Initialize(
     new DidomiInitializeParameters(
          apiKey: "<Your API key>",
          localConfigurationPath: null,
          remoteConfigurationURL: null,
          providerId: null,
          disableDidomiRemoteConfig: false,
          languageCode: null,
          noticeId: "<Your notice Id>",
          tvNoticeId: null,
          androidTvEnabled: false
));
```

{% endtab %}
{% endtabs %}

## IsConsentRequired

Determine if consent is required for the user. This takes into account the location of the user and the configuration of the SDK:

* If your app is configured to apply GDPR to all users then this function always returns `true`.
* If your app is configured to apply GDPR to EU users only then this function returns `true` only if the user in the EU.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().IsConsentRequired();
```

{% endtab %}
{% endtabs %}

## IsUserConsentStatusPartial

Determine if all consent information is available for the user.

This function returns `true` if and only if:

* Consent is required for the user (ie the user is in the EU or your tag is configured to apply GDPR to all users)
* At least one vendor is configured (if there is no vendor configured, this function always returns `false` as there is no consent to collect)
* We miss consent information for some vendors or purposes

If there is at least one piece of consent information missing for a single vendor/purpose, this function will return `true`. The consent notice is usually displayed when this function returns `true` although there is no guarantee of the direct mapping between the two.

An important edge case is when you add new vendors or if configured vendors ask for new purposes: the consent notice will be displayed again and this function will return `true` until the user has given or denied consent. Vendors that already had consent before will still operate normally as we only recollect consent for additional vendors/purposes.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().IsUserConsentStatusPartial();
```

{% endtab %}
{% endtabs %}

## IsUserStatusPartial

Determine if the user has provided a choice for all vendors selected for the regulation and linked data processing.

This function returns `true` if the user has not expressed a choice for all the required vendors and data processing.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().IsUserStatusPartial();
```

{% endtab %}
{% endtabs %}

## IsNoticeVisible

Check if the consent notice is currently displayed.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().IsNoticeVisible();
```

{% endtab %}
{% endtabs %}

## IsPreferencesVisible

Check if the preferences popup is currently displayed.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().IsPreferencesVisible();
```

{% endtab %}
{% endtabs %}

## IsReady

Check if the SDK is ready.

**Requires SDK to be initialized**

No.

**Parameters**

No parameter.

**Returns**

`bool`

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().IsReady();
```

{% endtab %}
{% endtabs %}

## OnReady

Add an event listener that will be called when the SDK is ready (ie fully initialized). If the event listener is added after the SDK initialization, the listener will be called immediately.

All calls to other functions of this API must only be made in a listener to the ready event to make sure that the SDK is initialized before it is used.

**Requires SDK to be initialized**

No.

**Parameters**

| Name     | Type     | Description                             |
| -------- | -------- | --------------------------------------- |
| callback | `Action` | An action to call when the SDK is ready |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().OnReady( () => {
     // The SDK is ready 
});
```

{% endtab %}
{% endtabs %}

## OnError

Add an event listener that will be called when the SDK initialization encounters an error or if an unexpected situation occurs. Note that the behavior of the callback may slightly differ between Android and iOS platforms.

**Requires SDK to be initialized**

No.

**Parameters**

| Name     | Type     | Description                                        |
| -------- | -------- | -------------------------------------------------- |
| callback | `Action` | An action to call when the SDK encounters an error |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().OnError( () => {
     // The SDK encountered an error 
});
```

{% endtab %}
{% endtabs %}

## OpenCurrentUserStatusTransaction

**Definition**

Create an instance of the `CurrentUserStatusTransaction` class.

This class provides mechanisms to stage updates to the user status regarding purposes and vendors, allowing for batch operations.

Updates made through its methods are queued and applied simultaneously to the user status only once the `commit` method of the returned object is called.

Additional details:

* The status of vendors and purposes whose IDs are not not specified through the methods provided by `CurrentUserStatusTransaction` are kept unchanged.
* Essential purposes are always set to enabled and can’t be updated by the methods provided by `CurrentUserStatusTransaction`.
* When the regulation applied for a user is `none`, the methods provided by `CurrentUserStatusTransaction` should not update the status of any vendor or purpose which will always remain as enabled. When the `commit` method is called it will return `false`.
* If the IDs that are passed through the methods provided by `CurrentUserStatusTransaction` don’t correspond to vendors or purposes required by the Notice Config, they will be ignored.

**Requires SDK to be initialized**

Yes.

#### Parameters

No parameter.

**Returns**

An instance of the `CurrentUserStatusTransaction` class.

**Description of the** `CurrentUserStatusTransaction` **class**

<table><thead><tr><th width="207">Method</th><th width="233">Parameters</th><th>Returns</th><th>Description</th></tr></thead><tbody><tr><td><code>EnablePurpose</code></td><td><code>id</code> (<code>string</code>): ID of the purpose to be enabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Enable a single purpose based on its ID.</td></tr><tr><td><code>EnablePurposes</code></td><td><code>ids</code> (<code>string[]</code>): IDs of the purposes to be enabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Enable multiple purposes based on their IDs.</td></tr><tr><td><code>DisablePurpose</code></td><td><code>id</code> (<code>string</code>): ID of the purpose to be disabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Disable a single purpose based on its ID.</td></tr><tr><td><code>DisablePurposes</code></td><td><code>ids</code> (<code>string[]</code>): IDs of the purposes to be disabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Disable multiple purposes based on their IDs.</td></tr><tr><td><code>EnableVendor</code></td><td><code>id</code> (<code>string</code>): Didomi ID of the vendor to be enabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Enable a single vendor based on its Didomi ID.</td></tr><tr><td><code>EnableVendors</code></td><td><code>ids</code> (<code>string[]</code>): Didomi IDs of the vendors to be enabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Enable multiple vendors based on their Didomi IDs.</td></tr><tr><td><code>DisableVendor</code></td><td><code>id</code> (<code>string</code>): Didomi ID of the vendor to be disabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Disable a single vendor based on its Didomi ID.</td></tr><tr><td><code>DisableVendors</code></td><td><code>ids</code> (<code>string[]</code>): Didomi IDs of the vendors to be disabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Disable multiple vendors based on their Didomi IDs.</td></tr><tr><td><code>Commit</code></td><td>No parameters.</td><td><code>bool</code>: <code>true</code> if user status has been updated, <code>false</code> otherwise.</td><td>Commit the changes that have been made through other methods.</td></tr></tbody></table>

#### Examples

{% tabs %}
{% tab title="C#" %}

```csharp
var transaction = Didomi.GetInstance().OpenCurrentUserStatusTransaction();

// Enable a purpose
transaction.EnablePurpose("cookies");
// Enable purposes
transaction.EnablePurposes("cookies", "analytics");
// Disable a purpose
transaction.DisablePurpose("analytics");
// Disable purposes
transaction.DisablePurposes("cookies", "analytics");
// Enable a vendor
transaction.EnableVendor("vendor-1");
// Enable vendors
transaction.EnableVendors("vendor-1", "vendor-2");
// Disable a vendor
transaction.DisableVendor("vendor-1");
// Disable vendors
transaction.DisableVendors("vendor-1", "vendor-2");

// Chain multiple calls
transaction.EnablePurpose("cookies").DisablePurpose("analytics");

// Save user choices
var updated = transaction.Commit();
```

{% endtab %}
{% endtabs %}

## SetupUI

{% hint style="info" %}
Internally, the setupUI method calls the `showNotice` method, which calls the `shouldUserStatusBeCollected` method. Therefore, by calling the `setupUI` method, the notice or preferences view will be displayed only if required.
{% endhint %}

Setup the SDK UI workflows. By calling this method the notice or the preferences views will be displayed only once the SDK is ready and if consent should be collected.

For IOS platforms`UIViewController` returned by UnityGetGLViewController at Unity is used as base UI. For Android platforms `Activity` returned by com.unity3d.player.UnityPlayer.currentActivity is used as base UI.

**Requires SDK to be initialized**

No.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().SetupUI();
```

{% endtab %}
{% endtabs %}

## **S**howNotice

{% hint style="info" %}
In most cases this method should be called if the notice should be displayed in response to a user action (e.g.: select the privacy settings section within your app). By calling the setupUI method, the notice will be displayed if required.
{% endhint %}

Show the consent notice. The consent notice actually only gets shown if needed (consent is required and we are missing consent information for some vendor or purpose).

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().ShowNotice();
```

{% endtab %}
{% endtabs %}

## ShowPreferences

{% hint style="info" %}
In most cases this method should be called if you want to show the Preferences screen in response to a user action (the user pressing a Consent Preferences button in your app menu, for instance).
{% endhint %}

Show the Preferences view to the user. This can be used to allow the user to update their preferences after the banner has been closed. We suggest adding a link with this function call somewhere in your app.

**Requires SDK to be initialized**

Yes.

**Parameters**

<table><thead><tr><th width="206.72727272727272">Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>view</code></td><td><code>Didomi.Views</code></td><td>Optional, specify which view to open. Can be <code>Didomi.Views.Purposes</code> or <code>Didomi.View.Vendors</code>. By default, opens the Purposes screen.</td></tr></tbody></table>

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().ShowPreferences();    // Open the purposes screen
Didomi.GetInstance().ShowPreferences(Didomi.Views.Vendors);    // Open the vendors screen
```

{% endtab %}
{% endtabs %}

## Reset

Reset all the consent information for the current user. This will remove all consent information stored on the device by Didomi and will trigger re-collection of consent. The consent notice will be displayed again.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().Reset();
```

{% endtab %}
{% endtabs %}

## SetUser

Set custom user information from organization. More information about the organization user information behavior: [Share consents across devices](/cmp/mobile-sdk/share-consents-across-devices.md#setting-user-organization-id)

**Parameter**

| Name           | Type                   | Description                                          |
| -------------- | ---------------------- | ---------------------------------------------------- |
| userParameters | `DidomiUserParameters` | Object containing properties required to set a user. |

***Description for*** `DidomiUserParameters`***:***

<table><thead><tr><th width="193">Name</th><th width="219">Type</th><th>Description</th></tr></thead><tbody><tr><td>userAuth</td><td><code>UserAuth</code></td><td>User authentication object. Can be either <code>UserAuthWithoutParams</code>, <code>UserAuthWithEncryptionParams</code> or <code>UserAuthWithHashParams</code>.</td></tr><tr><td>dcsUserAuth</td><td><code>UserAuthParams</code></td><td>Optional. Dedicated user with encryption or hash used for Didomi Consent String signature. Can be either <code>UserAuthWithEncryptionParams</code> or <code>UserAuthWithHashParams</code>.<br>This parameter can only be used if you are using the Didomi Consent String feature (This feature is currently in beta version)</td></tr><tr><td>isUnderage</td><td><code>bool?</code></td><td>Optional. Whether the user is underage or not. This parameter can only be used if the Underage feature has been configured in your notice. (Underage is currently in beta version).</td></tr></tbody></table>

Parameters for `UserAuthWithoutParams` :

<table><thead><tr><th width="204">Name</th><th width="228">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td><code>string</code></td><td>Organization ID to associate with the user.</td></tr></tbody></table>

Parameters for `UserAuthWithEncryptionParams` :

<table><thead><tr><th width="211">Name</th><th width="202">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td><code>string</code></td><td>Organization ID to associate with the user.</td></tr><tr><td>algorithm</td><td><code>string</code></td><td>Algorithm used for computing the user ID.</td></tr><tr><td>secretId</td><td><code>string</code></td><td>ID of the secret used for the computing the user ID.</td></tr><tr><td>initializationVector</td><td><code>string</code></td><td>Initialization Vector used for encrypting the message.</td></tr><tr><td>expiration</td><td><code>long?</code></td><td>Optional. Expiration time as UNIX timestamp (must be > 0).</td></tr></tbody></table>

Parameters for `UserAuthWithHashParams` :

<table><thead><tr><th width="212">Name</th><th width="205">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td><code>string</code></td><td>Organization ID to associate with the user.</td></tr><tr><td>algorithm</td><td><code>string</code></td><td>Algorithm used for computing the user ID.</td></tr><tr><td>secretId</td><td><code>string</code></td><td>ID of the secret used for the computing the user ID.</td></tr><tr><td>digest</td><td><code>string</code></td><td>Digest used for representing the user ID</td></tr><tr><td>salt</td><td><code>string?</code></td><td>Optional. Salt used for computing the user ID.</td></tr><tr><td>expiration</td><td><code>long?</code></td><td>Optional. Expiration time as UNIX timestamp (must be > 0)</td></tr></tbody></table>

**Other signatures for `SetUser` are deprecated and should not be used.**

**Returns**

Nothing

**Example**

```csharp
Didomi.GetInstance().SetUser(new DidomiUserParameters(
            new UserAuthWithoutParams("e3222031-7c45-4f4a-8851-ffd57dbf0a2a")
));

Didomi.GetInstance().SetUser(new DidomiUserParameters(
            new UserAuthWithEncryptionParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
                        "algorithm",
                        "secret_id",
                        "initialization_vector",
                        10000L // or null
            )
));

Didomi.GetInstance().SetUser(new DidomiUserParameters(
            new UserAuthWithHashParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
                        "algorithm",
                        "secret_id",
                        "digest",
                        "salt", // or null
                        10000L // or null
            )
));

Didomi.GetInstance().SetUser(new DidomiUserParameters(
            new UserAuthWithHashParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
                        "algorithm",
                        "secret_id",
                        "digest"
            ),
            dcsUserAuth: new UserAuthWithHashParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
                        "algorithm",
                        "secret_id",
                        "digest"
            ),
            isUnderage: false
));
```

## SetUserAndSetupUI

Set custom user information from organization, and call `SetupUI` after synchronization if sdk was initialized

**Parameters**

See [#setuser](#setuser "mention")

**Returns**

Nothing

**Example**

```csharp
Didomi.GetInstance().SetUserAndSetupUI("e3222031-7c45-4f4a-8851-ffd57dbf0a2a");

Didomi.GetInstance().SetUserAndSetupUI(new UserAuthWithEncryptionParams(
            "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
            "algorithm",
            "secret_id",
            "initialization_vector",
            10000L // or null
));

Didomi.GetInstance().SetUserAndSetupUI(new UserAuthWithHashParams(
            "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
            "algorithm",
            "secret_id",
            "digest",
            "salt", // or null
            10000L // or null
)); 
```

## ClearUser

Remove custom user information from organization

**Requires SDK to be initialized**

No.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

```csharp
Didomi.GetInstance().ClearUser();
```

## SetUserAgreeToAll

Report that the user has given consent to all purposes and vendors setup for your app programmatically.\
This function will log the consent on our platform and close the notice.

Please read [our article](https://docs.didomi.io/analytics/consent-management-platform-cmp-analytics/introduction/custom-behavior-impact-on-cmp-analytics) on what to expect from your analytics when setting a custom behavior for your consent notice.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

`true` if the user consent status has changed (ie the user had given different consent information before this function got called).

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().SetUserAgreeToAll();
```

{% endtab %}
{% endtabs %}

## SetCurrentUserStatus

Set the user status for purposes and vendors. This function will trigger events and API calls every time it is called (and the user status changes) so make sure to push all user choices at once and not one by one.

Please read [our article](https://docs.didomi.io/analytics/consent-management-platform-cmp-analytics/introduction/custom-behavior-impact-on-cmp-analytics) on what to expect from your analytics when setting a custom behavior for your consent notice.

**Parameters**

Add the desired global status for each vendor and each purpose:

* the vendor status specified in this function will be reflected on the vendor’s layer.
  * vendor enabled : true → means the vendor is enabled in all the legal basis that this vendor uses.
  * vendor enabled : false → means the vendor is disabled in all the legal basis that this vendor uses
* the purposes status specified in this function will be reflected on the preferences layer.
  * purpose enabled : true → means the purpose is enabled in all the legal basis in which it’s defined.
  * purpose enabled : false → means the purpose is disabled in all the legal basis in which it’s defined.

**Returns**

`boolean`

`true` if the user choices have changed (i.e. the user had made different choices before this function got called).

**Example**

{% tabs %}
{% tab title="C#" %}

```csharp
var currentUserStatus = new CurrentUserStatus();

var purposes = new Dictionary<string, PurposeStatus>
{
    { "1", new PurposeStatus("1", true) },
    { "2", new PurposeStatus("2", true) },
    { "3", new PurposeStatus("3", false) },
    { "4", new PurposeStatus("4", false) }
};

var vendors = new Dictionary<string, VendorStatus>
{
    { "1", new VendorStatus("1", true) },
    { "2", new VendorStatus("2", true) },
    { "3", new VendorStatus("3", false) },
    { "4", new VendorStatus("4", false) }
};

bool updated = Didomi.GetInstance().SetCurrentUserStatus(currentUserStatus);
```

{% endtab %}
{% endtabs %}

## SetUserDisagreeToAll

Report that the user has denied consent to all purposes and vendors setup for your app programmatically.\
This function will log the consent information on our platform and close the banner.

Please read [our article](https://docs.didomi.io/analytics/consent-management-platform-cmp-analytics/introduction/custom-behavior-impact-on-cmp-analytics) on what to expect from your analytics when setting a custom behavior for your consent notice.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

`true` if the user consent status has changed (ie the user had given different consent information before this function got called).

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().SetUserDisagreeToAll();
```

{% endtab %}
{% endtabs %}

## ShouldConsentBeCollected

**Deprecated**, use [ShouldUserStatusBeCollected](#shoulduserstatusbecollected) instead.

Determine if consent should be collected for the visitor. Returns `true` if consent is required for the current user and one of following two conditions is met:

* Consent has never been collected for this visitor yet
* New consents should be collected (as new vendors have been added) AND the number of days before recollecting them has exceeded

If none of these two conditions is met, the function returns `false`. This function is mainly present to allow you to know when to display your own notice if you have disabled our standard notice.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().ShouldConsentBeCollected();
```

{% endtab %}
{% endtabs %}

## ShouldUserStatusBeCollected

Determine if user status (consent) should be collected for the user. Returns `true` if status is required for the current user and one of following two conditions is met:

* User status has never been collected for this user yet
* New user status should be collected (as new vendors have been added) AND the number of days before recollecting them has exceeded

If none of these two conditions is met, the function returns `False`. This function is mainly present to allow you to know when to display your own notice if you have disabled our standard notice.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

`bool`

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().ShouldUserStatusBeCollected();
```

{% endtab %}
{% endtabs %}

## UpdateSelectedLanguage

Method used to update the selected language of the Didomi SDK and any property that depends on it.

In most cases this method doesn't need to be called. It would only be required for those apps that allow language change on-the-fly, i.e.: from within the app rather than from the device settings.

In order to update the language of the views displayed by the Didomi SDK, this method needs to be called before these views are displayed.

The language update is performed asynchronously. If you need to make sure the update is done, you can listen to the events `LanguageUpdated` / `LanguageUpdateFailed`.

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name         | Type     | Description                                                              |
| ------------ | -------- | ------------------------------------------------------------------------ |
| languageCode | `string` | string containing the 2-letter language code e.g. `en`, `es`, `fr`, etc. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="C#" %}

```swift
Didomi.GetInstance().OnReady( () => {
     // The SDK is ready 
     Didomi.GetInstance().UpdateSelectedLanguage("en");
});           
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.didomi.io/cmp/mobile-sdk/unity-sdk/reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
