Reference

Usage

You can access all methods through a ref to the <DidomiSDK /> component.

import { DidomiSDK, DidomiSDKAPI } from '@didomi/vega-sdk';
import React, { useRef } from 'react';

const App = () => {
  const didomiRef = useRef<DidomiSDKAPI>(null);

  return (
    <DidomiSDK
      noticeId="YOUR_NOTICE_ID"
      didomiPublicApiKey="YOUR_PUBLIC_API_KEY"
      ref={didomiRef}
      onReady={() => console.log('SDK ready')}
    >
      <YourApp />
    </DidomiSDK>
  );
};

addEventListener

Attach a listener to SDK events (consent changes, UI visibility, errors, etc.).

Signature

Parameters

  • event — Event name (see Events list below).

  • handler — Callback invoked with an optional payload.

Returns

  • void

Example


removeEventListener

Detach a previously registered event listener.

Signature

Parameters

  • event — Event name.

  • handler — The same function reference passed to addEventListener.

Returns

  • void

Example


getJavaScriptForWebView

Generate an inline JS snippet to inject into a Vega WebView that mirrors the current consent state.

Signature

Parameters

  • None

Returns

  • Promise<string> — JavaScript to inject.

Example


getQueryStringForWebView

Build a query string carrying the current consent information for WebView navigation.

Signature

Parameters

  • None

Returns

  • Promise<string> — Query string (without the leading ?).

Example


showNotice

Display the consent notice. If already visible, it becomes focused.

Signature

Parameters

  • None

Returns

  • void

Example


hideNotice

Hide the consent notice if visible.

Signature

Parameters

  • None

Returns

  • void

Example


isNoticeVisible

Check if the consent notice is currently visible.

Signature

Parameters

  • None

Returns

  • Promise<boolean>

Example


showPreferences

Open the preferences dialog.

Signature

Parameters

  • type (optional) — Initial tab to open ('information', 'purposes', or 'vendor'). Defaults to 'purposes'.

Returns

  • void

Example


hidePreferences

Close the preferences dialog if open.

Signature

Parameters

  • None

Returns

  • void

Example


isPreferencesVisible

Check if the preferences dialog is visible.

Signature

Parameters

  • None

Returns

  • Promise<boolean>

Example


isReady

Return whether the SDK has finished initialization.

Signature

Parameters

  • None

Returns

  • boolean

Example


onReady

Register a callback to run once the SDK is ready.

Signature

Parameters

  • callback — Invoked when the SDK is ready (called immediately if already ready).

Returns

  • void

Example


onError

Register a callback for SDK-level errors (configuration, network, rendering).

Signature

Parameters

  • callback — Receives an error object or message.

Returns

  • void

Example


isError

Returns whether the SDK is in an error state.

Signature

Parameters

  • None

Returns

  • boolean

Example


setLogLevel

Set the SDK log verbosity.

Signature

Parameters

  • level — Desired log level.

Returns

  • void

Example


getText

Resolve a UI text key using the current language.

Signature

Parameters

  • key — Text key.

Returns

  • Promise<string | undefined>

Example


getTranslatedText

Resolve a UI text key for a specific language.

Signature

Parameters

  • key — Text key.

  • lang — IETF language tag (e.g., en, fr-FR).

Returns

  • Promise<string | undefined>

Example


updateSelectedLanguage

Change the SDK UI language at runtime.

Signature

Parameters

  • lang — IETF language tag.

Returns

  • Promise<void>

Example


getVendor

Retrieve a vendor definition by ID.

Signature

Parameters

  • vendorId — Vendor identifier.

Returns

  • Promise<Vendor | undefined>

Example


getPurpose

Retrieve a purpose definition by ID.

Signature

Parameters

  • purposeId — Purpose identifier.

Returns

  • Promise<Purpose | undefined>

Example


getTotalVendorCount / getIabVendorCount / getNonIabVendorCount

Counts for vendors in the current configuration.

Signatures

Parameters

  • None

Returns

  • Promise<number>

Example


getRequiredPurposes / getRequiredVendors

Return lists of purposes/vendors that are required by configuration.

Signatures

Parameters

  • None

Returns

  • Promise<string[]>

Example


applicableRegulation

Get the regulation currently applied to the user (e.g., gdpr, cpra, none).

Signature

Parameters

  • None

Returns

  • Promise<string>

Example


getCurrentUserStatus

Return the current user consent status.

Signature

Parameters

  • None

Returns

  • Promise<UserStatus>

Example


isUserStatusPartial

Whether the stored status is partial (some choices missing).

Signature

Parameters

  • None

Returns

  • Promise<boolean>

Example


setCurrentUserStatus

Set the user consent status at purpose/vendor level.

Signature

Parameters

  • status — Object with per-purpose and/or per-vendor decisions.

Returns

  • Promise<void>

Example


setUserAgreeToAll

Grant consent for all purposes and vendors.

Signature

Parameters

  • None

Returns

  • Promise<void>

Example


setUserDisagreeToAll

Deny consent for all purposes and vendors.

Signature

Parameters

  • None

Returns

  • Promise<void>

Example


openCurrentUserStatusTransaction

Create a transaction to stage updates to the current user status (purposes & vendors) and apply them atomically on commit.

Updates made via the transaction are queued and only written to the user status when you call commit().

Signature

Parameters

  • None

Returns

  • CurrentUserStatusTransaction — A chainable object for batching purpose/vendor updates.

Behavior & Notes

  • Purposes/vendors not specified in the transaction remain unchanged.

  • Essential purposes are always enabled and cannot be changed by the transaction.

  • If the applied regulation is none, vendors and purposes remain enabled; commit() will return false.

  • IDs not present in the Notice Config are ignored (no-op).

  • Invalid IDs are ignored; errors may be logged to the console (see Error handling below).

Example

Error handling

  • Invalid purposes or vendors are ignored; the SDK may log messages to the browser console. Example:


CurrentUserStatusTransaction (Methods)

Method
Parameters
Returns
Description

enablePurpose

id: string

CurrentUserStatusTransaction

Enable a single purpose by ID.

enablePurposes

ids: string[]

CurrentUserStatusTransaction

Enable multiple purposes by ID.

disablePurpose

id: string

CurrentUserStatusTransaction

Disable a single purpose by ID.

disablePurposes

ids: string[]

CurrentUserStatusTransaction

Disable multiple purposes by ID.

enableVendor

id: string

CurrentUserStatusTransaction

Enable a single vendor by Didomi ID.

enableVendors

ids: string[]

CurrentUserStatusTransaction

Enable multiple vendors by Didomi ID.

disableVendor

id: string

CurrentUserStatusTransaction

Disable a single vendor by Didomi ID.

disableVendors

ids: string[]

CurrentUserStatusTransaction

Disable multiple vendors by Didomi ID.

commit

Promise<boolean>

Apply all staged changes. Returns true if the user status was updated, false otherwise.


Types

Add these to the Types section for completeness:

And add the method to your API surface:


reset

Clear locally stored consent data and re-evaluate.

Signature

Parameters

  • None

Returns

  • Promise<void>

Example


shouldUserStatusBeCollected

Whether the app should prompt for consent (e.g., user is in-scope, no valid status yet).

Signature

Parameters

  • None

Returns

  • Promise<boolean>

Example


syncUser

Update the local user status from the Didomi servers in a single-page application.

If your site is not an SPA, do not call this method directly — syncing is automatically performed when window.didomiConfig.user is set on page load.

Synchronization will only run if:

  • Sync is enabled in the configuration,

  • An organizationUserId is provided,

  • The user is not a bot, and

  • The sync frequency has not been exceeded.

Signature

Parameters

  • None

Returns

  • Promise<SyncReadyEvent> — An object describing the result of the sync.


SyncReadyEvent

Property
Type
Description

statusApplied

boolean

true if the local user status was updated from the server, false otherwise.

syncAcknowledged

() => Promise<boolean>

Call this to confirm to Didomi that the synchronized status has been communicated to the user. Returns true if the acknowledgment event was sent successfully, false otherwise.

syncError

string | undefined

Error message if the sync failed.


Examples

Simple sync

Reassurance notice flow


Notes

  • Use syncUser() only when you need to refresh consent state in an SPA.

  • Always check statusApplied — if it’s false, the local state is already up to date.

  • If you show any UI reassurance (e.g., “Your preferences are updated”), remember to call syncAcknowledged().


setUser

Update the user configuration details in a single-page application. In multi-page apps, do not call this method directly. Instead, set the user configuration details via window.didomiConfig.user on page load.

The function updates all the provided properties and sets any omitted properties to undefined.

Signature

Parameters

Name
Type
Description

organizationUserId

string

Organization User ID to associate with the user.

organizationUserIdAuthAlgorithm

string

Algorithm used for computing the digest.

organizationUserIdAuthSid

string

ID of the secret used for computing the digest.

organizationUserIdAuthSalt

string

Salt used for computing the digest.

organizationUserIdAuthDigest

string

Digest of the organization user ID and secret.

organizationUserIdExp

number

Unix timestamp (expiration).

organizationUserIdIv

string

Initialization vector if encryption was used for the digest.

Returns

  • Promise<void>

Example

Notes

  • Call setUser only once per session unless you explicitly need to update the user identity.

  • If you pass only a subset of fields, any omitted ones will be reset to undefined.

  • Always ensure the digest values (if used) are generated securely on your backend.


clearUser

Disassociate any user identifier from the current session.

Signature

Parameters

  • None

Returns

  • Promise<void>

Example


Notice Config

These helpers expose details about the loaded notice/config.

Depending on your Vega integration, some fields may be undefined until onReady.


Types

Below are the key TypeScript interfaces surfaced by the SDK.

Last updated