Skip to content

Latest commit

 

History

History
599 lines (368 loc) · 18.8 KB

android-mopub-adapter.md

File metadata and controls

599 lines (368 loc) · 18.8 KB
v6.1.6.1
  • Internal fixes

v6.1.6.0

  • Updated with Pollfish Android SDK v6.1.6

v6.1.5.1

  • Internal fixes

v6.1.5.0

  • Updated with Pollfish Android SDK v6.1.5

v6.1.4.0

  • Updated with Pollfish Android SDK v6.1.4

v6.1.3.0

  • Updated with Pollfish Android SDK v6.1.3

v6.1.2.0

  • Updated with Pollfish Andorid SDK v6.1.2

v6.1.1.0

  • Updated with Pollfish Android SDK v6.1.1

v6.1.0.0

  • Updated with Pollfish Android SDK v6.1.0.0

v6.0.4.0

  • Updated with Pollfish Android SDK v6.0.4

v6.0.3.0

  • Updated with Pollfish Android SDK v6.0.3

v6.0.2.0

  • Updated adapter with the new Pollfish Android SDK v6.0.2.0

v5.6.0.0

  • New PollfishMoPubAdapter

This guide is for publishers looking to use MoPub mediation to load and show Rewarded Surveys from Pollfish in the same waterfall with other Rewarded Ads.


Prerequisites

Note: Apps designed for Children and Families program should not be using Pollfish SDK, since Pollfish does not collect responses from users less than 16 years old

Note: Pollfish SDK requires minSdk 21. If your app supports a lower minSdk you can still build your app.

➤ For apps with minSDK lower than 21 please follow the steps here (Click to expand)

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    ... >

    <uses-sdk tools:overrideLibrary="com.pollfish" />

    <application
	... >
        ...
    </application>

app/build.gradle

defaultConfig {
    ...
    multiDexEnabled true
}

dependencies {
    ...
    implementation 'androidx.multidex:multidex:2.0.1'
}

Quick Guide

  • Set up AdMob Rewarded Ads
  • Set up Pollfish
  • Add Pollfish AdMob Adapter to your project
  • Publish your app

Analytical Steps

Below you can find a step by step guide on how to incorporate Pollfish surveys with MoPub mediation:

1. Set up MoPub Rewarded Ads

1.1. Create a Rewarded Ad Unit

If you have not implemented Rewarded Ads in your app yet, you can follow the documentation implementation as described by MoPub.

Note: If you have already implemented Rewarded Ads in your app you can skip this step

First you need to sign in to your MoPub account. In your app's section you can click to create a New Ad Unit and select Rewarded Video



In the configuration of the Ad Unit you can specify a name for your rewarded placement. If you want you can specify the reward name and a fix amount by clicking Add Reward.



If you don't apply this setting, the Pollfish adapter will provide a dynamic value as you specified it on your Pollfish Dashboard, in the App Settings area, based on the actual price of each survey completed.


1.2. Configure Ad Sources for your Rewarded Ad unit

You need to add Pollfish Network as a Custom Native Network line item and link it with your Rewarded Ad unit.

Log in to your MoPub account. On the top, click on the Orders tab and then select Create Order. If you already have an existing Order item you will need to modify it by clicking on it.

In the Create Order form, fill the required fields and press Save & Create line item



Next you will be prompted to create a New Line Item

Please make sure the correct order item is selected. Then set Pollfish Network as the line item name and Network line item as the Line item type.

On the Network field select Custom SDK Network. Set com.mopub.mobileads.PollfishMoPubAdapter in the Custom event class field and optionally provide a JSON formatted text with your Pollfish confiiguration (alternatively you can pass those params in code as described in Step 6) in the Custom event data field.

Note: In order for PollfishMoPubAdapter to work, you need to provide the configuration at least one time. If you skip please make sure you provide this configuration during the RewardedAd request in code (Step 6). Configuration parameters in code will override Web UI parameters if provided in both places.

Field Value
Custom event class com.mopub.mobileads.PollfishMoPubAdapter
Custom event data: JSON with Pollfish SDK configuration prams (optional)

JSON configuration structure

Key Type
api_key
Sets Pollfish SDK API key as provided by Pollfish
String
release_mode
Sets Pollfish SDK to Developer or Release mode
Bool
oferrwall_mode
Sets Pollfish SDK to Oferwall Mode
Bool
request_uuid
Sets a pass-through param to be received via the server-to-server callbacks
String

Example:

{
    "api_key": "API_KEY", 
    "release_mode": true,
    "offerwall_mode": true,
    "request_uuid": "REQUEST_UUID" 
}

If you want to configure those params in code (section 6) fill the Custom event data field with an empty JSON object .

{}

Note: Pollfish SDK works by default in production mode. If you would like to test with test surveys you should use release_mode false or explicitly request that in code as described in Step 6.



Next head to the Budget & Schedule section and fill the Rate field with a value ranging between $70-$80 since Pollfish rewarded surveys eCPMs usually fluctuates in that range.



Click next to proceed on the next step where you will select the Ad Unit on which this line item will apply. Please select Android only Ad Units.



Click next to proceed on the next step where you will select the audience targeting of this Netwrok line item. Fill those fields as you wish or proceed with the default values.



1.3. Add MoPub SDK to your porject

Retrieve MoPub SDK through maven() with gradle by adding the following line in your project build.gradle (not the top level one, the one under 'app') in dependencies section:

dependencies {
    implementation('com.mopub:mopub-sdk-fullscreen:5.16.0@aar') {
        transitive = true
    }
}

OR

Visit MoPub SDK GitHub page for more info and alternative ways of downloading and integrating their SDK in your app.


2 Set Up Pollfish

2.1. Obtain a Developer Account

Register as a Publisher at www.pollfish.com


2.2. Add new app on Pollfish Publisher Dashboard and copy the given API Key

Login at www.pollfish.com and click "Add a new app" on Pollfish Publisher Dashboard. Copy then the given API key for this app in order to use later on, when initializing Pollfish within your code.


2.3. Add Pollfish SDK to your project

Download Pollfish Android SDK or reference it through maven().

Download Pollfish Android SDK

Import Pollfish .aar file to your project libraries

If you are using Android Studio, right click on your project and select New Module. Then select Import .JAR or .AAR Package option and from the file browser locate Pollfish aar file. Right click again on your project and in the Module Dependencies tab choose to add Pollfish module that you recently added, as a dependency.

Integrate Google Play Services to your project

Applications that integrate Pollfish SDK are required to include Google Play Services library in order to give access to the Advertising ID of a device to the SDK. Further details regarding integration with the Google Play services library can be found here.

dependencies {
    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
}

OR

Retrieve Pollfish Android SDK through maven()

Retrieve Pollfish through maven() with gradle by adding the following line in your project build.gradle (not the top level one, the one under 'app') in dependencies section:

dependencies {
    implementation 'com.pollfish:pollfish-googleplay:6.1.5'
}

3. Add Pollfish MoPub Adapter to your project

Import Pollfish MoPub Adapter .AAR file to your project libraries

If you are using Android Studio, right click on your project and select New Module. Then select Import .JAR or .AAR Package option and from the file browser locate Pollfish MoPub Adapter aar file. Right click again on your project and in the Module Dependencies tab choose to add Pollfish module that you recently added, as a dependency.

OR

Retrieve Pollfish MoPub Adapter through maven()

Retrieve Pollfish MoPub Adapter through maven() with gradle by adding the following line in your project build.gradle (not the top level one, the one under 'app') in dependencies section:

dependencies {
    implementation 'com.pollfish.mediation:pollfish-mopub:6.1.5.1'
}

4. Request for a RewardedAd

Import com.mopub.common and com.mopub.mobileads packages

Kotlin

import com.mopub.common.*
import com.mopub.mobileads.*

Java

import com.mopub.common.*;
import com.mopub.mobileads.*;

Implement SdkInitializationListener interface to listen for MoPub SDK intialisation completion

Kotlin

class MainActivity : AppCompatActivity(), SdkInitializationListener {
    
     override fun onInitializationFinished() {}

}

Java

public class MainActivity extends AppCompatActivity implements SdkInitializationListener {
    
    @Override
    public void onInitializationFinished() {}

}

Initialize MoPub SDK and pass PollfishAdapterConfiguration class name on the initialisation configuration.

Kotlin

val configuration = SdkConfiguration.Builder("AD_UNIT_ID")
    .withAdditionalNetwork(PollfishAdapterConfiguration::class.java.name)
    .withMediatedNetworkConfiguration(
        PollfishAdapterConfiguration::class.java.name, emptyMap()
    )
    .build()

MoPub.initializeSdk(this, configuration, this)

Java

SdkConfiguration configuration = new SdkConfiguration.Builder("AD_UNIT_ID")
    .withAdditionalNetwork(PollfishAdapterConfiguration.class.getName())
    .withMediatedNetworkConfiguration(
        PollfishAdapterConfiguration.class.getName(), new HashMap<>())
    .build();

MoPub.initializeSdk(this, configuration, this);

Request a RewardedAd from MoPub using the Pollfish configuration params that you provided on MoPub's Web UI (step 2). If no configuration is provided or if you want to override any of those params provided in the Web UI please see step 6.

Kotlin

MoPubRewardedAds.setRewardedAdListener(this)
MoPubRewardedAds.loadRewardedAd("AD_UNIT_ID")

Java

MoPubRewardedAds.setRewardedAdListener(this);
MoPubRewardedAds.loadRewardedAd("AD_UNIT_ID");

Implement MoPubRewardedAdListener to get notified when the rewarded ad is ready to be shown

Kotlin

class MainActivity : AppCompatActivity(), 
    ...,
    MoPubRewardedAdListener {

    override fun onRewardedAdClicked(adUnitId: String) {}

    override fun onRewardedAdClosed(adUnitId: String) {}

    override fun onRewardedAdCompleted(adUnitIds: Set<String?>, reward: MoPubReward) {}

    override fun onRewardedAdLoadFailure(adUnitId: String, errorCode: MoPubErrorCode) {}

    override fun onRewardedAdLoadSuccess(adUnitId: String) {}

    override fun onRewardedAdShowError(adUnitId: String, errorCode: MoPubErrorCode) {}

    override fun onRewardedAdStarted(adUnitId: String) {}

}

Java

public class MainActivity extends AppCompatActivity implements MoPubRewardedAdListener {

    @Override
    public void onRewardedAdClicked(String s) {}

    @Override
    public void onRewardedAdClosed(String s) {}

    @Override
    public void onRewardedAdCompleted(Set<String> set, MoPubReward reward) {}

    @Override
    public void onRewardedAdLoadFailure(String s, MoPubErrorCode moPubErrorCode) {}

    @Override
    public void onRewardedAdLoadSuccess(String s) {}

    @Override
    public void onRewardedAdShowError(String s, MoPubErrorCode moPubErrorCode) {}

    @Override
    public void onRewardedAdStarted(String s) {}

}

When the Rewarded Ad is ready present the ad by invoking showRewardedAd

Kotlin

MoPubRewardedAds.showRewardedAd("AD_UNIT_ID")

Java

MoPubRewardedAds.showRewardedAd("AD_UNIT_ID");

5. Publish your app on the store

If you everything worked fine during the previous steps, you should turn Pollfish to release mode and publish your app.

Note: After you take your app live, you should request your account to get verified through Pollfish Dashboard in the App Settings area.

Note: There is an option to show Standalone Demographic Questions needed for Pollfish to target users with surveys even when no actually surveys are available. Those surveys do not deliver any revenue to the publisher (but they can increase fill rate) and therefore if you do not want to show such surveys in the Waterfall you should visit your App Settings are and disable that option. You can read more here


Optional section

6. Create PollfishMoPubMediationSettings object

Pollfish MoPub Adapter provides different options that you can use to control the behaviour of Pollfish SDK.


Below you can see how to initialise PollfishMoPubMediationSettings that is used to configure the behaviour of Pollfish SDK.


No Description
6.1 apikey
Sets Pollfish SDK API key as provided by Pollfish
6.2 requestUUID
Sets a pass-through param to be received via the server-to-server callbacks
6.3 releaseMode
Sets Pollfish SDK to Developer or Release mode
6.4 offerwallMode
Sets Pollfish SDK to Offerwall Mode

6.1 apiKey

Pollfish API Key as provided by Pollfish on Pollfish Dashboard after you sign up to the platform. If you have already specified Pollfish API Key on MoPub's UI, this param will override the one defined on Web UI.


6.2 requestUUID

Sets a pass-through param to be received via the server-to-server callbacks.

In order to register for such callbacks you can set up your server URL on your app's page on Pollfish Developer Dashboard and then pass your requestUUID through ParamsBuilder object during initialization. On each survey completion you will receive a callback to your server including the requestUUID param passed.

If you would like to read more on Pollfish s2s callbacks you can read the documentation here


6.3 releaseMode

Sets Pollfish SDK to Developer or Release mode.

  • Developer mode is used to show to the developer how Pollfish surveys will be shown through an app (useful during development and testing).
  • Release mode is the mode to be used for a released app in any app store (start receiving paid surveys).

Pollfish MoPub Adapter runs Pollfish SDK in release mode by default. If you would like to test with Test survey, you should set release mode to fasle.


6.4 offerwall_mode

Enables offerwall mode. If not set, one single survey is shown each time.


Below you can see an example on how you can pass info to Pollfish MoPub Adapter connfiguration:

Kotlin

val configuration = SdkConfiguration.Builder(adUnitId)
    ...
    .withMediationSettings(
        PollfishMoPubAdapter.PollfishMoPubMediationSettings
            .create(
                apiKey = "YOUR_POLLFISH_API_KEY",
                requestUUID = "REQUEST_UUID",
                releaseMode = true,
                offerwallMode = false
            )
    )
    .build()

MoPub.initializeSdk(this, configuration, this)

Java

SdkConfiguration configuration = new SdkConfiguration.Builder(adUnitId)
    ...
    .withMediationSettings(
        PollfishMoPubAdapter.PollfishMoPubMediationSettings
            .create("YOUR_POLLFISH_API_KEY", "REQUEST_UUID", true, false)
    )
    .build()

MoPub.initializeSdk(this, configuration, this);

7. Payouts on Screenouts

In Market Research monetization users can get screened out within the survey since the Researcher might be looking a different user based on the provided answers. Screenouts do not deliver any revenue for the publisher nor any reward for the users. If you would like to activate payouts on screenouts too please follow the steps as described here.


8. Proguard

If you use proguard with your app, please insert the following lines in your proguard configuration file:

-dontwarn com.pollfish.**
-keep class com.pollfish.** { *; }

More info

You can read more info on how the Pollfish SDKs work or how to get started with MoPub at the following links:

Pollfish Android SDK

MoPub Android SDK