⌨️SDK integration

Setup project

To integrate our SDK for React Native, it is needed to run the following command in the project's root:

npm install @wortise/react-native-sdk --save

The latest version of the React Native SDK is 1.5.1

Next, the following Maven repositories need to be added inside the allprojects > repositories block of the android/build.gradle file:

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

Last, if not already done, the MultiDex support must be enabled by adding the following line in the android > defaultConfig block of the android/app/build.gradle file:

android {
    ...
    defaultConfig {
        ...
        multiDexEnabled true
    }
}

Setup Manifest

To improve the eCPM of Google's Open Bidding partners, it is needed to add a <meta-data> element in the android/app/src/main/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 android/app/src/main/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, just as specified in React Native's official documentation.

Example

Example of a permission request in React Native.

import { PermissionsAndroid } from 'react-native';

await PermissionsAndroid.requestMultiple([
  PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
  PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
  PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION
]);

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

There are two options to do the SDK initialization:

The most recommended option is to do the initialization in the Application class of the app. To do son, the following code has to be integrated in the onCreate() method of the MainApplication.java file:

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

Option 2

In this option, the SDK initialization would be directly done in the JavaScript code of the project. To do so, the following lines have to be added to the code in a proper place:

import { RNWortiseSdk } from '@wortise/react-native-sdk';

await RNWortiseSdk.initialize('your app key');

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:

import { RNWortiseAdSettings } from '@wortise/react-native-sdk';

RNWortiseAdSettings.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 RNWortiseDataManager class, just as shown below:

import {
  RNWortiseDataManager,
  RNWortiseUserGender
} from '@wortise/react-native-sdk';

// Share age
RNWortiseDataManager.setAge(20);

// Share gender
RNWortiseDataManager.setGender(RNWortiseUserGender.MALE);

// Share email addresses
RNWortiseDataManager.setEmails(["email1@gmail.com", "email2@gmail.com"]);
RNWortiseDataManager.addEmail("email3@gmail.com");

Last updated