# Reference

## Reference

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

These methods are accessible in the `Didomi` class. Also make sure to always call the SDK after it is fully initialized (see [onReady](#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.

**Requires SDK to be initialized**

No.

**Parameters**

| Name      | Type                  | Description                                                                                |
| --------- | --------------------- | ------------------------------------------------------------------------------------------ |
| eventType | `DidomiEventType`     | The type of event to listen to                                                             |
| callback  | `(data: any) => void` | Callback to call when event occurs. `data` is an optional parameter sent with some events. |

**Event types**

`DidomiEventType` is an enum with the following values:

```javascript
export enum DidomiEventType {
    // Consent
    CONSENT_CHANGED = "on_consent_changed",
    // SDK lifecycle events
    ERROR = "on_error",
    READY = "on_ready",
    // Notice
    HIDE_NOTICE = "on_hide_notice",
    SHOW_NOTICE = "on_show_notice",
    NOTICE_CLICK_AGREE = "on_notice_click_agree",
    NOTICE_CLICK_DISAGREE = "on_notice_click_disagree",
    NOTICE_CLICK_VIEW_VENDORS = "on_notice_click_view_vendors",
    NOTICE_CLICK_VIEW_SPI_PURPOSES = "on_notice_click_view_spi_purposes",
    NOTICE_CLICK_MORE_INFO = "on_notice_click_more_info",
    NOTICE_CLICK_PRIVACY_POLICY = "on_notice_click_privacy_policy",
    // Preferences
    HIDE_PREFERENCES = "on_hide_preferences",
    SHOW_PREFERENCES = "on_show_preferences",
    // Preferences - Views
    PREFERENCES_CLICK_VIEW_PURPOSES = "on_preferences_click_view_purposes",
    PREFERENCES_CLICK_VIEW_VENDORS = "on_preferences_click_view_vendors",
    PREFERENCES_CLICK_VIEW_SPI_PURPOSES = "on_preferences_click_view_spi_purposes",
    // Preferences - Purpose
    PREFERENCES_CLICK_AGREE_TO_ALL = "on_preferences_click_agree_to_all",
    PREFERENCES_CLICK_DISAGREE_TO_ALL = "on_preferences_click_disagree_to_all",
    PREFERENCES_CLICK_AGREE_TO_ALL_PURPOSES = "on_preferences_click_agree_to_all_purposes",
    PREFERENCES_CLICK_DISAGREE_TO_ALL_PURPOSES = "on_preferences_click_disagree_to_all_purposes",
    PREFERENCES_CLICK_RESET_ALL_PURPOSES = "on_preferences_click_reset_all_purposes",
    PREFERENCES_CLICK_PURPOSE_AGREE = "on_preferences_click_purpose_agree",
    PREFERENCES_CLICK_PURPOSE_DISAGREE = "on_preferences_click_purpose_disagree",
    PREFERENCES_CLICK_CATEGORY_AGREE = "on_preferences_click_category_agree",
    PREFERENCES_CLICK_CATEGORY_DISAGREE = "on_preferences_click_category_disagree",
    PREFERENCES_CLICK_SAVE_CHOICES = "on_preferences_click_save_choices",
    // Preferences - Vendor
    PREFERENCES_CLICK_AGREE_TO_ALL_VENDORS = "on_preferences_click_agree_to_all_vendors",
    PREFERENCES_CLICK_DISAGREE_TO_ALL_VENDORS = "on_preferences_click_disagree_to_all_vendors",
    PREFERENCES_CLICK_VENDOR_AGREE = "on_preferences_click_vendor_agree",
    PREFERENCES_CLICK_VENDOR_DISAGREE = "on_preferences_click_vendor_disagree",
    PREFERENCES_CLICK_VENDOR_SAVE_CHOICES = "on_preferences_click_vendor_save_choices",
    // Preferences - Sensitive Personal Information
    PREFERENCES_CLICK_SPI_PURPOSE_AGREE = "on_preferences_click_spi_purpose_agree",
    PREFERENCES_CLICK_SPI_PURPOSE_DISAGREE = "on_preferences_click_spi_purpose_disagree",
    PREFERENCES_CLICK_SPI_CATEGORY_AGREE = "on_preferences_click_spi_category_agree",
    PREFERENCES_CLICK_SPI_CATEGORY_DISAGREE = "on_preferences_click_spi_category_disagree",
    PREFERENCES_CLICK_SPI_PURPOSE_SAVE_CHOICES = "on_preferences_click_spi_purpose_save_choices",
    // Sync
    SYNC_READY = "on_sync_ready",
    SYNC_DONE = "on_sync_done", // Deprecated
    SYNC_ERROR = "on_sync_error",
    // Language
    LANGUAGE_UPDATED = "on_language_updated",
    LANGUAGE_UPDATE_FAILED = "on_language_update_failed",
}
```

These events are supported by the Didomi SDK:

<table data-header-hidden><thead><tr><th width="374">Value</th><th>Description</th></tr></thead><tbody><tr><td><strong>Value</strong></td><td>Description</td></tr><tr><td>CONSENT_CHANGED</td><td>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).</td></tr><tr><td>ERROR</td><td>When the SDK encountered an error (<code>message</code> provided as parameter).</td></tr><tr><td>READY</td><td>When the SDK is ready.</td></tr><tr><td>HIDE_NOTICE</td><td>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.</td></tr><tr><td>SHOW_NOTICE</td><td>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.</td></tr><tr><td>NOTICE_CLICK_AGREE</td><td>When user clicks on agree on the notice.</td></tr><tr><td>NOTICE_CLICK_DISAGREE</td><td>When user clicks on disagree on the notice.</td></tr><tr><td>NOTICE_CLICK_VIEW_VENDORS</td><td>When user clicks on Partners on the notice.</td></tr><tr><td>NOTICE_CLICK_VIEW_SPI_PURPOSES</td><td>When user clicks on Sensitive Personal Information on the notice.</td></tr><tr><td>NOTICE_CLICK_MORE_INFO</td><td>When user clicks on learn more on the notice.</td></tr><tr><td>NOTICE_CLICK_PRIVACY_POLICY</td><td>When user clicks on privacy policy on the notice.</td></tr><tr><td>HIDE_PREFERENCES</td><td>When the preferences screen is hidden.</td></tr><tr><td>SHOW_PREFERENCES</td><td>When the preferences screen is displayed.</td></tr><tr><td>PREFERENCES_CLICK_VIEW_PURPOSES</td><td>When user clicks on view purposes on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_VIEW_VENDORS</td><td>When user clicks on view vendors on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_VIEW_SPI_PURPOSES</td><td>When user clicks on view Sensitive Personal Information on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_AGREE_TO_ALL</td><td>When user clicks on agree to all on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_DISAGREE_TO_ALL</td><td>When user clicks on disagree to all on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_AGREE_TO_ALL_PURPOSES</td><td>When user flips ON all purposes switch on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_DISAGREE_TO_ALL_PURPOSES</td><td>When user flips OFF all purposes switch on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_RESET_ALL_PURPOSES</td><td>When user resets all purposes switch on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_PURPOSE_AGREE</td><td>When user agree to a purpose on the preferences popup. (<code>purposeId</code> provided as parameter).</td></tr><tr><td>PREFERENCES_CLICK_PURPOSE_DISAGREE</td><td>When user disagree to a purpose on the preferences popup. (<code>purposeId</code> provided as parameter)</td></tr><tr><td>PREFERENCES_CLICK_CATEGORY_AGREE</td><td>When user agree to a category on the preferences popup (<code>categoryId</code> provided as parameter).</td></tr><tr><td>PREFERENCES_CLICK_CATEGORY_DISAGREE</td><td>When user disagree to a category on the preferences popup (<code>categoryId</code> provided as parameter).</td></tr><tr><td>PREFERENCES_CLICK_SAVE_CHOICES</td><td>When user saves his choice on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_AGREE_TO_ALL_VENDORS</td><td>When user flips ON all vendors switch on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_DISAGREE_TO_ALL_VENDORS</td><td>When user flips OFF all vendors switch on the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_VENDOR_AGREE</td><td>When user agree to a vendor on the preferences popup (<code>vendorId</code> provided as parameter).</td></tr><tr><td>PREFERENCES_CLICK_VENDOR_DISAGREE</td><td>When user disagree to a vendor on the preferences popup (<code>vendorId</code> provided as parameter).</td></tr><tr><td>PREFERENCES_CLICK_VENDOR_SAVE_CHOICES</td><td>When user saves his choice on the vendors view from the preferences popup.</td></tr><tr><td>PREFERENCES_CLICK_SPI_PURPOSE_AGREE</td><td>When user agree to a purpose on the Sensitive Personal Information view from preferences popup. (<code>purposeId</code> provided as parameter).</td></tr><tr><td>PREFERENCES_CLICK_SPI_PURPOSE_DISAGREE</td><td>When user disagree to a purpose on Sensitive Personal Information view from the preferences popup. (<code>purposeId</code> provided as parameter)</td></tr><tr><td>PREFERENCES_CLICK_SPI_CATEGORY_AGREE</td><td>When user agree to a category on the Sensitive Personal Information view from preferences popup (<code>categoryId</code> provided as parameter).</td></tr><tr><td>PREFERENCES_CLICK_SPI_CATEGORY_DISAGREE</td><td>When user disagree to a category on the Sensitive Personal Information view from preferences popup (<code>categoryId</code> provided as parameter).</td></tr><tr><td>PREFERENCES_CLICK_SPI_PURPOSE_SAVE_CHOICES</td><td>When user saves his choice on the Sensitive Personal Information view from preferences popup.</td></tr><tr><td>SYNC_READY</td><td><p>When the consent synchronization process is over.</p><p><code>data</code> parameter is a <code>SyncReadyEvent</code> object that contains the fields <code>statusApplied</code> and <code>syncAcknowledged</code> (see below)</p></td></tr><tr><td><code>SyncReadyEvent.statusApplied</code></td><td>Whether the user status was applied</td></tr><tr><td><code>SyncReadyEvent.syncAcknowledged</code></td><td>Function that triggers a <code>sync.acknowledged</code> API event when called. It returns <code>true</code> if the API event was sent successfully.</td></tr><tr><td>SYNC_DONE</td><td><p><strong>Deprecated, use <code>SYNC_READY</code> instead.</strong></p><p>When the consent synchronization is successful (<code>organizationUserId</code> provided as parameter).</p></td></tr><tr><td>SYNC_ERROR</td><td>When the consent synchronization has failed (<code>error</code> provided as parameter).</td></tr><tr><td>LANGUAGE_UPDATED</td><td>When the language has changed (<code>languageCode</code> provided as parameter).</td></tr><tr><td>LANGUAGE_UPDATE_FAILED</td><td>When the language change has failed (<code>reason</code> provided as parameter).</td></tr></tbody></table>

**Returns**

Nothing

**Example**

```javascript
const registerListener = (eventType: DidomiEventType) => {
  Didomi.addEventListener(eventType, (data: any) => {
    console.log('Event received: ' + eventType + ', data:' + data);
  });
};
  
registerListener(DidomiEventType.READY);
registerListener(DidomiEventType.CONSENT_CHANGED);
registerListener(DidomiEventType.SHOW_NOTICE);
registerListener(DidomiEventType.HIDE_NOTICE);
```

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

Listen 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 start listening for changes.</p><p>This ID should be the ID provided by Didomi, which doesn't contain prefixes.</p>                |
| callback | callback: `(VendorStatus) => void` | Callback that will be executed whenever changes are detected on the specified vendor. When this callback is executed, the status linked to the specified vendor will be passed. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
Didomi.addVendorStatusListener('vendorId', (vendorStatus: VendorStatus) => {
    console.log("Event received: Vendor status for " + vendorStatus.id + " is " + vendorStatus.enabled);
});
```

{% 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="JavaScript" %}

```javascript
Didomi.removeVendorStatusListener('vendorId');
```

{% endtab %}
{% endtabs %}

## getCurrentUserStatus

**Definition**

Exposes the user status for the current regulation that applies.

**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.

<table><thead><tr><th width="185">Parameter</th><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td>vendors</td><td><code>object</code></td><td><ul><li>Object 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></td></tr><tr><td>purposes</td><td><code>object</code></td><td><ul><li>Object 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></td></tr><tr><td>regulation</td><td><code>object</code></td><td><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></td></tr><tr><td>userId</td><td><code>string</code></td><td>Didomi user id.</td></tr><tr><td>created</td><td><code>string</code></td><td>User choices creation date.</td></tr><tr><td>updated</td><td><code>string</code></td><td>User choices update date.</td></tr><tr><td>consentString</td><td><code>string</code></td><td>TCF consent as string</td></tr><tr><td>additionalConsent</td><td><code>string</code></td><td>Additional consent.</td></tr></tbody></table>

**Examples**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
let userStatus = await Didomi.getCurrentUserStatus();

let isVendorEnabled = userStatus.vendors["vendor-id"].enabled;
```

{% 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                           |
| ----------------- | ------------------------------------- |
| `Promise<string>` | JavaScript code to embed in a WebView |

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.getJavaScriptForWebView();
```

{% endtab %}
{% endtabs %}

## getQueryStringForWebView

Get a query string parameter to append to the URL of a WebView to pass the consent status from the app to the Didomi Web SDK embedded into the WebView.

Read our article on [sharing consent with WebViews](https://gitlab.com/didomi/developers-documentation/-/blob/main/docs/docs/cmp/mobile-sdk/share-consent-with-webviews.md) for more information.

{% hint style="info" %}
This method is currently available on Android platform only.
{% endhint %}

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

| Type              | Description                                                                                                                                                                            |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Promise<string>` | Query string parameter with the format `didomiConfig.user.externalConsent.value=...`. It can be appended to your URL after a `?` or a `&` if your URL already contains a query string. |

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.getQueryStringForWebView();
```

{% endtab %}
{% endtabs %}

## getPurpose

Get a purpose based on its ID.

**Requires SDK to be initialized**

Yes.

**Parameters**

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

**Returns**

| Type               | Description                                                                              |
| ------------------ | ---------------------------------------------------------------------------------------- |
| `Promise<Purpose>` | A `Purpose` with ID `purposeId` found in the array of required purposes, or `undefined`. |

`Purpose` interface is defined in `DidomiTypes.ts`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.getPurpose("purpose-id") as Purpose;
```

{% endtab %}
{% endtabs %}

## getRequiredPurposes

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

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

| Type                 | Description                                                |
| -------------------- | ---------------------------------------------------------- |
| `Promise<Purpose[]>` | A list of type `Purpose` containing the required purposes. |

`Purpose` interface is defined in `DidomiTypes.ts`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.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                                                      |
| ------------------- | ---------------------------------------------------------------- |
| `Promise<string[]>` | A list of type `string` containing the IDs of required purposes. |

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.getRequiredPurposeIds();
```

{% endtab %}
{% endtabs %}

## getRequiredVendors

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

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Returns**

| Type                | Description                                              |
| ------------------- | -------------------------------------------------------- |
| `Promise<Vendor[]>` | A list of type `Vendor` containing the required vendors. |

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.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                                                     |
| ------------------- | --------------------------------------------------------------- |
| `Promise<string[]>` | A list of type `string` containing the IDs of required vendors. |

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.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                                                                                                                                                |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Dictionary/map: `Promise<any[]>` | Dictionary/map containing the translations for a specific key in different languages, with the form { "en:" "text in English", "fr": "texte en Français" } |

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.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/build-your-own-custom-notice#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="JavaScript" %}

```dart
await Didomi.getTranslatedText("key");
```

{% endtab %}
{% endtabs %}

## getVendor

Get a vendor based on its ID.

**Requires SDK to be initialized**

Yes.

**Parameters**

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

**Returns**

| Type           | Description                                                                           |
| -------------- | ------------------------------------------------------------------------------------- |
| `Promise<any>` | A `Vendor` with ID `vendorId` found in the array of required vendors, or `undefined`. |

`Vendor` interface is defined in `DidomiTypes.ts`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.getVendor("vendor-id") as Vendor;
```

{% endtab %}
{% endtabs %}

## hideNotice

Hide the consent notice.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.hideNotice();
```

{% endtab %}
{% endtabs %}

## hidePreferences

Hide the preferences popup.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.hidePreferences();
```

{% endtab %}
{% endtabs %}

## initialize

**Deprecated**, use [initializeWithParameters](#initializewithparameters) instead.

Initialize the SDK. The initialization runs on a background thread to avoid blocking your UI. Use the [onReady](https://gitlab.com/didomi/developers-documentation/-/blob/main/docs/docs/cmp/mobile-sdk/android/reference/api.md#onready) function to know when the initialization is done and the SDK is ready to be used.

**Parameters**

{% hint style="warning" %}
The parameter `disableDidomiRemoteConfig` is deprecated, we strongly suggest you to create your notice from the console (see [Setup from the Console](https://gitlab.com/didomi/developers-documentation/-/blob/main/docs/docs/cmp/mobile-sdk/react-native/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 undefined.                                                                                                                                                                                                                                                                      |
| remoteConfigurationPath   | `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 `undefined`.                                                                                                                                                                                                                  |
| disableDidomiRemoteConfig | `boolean` | Yes      | <p>Prevent the SDK from loading a remote configuration from the Didomi Console. Defaults to <code>false</code> (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", 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.                                                                                                                                                                                                                            |
| androidTvNoticeId         |           |          | Given the same binary is used for Android and Android TV, this property allows clients to provide the notice ID used for CTV.                                                                                                                                                                                                                                                    |
| androidTvEnabled          |           |          | Given the same binary is used for Android and Android TV, this property allows clients to specify if the app will run on Android TV or not.                                                                                                                                                                                                                                      |
| countryCode               |           |          | <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                |           |          | <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>                                                                                                                                                                        |

**Returns**

`Promise<void>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.initialize(
    '465ca0b2-b96f-43b4-a864-f87e18d2fd38',
    undefined,
    undefined,
    undefined,
    false,
    undefined,
    undefined
  );
```

{% endtab %}
{% endtabs %}

## initializeWithParameters

Initialize the SDK. The initialization runs on a background thread to avoid blocking your UI. Use the [onReady](#onready) function to know when the initialization is done and the SDK is ready to be used.

**Parameter**

| Name                       | Type                         | Description                                                   |
| -------------------------- | ---------------------------- | ------------------------------------------------------------- |
| didomiInitializeParameters | `DidomiInitializeParameters` | Object containing properties required to initilalize the SDK. |

**Description for** `DidomiInitializeParameters`:

{% 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/flutter/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 undefined.                                                                                                                                                                                                                                                                      |
| remoteConfigurationPath   | `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 `undefined`.                                                                                                                                                                                                                  |
| disableDidomiRemoteConfig | `boolean` | Yes      | <p>Prevent the SDK from loading a remote configuration from the Didomi Console. Defaults to <code>false</code> (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", 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.                                                                                                                                                                                                                            |
| androidTvNoticeId         | `string`  | Yes      | Given the same binary is used for Android and Android TV, this property allows clients to provide the notice ID used for CTV.                                                                                                                                                                                                                                                    |
| androidTvEnabled          | `boolean` | Yes      | Given the same binary is used for Android and Android TV, this property allows clients to specify if the app will run on Android TV or not.                                                                                                                                                                                                                                      |
| 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                | `boolean` | No       | Whether the user is underage or not. This parameters can only be used if the Underage feature has been configured in your notice. (Underage is currently in beta version).                                                                                                                                                                                                       |

**Returns**

`Promise<void>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```typescript
const parameters = {
  apiKey: '<API key>',
  noticeId: '<notice ID>'
};
await Didomi.initializeWithParameters(parameters);
```

{% 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.

**Parameters**

No parameter.

**Returns**

`Promise<boolean>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.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.

**Parameters**

No parameter.

**Returns**

`Promise<boolean>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.isUserConsentStatusPartial();
```

{% endtab %}
{% endtabs %}

## isNoticeVisible

Check if the consent notice is currently displayed.

**Parameters**

No parameter.

**Returns**

`Promise<boolean>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.isNoticeVisible();
```

{% endtab %}
{% endtabs %}

## isPreferencesVisible

Check if the preferences popup is currently displayed.

**Parameters**

No parameter.

**Returns**

`Promise<boolean>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.isPreferencesVisible();
```

{% endtab %}
{% endtabs %}

## isReady

Check if the SDK is ready.

**Parameters**

No parameter.

**Returns**

`Promise<boolean>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.isReady();
```

{% 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**

`Promise<boolean>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.isUserStatusPartial();
```

{% endtab %}
{% endtabs %}

## onError

Add a callback that will be called when the SDK initialization encounters an error. If the callback is added after the SDK initialization already failed, it will be called immediately.

**Parameters**

| Type               | Description                                                       |
| ------------------ | ----------------------------------------------------------------- |
| `(): Promise<any>` | A callback to run when the SDK initialization encounters an error |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
Didomi.onError().then((err: any) => {
    console.log('Error: ' + err);
});
```

{% endtab %}
{% endtabs %}

## onReady

Add a callback that will be called when the SDK is ready (ie fully initialized). If the callback is added after the SDK initialization, it will be called immediately.

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

**Parameters**

| Type                | Description                             |
| ------------------- | --------------------------------------- |
| `(): Promise<void>` | A callback to run when the SDK is ready |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
Didomi.onReady().then(() => {
    // SDK is ready
});

```

{% endtab %}
{% endtabs %}

### openCurrentUserStatusTransaction

**Definition**

Create a `CurrentUserStatusTransaction` object.

This object 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`CurrentUserStatusTransaction` object.

**Description of a** `CurrentUserStatusTransaction` **object**

<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>boolean</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="JavaScript" %}

```javascript
const transaction = Didomi.openCurrentUserStatusTransaction();

// enable a purpose
transaction.enablePurpose("cookies");
// enable purposes
transaction.enablePurpose(["cookies", "analytics"]);
// disable a purpose
transaction.enablePurpose("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-1"]);

// Chain multiple calls
transaction.enablePurpose("cookies").disablePurpose("analytics");

// Save user choices
let updated = await transaction.commit();
```

{% endtab %}
{% endtabs %}

## setLogLevel

Set the minimum level of messages to log. The SDK will not log messages under that level.

It uses a `number` argument which can have different values on Android and iOS platforms., for example:

iOS

| Level   | Value |
| ------- | ----- |
| `info`  | 1     |
| `debug` | 2     |
| `error` | 16    |
| `fault` | 17    |

Android

| Level   | Value |
| ------- | ----- |
| `debug` | 3     |
| `info`  | 4     |
| `warn`  | 5     |
| `error` | 6     |

For more information see

* [Logging for Android](https://gitlab.com/didomi/developers-documentation/-/blob/main/docs/docs/cmp/mobile-sdk/android/logging.md)
* [Logging for iOS](https://gitlab.com/didomi/developers-documentation/-/blob/main/docs/docs/cmp/mobile-sdk/ios/logging.md)

**Parameters**

| Name  | Type     | Description                       |
| ----- | -------- | --------------------------------- |
| level | `number` | Minimum level of messages to log. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
// "Debug" log level is 2 on iOS, 3 on Android
let level = Platform.OS === 'ios' ? 2 : 3
Didomi.setLogLevel(level);
```

{% endtab %}
{% endtabs %}

## setupUI

Setup the SDK UI. By calling this method, the consent notice will be displayed once the SDK is ready and if consent should be collected. It does not show any view if consent was already collected or is not required.\
This method should be called only from your contexts where the application starts.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
Didomi.setupUI();
```

{% endtab %}
{% endtabs %}

## setUserWithParameters

Set user information from the organization, with or without authentication parameters.

**Parameter:**

| Name                 | Type                   | Description                                          |
| -------------------- | ---------------------- | ---------------------------------------------------- |
| didomiUserParameters | `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>boolean?</code></td><td>Optional. Whether the user is underage or not. This parameters 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>number?</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>number?</code></td><td>Optional. Expiration time as UNIX timestamp (must be > 0)</td></tr></tbody></table>

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```typescript

const userAuth = {
  id: '<user ID>',
  algorithm: 'aes-256-cbc',
  secretId: '<secret ID>',
  initializationVector: 'abcd',
  expiration: 3600
};

const dcsUserAuth = {
  id: '<user ID for DCS>',
  algorithm: 'aes-256-cbc',
  secretId: '<secret ID>',
  initializationVector: 'abcd',
  expiration: 3600
};

const parameters = {
  userAuth: userAuth,
  dcsUserAuth: dcsUserAuth
};

await Didomi.setUserWithParameters(parameters);
```

{% endtab %}
{% endtabs %}

## setUserWithParametersAndSetupUI

Set user information from the organization, with or without authentication parameters, and display the notice if required.

**Parameter:**

| Name                 | Type                   | Description                                          |
| -------------------- | ---------------------- | ---------------------------------------------------- |
| didomiUserParameters | `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>boolean?</code></td><td>Optional. Whether the user is underage or not. This parameters 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>number?</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>number?</code></td><td>Optional. Expiration time as UNIX timestamp (must be > 0)</td></tr></tbody></table>

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```typescript

const userAuth = {
  id: '<user ID>',
  algorithm: 'aes-256-cbc',
  secretId: '<secret ID>',
  initializationVector: 'abcd',
  expiration: 3600
};

const dcsUserAuth = {
  id: '<user ID for DCS>',
  algorithm: 'aes-256-cbc',
  secretId: '<secret ID>',
  initializationVector: 'abcd',
  expiration: 3600
};

const parameters = {
  userAuth: userAuth,
  dcsUserAuth: dcsUserAuth
};

await Didomi.setUserWithParametersAndSetupUI(parameters);
```

{% endtab %}
{% endtabs %}

## clearUser

Remove custom user information from organization

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.clearUser();
```

{% endtab %}
{% endtabs %}

## showNotice

{% 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 automatically 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).

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.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 method can be used to allow the user to update their preferences after the banner has been closed. We suggest adding a link/button/item that calls this method somewhere in your app, for example from your settings menu. By default, the Purposes view is displayed first. By calling this method, users will have the opportunity to modify the choices previously made.

**Parameters**

| Type              |                                                                                                                                                                                                                                                                                                                                  |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `view` (Optional) | <p>Defines which view is displayed to the user first between the purposes view or the vendors view.</p><p>Can be <code>purposes</code> , <code>sensitive-personal-information</code> or <code>vendors</code>.</p><p>If this parameter is not defined or contains an unexpected string, the purposes' view will be displayed.</p> |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await Didomi.showPreferences();
await Didomi.showPreferences("purposes");
await Didomi.showPreferences("sensitive-personal-information");
await Didomi.showPreferences("vendors");
```

{% 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.

**Parameters**

No parameter.

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```java
await Didomi.reset();
```

{% endtab %}
{% endtabs %}

## setUserAgreeToAll

Report that the user has enabled consents and legitimate interests for all purposes and vendors configured for your app.

This function will log the user choice on our platform and close the notice.

Consent statuses for essential purposes are not stored.

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**

No parameter.

**Returns**

`Promise<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="JavaScript" %}

```javascript
await Didomi.setUserAgreeToAll();
```

{% endtab %}
{% endtabs %}

## setUserDisagreeToAll

Report that the user has disabled consents and legitimate interests for all purposes and vendors configured for your app.

This function will log the user choice on our platform and close the notice.

Consent statuses for essential purposes are not stored.

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**

No parameter.

**Returns**

`Promise<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="JavaScript" %}

```javascript
Didomi.setUserDisagreeToAll();
```

{% endtab %}
{% endtabs %}

## setCurrentUserStatus <a href="#setcurrentuserstatus" id="setcurrentuserstatus"></a>

**Definition**

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="JavaScript" %}

```javascript
// Define purposes
const purposes = {
  purpose1: {
    id: 'purpose1',
    enabled: true,
  },
};

// Define vendors
const vendors = {
  vendor1: {
    id: 'vendor1',
    enabled: true,
  },
};

// Create the current user status object
const currentUserStatus = {
    purposes: purposes,
    vendors: vendors,
    user_id: '',
    created: '',
    updated: '',
    consent_string: '',
    addtl_consent: '',
    didomi_dcs: '',
    gpp_string: '',
    regulation: ''
  };

// Set the user status
const updated = await Didomi.setCurrentUserStatus(currentUserStatus);
```

{% endtab %}
{% endtabs %}

## setUserStatus

Set the global status for consent purposes, legitimate interest purposes, consent vendors, legitimate interest vendors. This function will trigger events and API calls every time it is called.

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.

| Name                  | Type      | Description                                                                                             |
| --------------------- | --------- | ------------------------------------------------------------------------------------------------------- |
| purposesConsentStatus | `boolean` | `true` if purposes on a consent basis should be enabled, `false` if they should be disabled             |
| purposesLIStatus      | `boolean` | `true` if purposes on a legitimate interest basis should be enabled, `false` if they should be disabled |
| vendorsConsentStatus  | `boolean` | `true` if vendors on a consent basis should be enabled, `false` if they should be disabled              |
| vendorsLIStatus       | `boolean` | `true` if vendors on a legitimate interest basis should be enabled, `false` if they should be disabled  |

**Returns**

`Promise<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="JavaScript" %}

```javascript
// Disable everything except vendors legitimate interest
let result = await Didomi.setUserStatus(
    false, false, false, true
);
```

{% 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.

**Parameters**

No parameter.

**Returns**

`Promise<boolean>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.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**

`Promise<boolean>`

**Example**

{% tabs %}
{% tab title="JavaScript" %}

```dart
await Didomi.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.

**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="JavaScript" %}

```java
Didomi.onReady().then(() => {
    Didomi.updateSelectedLanguage("fr");
});
```

{% 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/react-native/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.
