Build your own custom notice

Customizing the design of mobile views shown by the Didomi SDK is complex as there is no easy option like CSS to do so.

To fully customize the notice (the first view shown to the user), you can disable the standard Didomi notices (banner or dialog) and build your own notice entirely

Disable the standard notice

Disable the standard notice in your didomi_config.json file or in the Custom JSON of the notice in the Console by setting the notice.enable property to false:

{
"notice": {
"enable": false
}
}

When the notice is disabled, the SDK will never display its own standard notice and consent will not be automatically collected by Didomi. You must implement your own notice or no consent will be collected.

Make sure that the option "Display the full Preferences popup to the user instead of the notice" (in Look & Feel > Format > Pop-in) is not enabled. If this option is enabled, the SDK will still display the Preferences / Purposes view even if you disable the notice.

Build your own custom notice

Build your own custom notice (a Fragment on Android or a ViewController on iOS) with your design and content. A notice usually contains a disclaimer (what personal data you are collecting and for what usage) and the following action buttons:

  • Learn more: opens the Preferences popup (call the showPreferences() function of the SDK)

  • Agree & Close: stores the user consent to all vendors and purposes and closes the notice (call the setUserAgreeToAll() and hideNotice() functions of the SDK)

  • Disagree & Close (optional): stores the fact that the user has denied consent to all vendors and purposes and closes the notice (call the setUserDisagreeToAll() and hideNotice() functions of the SDK)

Keep in mind that for closing your own notice, you still need to call the hideNotice method from our SDK.

Examples:

Java
Swift
Objective-C
Java
/**
* Called when the "Learn more" button is clicked
*/
private void learnMoreClickListener() {
Didomi.getInstance().showPreferences();
}
/**
* Called when the "Agree & Close" button is clicked
*/
private void agreeAndCloseClickListener() {
Didomi.getInstance().setUserAgreeToAll();
Didomi.getInstance().hideNotice();
}
/**
* Called when the "Disagree & Close" button is clicked
*/
private void disagreeAndCloseClickListener() {
Didomi.getInstance().setUserDisagreeToAll();
Didomi.getInstance().hideNotice();
}
Swift
/**
* Called when the "Learn more" button is clicked
*/
func learnMoreClickListener() {
Didomi.shared.showPreferences()
}
/**
* Called when the "Agree & Close" button is clicked
*/
func agreeAndCloseClickListener() {
Didomi.shared.setUserAgreeToAll()
Didomi.shared.hideNotice()
}
/**
* Called when the "Disagree & Close" button is clicked
*/
func disagreeAndCloseClickListener() {
Didomi.shared.setUserDisagreeToAll()
Didomi.shared.hideNotice()
}
Objective-C
/**
* Called when the "Learn more" button is clicked
*/
- (void)learnMoreClickListener {
Didomi *didomi = [Didomi shared];
[didomi showPreferences];
}
/**
* Called when the "Agree & Close" button is clicked
*/
- (void)agreeAndCloseClickListener {
Didomi *didomi = [Didomi shared];
[didomi setUserAgreeToAll];
[didomi hideNotice];
}
/**
* Called when the "Disagree & Close" button is clicked
*/
- (void)disagreeAndCloseClickListener {
Didomi *didomi = [Didomi shared];
[didomi setUserDisagreeToAll];
[didomi hideNotice];
}

Show your custom notice

You need to show your custom notice when needed. You have two options to do so.

Option 1 - Show notice event

The first option is to show your notice when the show notice event is triggered by the SDK. In that case, the SDK is fully responsible for the consent logic and you simply need to handle showing/hiding your notice and its own logic:

Java
Swift
Java
import io.didomi.sdk.events.EventListener;
import io.didomi.sdk.events.HideNoticeEvent;
import io.didomi.sdk.events.ShowNoticeEvent;
Didomi.getInstance().addEventListener(new EventListener() {
@Override
public void showNotice(ShowNoticeEvent event) {
// Show your notice
}
@Override
public void hideNotice(HideNoticeEvent event) {
// Hide your notice
}
});
Swift
let didomiEventListener = EventListener()
didomiEventListener.onHideNotice = { event in
// Hide your consent notice
}
didomiEventListener.onShowNotice = { event in
// Show your consent notice
}
Didomi.shared.addEventListener(listener: didomiEventListener)

Option 2 - Check if the notice needs to be displayed

The second option is to check if the notice needs to be displayed because we do not have all the consent information that we require. Use the isUserConsentStatusPartial (Android reference and iOS reference) method for that. You can check and display the notice any time you want AFTER the SDK has been initialized (use the onReady function for that). This is more flexible but requires you to do a little bit more synchronization between the SDK and you code:

Java
Swift
Java
Didomi.getInstance().onReady(() -> {
if (Didomi.getInstance().isUserConsentStatusPartial()) {
// Display your notice
}
});
Swift
Didomi.shared.onReady{
if (Didomi.shared.isUserConsentStatusPartial()) {
// Display your notice
}
}

Translatable texts for custom notices

While building your own notice is great for the user experience and consistency of your app, it puts more responsibility into the app and reduces the usefulness of the Didomi Console for managing the content of the notice.

To get the best of both worlds, your app can get all the texts to display in your notice (the notice content, the buttons, etc.) from the SDK and the configuration in the console by calling the getTranslatedText method (for Android and for iOS). That function will return the text to display to the user based on the configured language.

Examples:

Java
Swift
Java
// Get the text to display in the notice
String noticeContent = Didomi.getInstance().getTranslatedText("notice.content.notice");
// Get the label of the Agree button
String agreeButtonLabel = Didomi.getInstance().getTranslatedText("notice.content.dismiss");
Swift
// Get the text to display in the notice
let noticeContent = Didomi.shared.getTranslatedText("notice.content.notice")
// Get the label of the Agree button
let agreeButtonLabel = Didomi.shared.getTranslatedText("notice.content.dismiss")

If you want to add other texts, that are not part of our regular views, you can specify the texts property in your didomi_config.json file or in the Custom JSON field of the Didomi Console:

didomi_config.json
{
"app": {
...
},
...
"texts": {
"custom_notice.content.title": {
"en": "Custom title in English",
"fr": "Titre personnalisée en Français"
}
}
}

Note that you should provide translations for all the languages that your app supports. We provide translations for all our standard messages.