SDK Android

This guide describes how to integrate the DataDome SDK in your Android application.


DataDome SDK has two major benefits:

1 - Network Tracking & captcha

Handle 403 API response, generate by DataDome server-side integration, to display the captcha.

2 - Event Tracking

The SDK track user interactions inside the app, only when the app is in activity, and send it to DataDome API

Install (Android 16+):

Gradle dependency

In the root build.gradle.

allprojects {
    repositories {
        maven { url 'https://dl.bintray.com/datadome-org/datadome/' }
    }
}

And in the module build.gradle, according with last version of SDK:

LAST_VERSION :
dependencies {
    implementation 'co.datadome.sdk:sdk:+'
}

1 - Network Tracking & captcha

The default and recommended integration is with OkHttp Client interceptor

We also have a manual integration:

2 - Event Tracking

We provide 2 events 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())
    }
}

Optional settings

Use custom Accept header

By default DataDome SDK override the default Accept header for each API calls to JSON.
Please follow the 2 steps to change this behavior.

1 - Inside Mobile app

Set the fourth 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 in the mobile app endpoint settings to JSON.

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 BLOCKUA user agent is not used in production. Otherwise, the captcha will appear at least once for each user.

Sample app

You can find a sample app showing implementation of DataDomeSDK in a basic android application.

Manual Cookie handling

If your application have multiple http client instance (example: okhttp and webview), you need to share the cookie between the both.
To do that you can use those 2 method setCookie(HEADER) and getCookie of dataDomeSDK Object

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

String dataDomeCookie = dataDomeSDK.getCookie();

Updated about a month ago

SDK Android


This guide describes how to integrate the DataDome SDK in your Android application.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.