Android SDK Installation

Installation (Android 16+):

Gradle dependency

build.gradle in the root:

allprojects {
    repositories {
        mavenCentral()
    }
}

build.gradle in the module, according to the version of the SDK you need, we usually recommend you to use the latest version:
Maven Central

dependencies {
    implementation 'co.datadome.sdk:sdk:1.7.0'
}

1 - Network tracking & Captcha

The default and recommended integration is with the OkHttp Client interceptor:

Manual integration is also available:

2 - Event tracking

We provide 2 event tracking types:

  • Touch screen tracking
  • Custom event tracking

Touch Screen Event tracking

@Override
  public boolean dispatchTouchEvent(MotionEvent event) {
    dataDomeSDK.handleTouchEvent(event);
    return super.dispatchTouchEvent(event);
}

Custom event Tracking

import android.app.Application;

class MainActivity extends AppCompatActivity {

    private DataDomeSDK.Builder dataDomeSDK;

    @Override
    protected void OnCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        dataDomeSDK = DataDomeSDK
                .with(getApplication(), "Client_Side_Key", BuildConfig.VERSION_NAME)
                .listener(DataDomeSDKListener);
    }
    [...]

    public void isClick(View v) {
        datadomeSDK.logEvent(102, "isClicked", MainActivity.class.getSimpleName())
    }
}

Use custom Accept header

By default, the DataDome SDK overrides the default Accept header for each API call to JSON.
Please follow the 2 steps below to change this behavior:

1 - Inside the Mobile app

Set the 4th parameter to true during Interceptor instantiation.

import android.app.Application;

class MainActivity extends AppCompatActivity {

    private DataDomeSDK.Builder dataDomeSDK;

    public void makeRequest(){

        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.addInterceptor(new DataDomeInterceptor(getApplication(), dataDomeSDKListener, "Client_Side_Key", BuildConfig.VERSION_NAME, true));
        OkHttpClient client = builder.build();
    }

    [...]
}

2 - DataDome Dashboard

Force the response format inside the mobile app endpoint settings to JSON.

Optional settings

Force a Captcha display

You can simulate a Captcha display using the framework by providing a user agent with the value BLOCKUA.
You can pass this value while building the instance of DataDomeSDK using the following API:

dataDomeSDK = DataDomeSDK
        .with(getApplication(), "Client_Side_Key", BuildConfig.VERSION_NAME)
        .listener(DataDomeSDKListener)
        .agent("BLOCKUA");

IMPORTANT NOTE
Make sure the BLOCKUA user agent is not used in production. Otherwise, the Captcha will appear at least once for each user.

Manual cookie handling

If your application has multiple HTTP client instances (example: okhttp and webview), you need to share the cookie between the instances.
To do that you can use the following 2 methods: setCookie(HEADER) and getCookie from dataDomeSDK Object:

if (DataDomeUtils.isValidCookie(header)) {
  dataDomeSDK.setCookie(header);
}

String dataDomeCookie = dataDomeSDK.getCookie();

The getCookie method returns only the value of the cookie. If for some reasons, you need the DataDome cookie with all its attributes, use getCookieWithAttributes

Activate verbose logger

Starting from Android SDK v1.7.0 you can enable a verbose logger to get more details about SDK response validation process. This feature is optional and can be activated/ deactivated at DataDome SDK initialization.
The DatadomeLogger enabler helps to track extra process details (captcha loading URL, cookie storage value, retried request responses, etc) but SDK main logs remain printed even if DatadomeLogger is disabled.

dataDomeSDK = DataDomeSDK
            .with(getApplication(), "Client_Side_Key", BuildConfig.VERSION_NAME)
            .activateDatadomeLogger(true) // Add this line to enable DatadomeLogger

Set the language of the DataDome response pages

The SDK is in charge of displaying the DataDome response pages when needed. Those response pages come in the form of a Captcha page, a Hard Block page or a Device Check page.

By default this page language is the application language (if supported, see the list of supported languages)

Starting from the Android SDK version 1.11.0, if you prefer to customize the language of those pages, you can do so by calling the setResponsePageLanguage(String language) method of DataDomeSDK with a language code (as define in the RFC 7231 section 5.3.5)

DataDomeSDK.setResponsePageLanguage("fr")

Sample app

Below is a sample app demonstrating the implementation of DataDomeSDK in a basic Java application.