⌨️SDK integration

Setup project

Depending of the language used by the project for the Gradle scripts, you must follow the steps from the corresponding tab:

In first place, it is needed to add the following Maven repositories inside the repositories block of the settings.gradle file:

In the projects which still use an old structure, the repositories block can be found on the build.gradle file located at the app-level.

repositories {
    maven { url 'https://maven.wortise.com/artifactory/public' }
    
    maven { url 'https://android-sdk.is.com/' }
    maven { url 'https://artifact.bytedance.com/repository/pangle' }
}

Once added, you can proceed to integrate the SDK. To do so, you have to add the following line inside the dependencies block of the build.gradle file located at the app-level:

implementation 'com.wortise:android-sdk:1.5.1'

In case of not already have it, it is needed to activate the Java 8 compatibility in the project. This can be achieved by adding these extra lines inside the android block, also in the same build.gradle file:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Setup Manifest

To improve the eCPM of Google's Open Bidding partners, it is needed to add a <meta-data> element in the AndroidManifest.xml file, inside the <application> block.

This value can be found in our dashboard, inside the app details, under the name Google App ID.

<manifest>
    ...
    <application>
        ...
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>

Request permissions (Optional)

The next step is to request the permissions in any place of the app where you believe will be more convenient. These permissions are needed to collect device data so we can display the best ads based on their real location and various attributes. This step is recommended but completely optional.

First, add the following permissions in the AndroidManifest.xml file:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Also, if your app targets Android 10 or higher (for example, if targetSdkVersion is 29 or higher), it is needed to add the following additional permission:

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

After adding the ACCESS_BACKGROUND_LOCATIONpermission, Google Play will force to fill the location permissions declaration to publish the app.

The recommended option is to obtain Google's approval to be able to use this permission.

In case it cannot be obtained, you can temporarily declare that the app does not comply with Google Play policies, to be able to use the permission until March 29th. When this date is reached, you must publish an app update without the permission, to comply with Google Play policies and avoid any kind of inconvenience.

And finally, request all the permissions so the users can grant them. Below you can find an example code to accomplish this step.

Example

Request example in the main Activity:

private static final String[] PERMISSIONS = {
    Manifest.permission.ACCESS_FINE_LOCATION,
    Manifest.permission.ACCESS_COARSE_LOCATION,
    Manifest.permission.ACCESS_BACKGROUND_LOCATION
};

ActivityCompat.requestPermissions(this, PERMISSIONS, 100);

It is very recommended to request the user consent to be able to show personalised ads. This will allow to display content of more interest and generate higher revenues.

You can consult the following section to implement this request and obtain the user consent: User consent

Initialize SDK

Our recommendation is to initialize the SDK in the Application class of the app, but it can also be done in any main Activity.

To do so, it is necessary to integrate the following code in the onCreate method:

WortiseSdk.initialize(this, "your app key");

Initialization listener

There are two possible ways to know when the SDK finishes its initialization:

Passing a listener as the last parameter of the method WortiseSdk.initialize

WortiseSdk.initialize(this, "your app key", () -> {
    // This listener will be invoked when the initialization finishes
    return Unit.INSTANCE;
});

Using the method WortiseSdk.wait

WortiseSdk.wait(() -> {
    // This listener will be invoked when the initialization finishes
    return Unit.INSTANCE;
});

Test mode

To verify the integration, the SDK provides a test mode that allows the app to always receive ads.

Beside the option that is available in our dashboard, you can programatically enable this test mode, from the SDK itself, by using the following code:

AdSettings.setTestEnabled(true);

Share user data

If the application knows some user data (age, gender, etc.), that information can be shared with the SDK so we can show ads of more interests, and therefore obtain a higher eCPM.

To share this information, it is needed to use the methods provided by the DataManager class, just as shown below:

// Share age
DataManager.setAge(context, 20);

// Share gender
DataManager.setGender(context, UserGender.MALE);

// Share email addresses
DataManager.setEmails(
    context,
    Arrays.asList("email1@gmail.com", "email2@gmail.com")
);

DataManager.addEmail(context, "email3@gmail.com");

Last updated