Public Methods

Public methods are SDK methods that are made available to facilitate your interactions with our SDK, including getting information from the widget configuration and from the current user consent state.

DidomiWidgets.getContainerById(widgetId)

The SDK allows you to get the configuration object of a published widget using the getContainerbyId method.

const container = await DidomiWidgets.getContainerById("widgetId");

We recommend getting the widget's configuration once the SDK is ready. You can refer to the example here.

container.getEntities()

The SDK provides a method called getEntities that enables you to retrieve entities from your Configuration Tree that are enabled in your widget. From there, you will be able to display purpose and preference choices on your page using our Custom Elements.

  const entities = await container.getEntities();

You will receive the following data. We recommend getting the widget's configuration once the SDK is ready. You can refer to the example here.

container.isConsentPurposeEnabled(purposeId)

The SDK provides a method for checking whether a purpose is enabled or not.

The method, isConsentPurposeEnabled(purposeId) takes the purpose ID as a parameter and returns true or false.

const isPurposeEnabled = container.isConsentPurposeEnabled(purposeId)

container.getPreferenceValueById({ purposeId, preferenceId })

The SDK provides a method for fetching choices selected from a preference.

The method getPreferenceValueById takes the purpose ID and preference ID as parameters and returns a string of IDs separated by commas (,) containing the enabled values.

const enabledValuesAsString = container.getPreferenceValueById({ purposeId, preferenceId });a

container.getEntityContentById({ entityType, entityId, entityProperty, withComponentContent })

The SDK offers a method for displaying the translated content of your entities if you are unable to use our custom elements.

The method getEntityContentById takes the entityType, entityId, entityProperty and withComponentContent as parameters and returns a string with the content requested.

ParameterDescription

entityType

This property determines which content of the entity object should be displayed. It can be name or description.

entityId

ID of the selected purpose, selected preference or preference value. You can easily find them in the Configuration Tree section on the Console.

entityProperty

Specify the type of property. It can be either purpose, preference or preference-value.

withComponentContent

This property is used to determine whether to override the entity content with the layout component one set a widget level, if any (true), or to display the entity content (undefined).

container.getComponentContentById({ componentId, componentProperty })

The SDK offers a method for displaying the translated content of your component if you are unable to use our custom elements.

The method getComponentContentById takes the containerId, componentId and componentCategory as parameters and returns a string with the content requested.

ParameterDescription

componentId

ID of the layout-component

componentProperty

Property of the layout-component. For example saveButton.text.content (if it has been edited at the layout-component level) or bannerImage.src to get the URL of the header banner image for instance.

Last updated