Skip to content
Permalink
Browse files

Add support for Mopub's consent

The adapter fetches Mopub's ConsentStatus information and passes it
along to Criteo's SDK.
  • Loading branch information
Amokrane committed Feb 14, 2020
1 parent 6f05a4f commit 25795caae33f1c567ed932c3859b3979264b3939
@@ -0,0 +1,4 @@
## Changelog
* 3.4.0.0
* This version of the adapters has been certified with Publisher SDK 3.4.0
* Added support for MoPub's consent
@@ -3,19 +3,15 @@
import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_ATTEMPTED;
import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_FAILED;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;
import com.criteo.publisher.Criteo;
import android.support.annotation.NonNull;
import com.criteo.publisher.CriteoBannerView;
import com.criteo.publisher.CriteoInitException;
import com.criteo.publisher.model.AdSize;
import com.criteo.publisher.model.AdUnit;
import com.criteo.publisher.model.BannerAdUnit;
import com.mopub.common.VisibleForTesting;
import com.mopub.common.logging.MoPubLog;
import com.mopub.mobileads.CustomEventBanner;
import com.mopub.mobileads.MoPubErrorCode;
import java.util.Collections;
import java.util.Map;

public class CriteoBannerAdapter extends CustomEventBanner {
@@ -27,11 +23,25 @@
protected static final String MOPUB_HEIGHT = "com_mopub_ad_height";
private CriteoBannerView bannerView;

private final CriteoInitializer criteoInitializer;

public CriteoBannerAdapter() {
this(new CriteoInitializer());
}

@VisibleForTesting
CriteoBannerAdapter(@NonNull CriteoInitializer criteoInitializer) {
this.criteoInitializer = criteoInitializer;
}

@Override
protected void loadBanner(Context context, CustomEventBannerListener customEventBannerListener,
Map<String, Object> localExtras, Map<String, String> serverExtras) {

if (TextUtils.isEmpty(localExtras.toString()) || TextUtils.isEmpty(serverExtras.toString())) {
boolean localExtrasEmpty = (localExtras == null) || localExtras.isEmpty();
boolean serverExtrasEmpty = (serverExtras == null) || serverExtras.isEmpty();

if (localExtrasEmpty || serverExtrasEmpty) {
MoPubLog.log(LOAD_FAILED, TAG, "Server parameters are empty");
customEventBannerListener.onBannerFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
return;
@@ -54,11 +64,7 @@ protected void loadBanner(Context context, CustomEventBannerListener customEvent
return;
}

try {
Criteo.init((Application) (context.getApplicationContext()), criteoPublisherId,
Collections.<AdUnit>emptyList());
} catch (CriteoInitException e1) {
}
criteoInitializer.init(context, criteoPublisherId);

try {
BannerAdUnit bannerAdUnit = new BannerAdUnit(adUnitId, adSize);
@@ -43,8 +43,8 @@ public String getNetworkSdkVersion() {
public void initializeNetwork(@NonNull Context context, @Nullable Map<String, String> configuration,
@NonNull OnNetworkInitializationFinishedListener listener) {

this.networkSdkVersion = "3.1.0";
this.adapterVersion = "3.1.0.1";
this.networkSdkVersion = "3.4.0";
this.adapterVersion = "3.4.0.0";
this.moPubNetworkName = "criteo";

listener.onNetworkInitializationFinished(CriteoBaseAdapterConfiguration.class,
@@ -0,0 +1,51 @@
package com.criteo.mediation.mopub;

import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import com.criteo.publisher.Criteo;
import com.criteo.publisher.CriteoInitException;
import com.mopub.common.MoPub;
import com.mopub.common.privacy.PersonalInfoManager;

public class CriteoInitializer {
private final PersonalInfoManager personalInfoManager;

public CriteoInitializer() {
this(MoPub.getPersonalInformationManager());
}

@VisibleForTesting
CriteoInitializer(@NonNull PersonalInfoManager personalInfoManager) {
this.personalInfoManager = personalInfoManager;
}

public void init(@NonNull Context context, @NonNull String criteoPublisherId) {
Criteo.Builder criteoBuilder = getCriteoBuilder(context, criteoPublisherId);
Criteo criteo = null;

String consentStatus = personalInfoManager.getPersonalInfoConsentStatus().name();

try {
criteoBuilder.mopubConsent(consentStatus);
criteo = criteoBuilder.init();
} catch (CriteoInitException e1) {
}

if (criteo != null) {
// re-setting ConsentStatus in case its value changes while Criteo object is still in memory
// this is necessary because CriteoBuilder.init() doesn't recreate Criteo object if it's
// already instantiated
criteo.setMopubConsent(consentStatus);
}
}

@VisibleForTesting
@NonNull
Criteo.Builder getCriteoBuilder(@NonNull Context context, @NonNull String criteoPublisherId) {
return new Criteo.Builder(
(Application) context.getApplicationContext(), criteoPublisherId
);
}
}
@@ -1,23 +1,16 @@
package com.criteo.mediation.mopub;


import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_ATTEMPTED;
import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_FAILED;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;
import com.criteo.publisher.Criteo;
import com.criteo.publisher.CriteoInitException;
import android.support.annotation.NonNull;
import com.criteo.publisher.CriteoInterstitial;
import com.criteo.publisher.model.AdUnit;
import com.criteo.publisher.model.InterstitialAdUnit;
import com.mopub.common.VisibleForTesting;
import com.mopub.common.logging.MoPubLog;
import com.mopub.mobileads.CustomEventInterstitial;
import com.mopub.mobileads.MoPubErrorCode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class CriteoInterstitialAdapter extends CustomEventInterstitial {
@@ -27,11 +20,22 @@
protected static final String CRITEO_PUBLISHER_ID = "cpId";
private CriteoInterstitial criteoInterstitial;

private final CriteoInitializer criteoInitializer;

public CriteoInterstitialAdapter() {
this(new CriteoInitializer());
}

@VisibleForTesting
CriteoInterstitialAdapter(@NonNull CriteoInitializer criteoInitializer) {
this.criteoInitializer = criteoInitializer;
}

@Override
protected void loadInterstitial(Context context, CustomEventInterstitialListener customEventInterstitialListener,
Map<String, Object> localExtras, Map<String, String> serverExtras) {

if (TextUtils.isEmpty(serverExtras.toString())) {
if (serverExtras == null || serverExtras.isEmpty()) {
MoPubLog.log(LOAD_FAILED, TAG, "Server parameters are empty");
customEventInterstitialListener.onInterstitialFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
return;
@@ -53,11 +57,7 @@ protected void loadInterstitial(Context context, CustomEventInterstitialListener
return;
}

try {
Criteo.init((Application) (context.getApplicationContext()), criteoPublisherId,
Collections.<AdUnit>emptyList());
} catch (CriteoInitException e1) {
}
criteoInitializer.init(context, criteoPublisherId);

try {
InterstitialAdUnit interstitialAdUnit = new InterstitialAdUnit(adUnitId);

0 comments on commit 25795ca

Please sign in to comment.
You can’t perform that action at this time.