Share consent with WebViews

If your mobile app sometimes opens WebViews to display specific content to the user, you should ensure that consent is passed from your app to the WebViews. That will ensure that the user does not have to give consent again in the WebViews.

The setup is the following:

  • Collect consent in your app with the Didomi native SDKs

  • Launch a WebView with the Didomi Web SDK embedded in it

  • Inject JavaScript into the WebView to pass consent information from the native app

This guide assumes that you have already setup the Didomi native SDKs in your Android or iOS app, and that you have setup our Web SDK in the HTML pages loaded into your WebViews.

SDK requirements The minimum SDK versions that support this feature are:

  • Android: 1.7.0

  • iOS: 1.8.0

If your app is a web application embedded through a WebView or a PWA, we recommend using our Web SDK rather that our native mobile SDKs.

Web SDK configuration in the WebView

You need to embed the Didomi Web SDK in the HTML page that is loaded by the WebView so that it can collect the consent information passed from the app and share it with vendors.

The list of vendors configured in the web SDK in the WebView should be a subset of the list of vendors configured in the mobile app. That will ensure that the WebView has all the consent information it needs and does not re-collect consent. Examples:

Configuration

WebView behavior

Vendors in the mobile app and the WebView are the same

WebView will not display the consent UI and will use the consent information provided by the mobile app as is

Vendors in the WebView are a subset of the vendors in the mobile app

WebView will not display the consent UI and will use the consent information provided by the mobile app as is

Vendors in the mobile app are a subset of the vendors in the WebView, or there is no vendor in common

WebView will display the consent UI and collect user consent for the vendors that are specific to the WebView

Other parameters of the web SDK can be configured freely, in particular with respect to the IAB framework and tags management.

Inject consent information into the WebView

Consent status can be passed to the Web SDK by embedding JavaScript code into your WebView.

The Android and iOS SDKs automatically generate the required JavaScript code for you with the getJavaScriptForWebView method. Call that method and embed the returned string into your WebView:

Java
Swift
Didomi.getInstance().onReady(() -> {
String didomiJavaScriptCode = Didomi.getInstance().getJavaScriptForWebView();
webView.evaluateJavascript(
didomiJavaScriptCode,
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onReceiveValue(String s) {}
);
});
let didomiJavaScriptCode = Didomi.shared.getJavaScriptForWebView()
webView.evaluateJavaScript(didomiJavaScriptCode, completionHandler: nil)