Docy

Android Integration

1. Update your Project-Level build.gradle  

Add the following repositories in allprojects section.

				
					mavenCentral()
maven { url "https://artifact.bytedance.com/repository/pangle" }
maven { url "https://android-sdk.is.com" }
maven { url "https://sdk.tapjoy.com/" }
				
			

Or these ones if you need to comply with the Google Family Policy.

				
					mavenCentral()
maven { url "https://android-sdk.is.com" }
maven { url "https://sdk.tapjoy.com/" }
				
			

2. Update your App-Level build.gradle

1. If you’re only targeting children under 13 years old, please add this Gradle dependency:

				
					implementation 'com.yodo1.mas:google:4.7.7'
				
			

2. If you’re targeting all ages, or 13+, use this Gradle dependency:

				
					implementation 'com.yodo1.mas:full:4.7.7'
				
			

3. Add MultiDex property to the defaultConfig Section

				
					defaultConfig {
    ...
    multiDexEnabled true
    ...
}
				
			

4. Make sure that minSdkVersion is at least 19 in the defaultConfig Section.

				
					defaultConfig {
   ...
   minSdkVersion 21
   ...
}
				
			

3. Support AndroidX

Add this content to the gradle.properties file:

				
					android.useAndroidX=true
android.enableJetifier=true
				
			

4. Update your AndroidManifest.xml

1. Add your AdMob App ID to your app’s AndroidManifest.xml file by including the  tag. Your AdMob App ID can be found under the “details” of your app on MAS Dashboard. Please replace android:value with your own AdMob App ID:

				
					<manifest>
	<application>
	<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
	<meta-data
		android:name="com.google.android.gms.ads.APPLICATION_ID"
		android:value="YOUR_ADMOB_APP_ID"/>
	</application>
</manifest>
				
			

2. Add the following line to the manifest tag.

				
					xmlns:tools="http://schemas.android.com/tools"
				
			

3. Add the following lines to the application tag.

				
					tools:replace="android:label"
tools:targetApi="n"
				
			

5. Update gradle.properties

1. Add the following line

				
					android.enableDexingArtifactTransform=false
				
			

6. Set up Yodo1MASAds.java

1. Create a new java file Yodo1MASAds.java under the same directory as MainActivity.java.

2. Add the following line at the top of the newly created java file. Make sure to replace the package name.

				
					package com.companyname.projectname;
				
			

3. Add the following code in the file.

				
					import android.util.Log;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Promise;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;

import com.yodo1.mas.Yodo1Mas;
import com.yodo1.mas.banner.Yodo1MasBannerAdListener;
import com.yodo1.mas.banner.Yodo1MasBannerAdView;
import com.yodo1.mas.error.Yodo1MasError;
import com.yodo1.mas.helper.model.Yodo1MasAdBuildConfig;
import com.yodo1.mas.helper.model.Yodo1MasUserPrivacyConfig;
import com.yodo1.mas.interstitial.Yodo1MasInterstitialAd;
import com.yodo1.mas.interstitial.Yodo1MasInterstitialAdListener;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdListener;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdView;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdViewBuilder;
import com.yodo1.mas.reward.Yodo1MasRewardAd;
import com.yodo1.mas.reward.Yodo1MasRewardAdListener;

public class Yodo1MASAds extends ReactContextBaseJavaModule {
    ReactApplicationContext context = null;
    boolean initialized = false;

    Yodo1MASAds(ReactApplicationContext context) {
        super(context);
        this.context = context;
    }

    @ReactMethod
    public void addListener(String eventName) {

    }

    @ReactMethod
    public void removeListeners(Integer count) {

    }

    @ReactMethod
    public void initMasSdk() {
        Yodo1MasAdBuildConfig config = new Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).build();
        Yodo1Mas.getInstance().setAdBuildConfig(config);
        //Call Delegate Function before Init Sdk:
        intiDelagates();
        Yodo1Mas.getInstance().init(Yodo1MASAds.this.getCurrentActivity(), "YourAppKey", new Yodo1Mas.InitListener() {
            @Override
            public void onMasInitSuccessful() {
                setInitialized(true);
                InitializeInterstitialAds();
                InitializeRewardedAds();
                sendEvent("onMasInitSuccessful");
            }
            @Override
            public void onMasInitFailed(@NonNull Yodo1MasError error) {
                sendEvent("onMasInitFailed");
            }
        });
        LoadInterstitialAds();
        LoadRewardedAds();

    }
   
    @ReactMethod
    public void InitializeInterstitialAds() {
        Yodo1MasInterstitialAd.getInstance().setAdListener(new Yodo1MasInterstitialAdListener() {

            @Override
            public void onInterstitialAdLoaded(Yodo1MasInterstitialAd ad) {
                sendEvent("interstitial-onInterstitialAdLoaded");
            }

            @Override
            public void onInterstitialAdFailedToLoad(Yodo1MasInterstitialAd ad, @NonNull Yodo1MasError error) {
                sendEvent("interstitial-onInterstitialAdFailedToLoad");
            }

            @Override
            public void onInterstitialAdOpened(Yodo1MasInterstitialAd ad) {
                sendEvent("interstitial-onInterstitialAdOpened");
            }

            @Override
            public void onInterstitialAdFailedToOpen(Yodo1MasInterstitialAd ad, @NonNull Yodo1MasError error) {
                sendEvent("interstitial-onInterstitialAdFailedToOpen");
                ad.loadAd(Yodo1MASAds.this.getCurrentActivity());
            }

            @Override
            public void onInterstitialAdClosed(Yodo1MasInterstitialAd ad) {
                sendEvent("interstitial-onInterstitialAdClosed");
                ad.loadAd(Yodo1MASAds.this.getCurrentActivity());
            }
        });
    }
    @ReactMethod
    public void LoadInterstitialAds() {
        Yodo1MasInterstitialAd.getInstance().loadAd(Yodo1MASAds.this.getCurrentActivity());
    }
    @ReactMethod
    public void InitializeRewardedAds() {
        Yodo1MasRewardAd.getInstance().setAdListener(new Yodo1MasRewardAdListener() {

            @Override
            public void onRewardAdLoaded(Yodo1MasRewardAd ad) {
                sendEvent("reward-onRewardAdLoaded");
            }

            @Override
            public void onRewardAdFailedToLoad(Yodo1MasRewardAd ad, @NonNull Yodo1MasError error) {
                sendEvent("reward-onRewardAdFailedToLoad");
            }

            @Override
            public void onRewardAdOpened(Yodo1MasRewardAd ad) {
                sendEvent("reward-onRewardAdOpened");
            }

            @Override
            public void onRewardAdFailedToOpen(Yodo1MasRewardAd ad, @NonNull Yodo1MasError error) {
                sendEvent("reward-onRewardAdFailedToOpen");
                ad.loadAd(Yodo1MASAds.this.getCurrentActivity());
            }

            @Override
            public void onRewardAdClosed(Yodo1MasRewardAd ad) {
                sendEvent("reward-onRewardAdClosed");
                ad.loadAd(Yodo1MASAds.this.getCurrentActivity());
            }

            @Override
            public void onRewardAdEarned(Yodo1MasRewardAd ad) {
                sendEvent("reward-onRewardAdEarned");
            }
        });
    }
    @ReactMethod
    public void LoadRewardedAds() {
        Yodo1MasRewardAd.getInstance().loadAd(Yodo1MASAds.this.getCurrentActivity());
    }

    @ReactMethod
    public void showBannerAds() {
        Yodo1MASAds.this.getCurrentActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {

                int align = Yodo1Mas.BannerBottom | Yodo1Mas.BannerHorizontalCenter;
                Yodo1Mas.getInstance().showBannerAd(Yodo1MASAds.this.getCurrentActivity());

            }
        });

    }

    @ReactMethod
    public void hideBannerAds() {
        Yodo1Mas.getInstance().dismissBannerAd();
    }

    @ReactMethod
    public void showIntertstialAds() {
        Yodo1MASAds.this.getCurrentActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Yodo1Mas.getInstance().showInterstitialAd(Yodo1MASAds.this.getCurrentActivity());
            }
        });
    }

    @ReactMethod
    public void showInterstitialAdWithPlacement(String tag) {
        Yodo1Mas.getInstance().showInterstitialAd(Yodo1MASAds.this.getCurrentActivity(), tag);
    }

    @ReactMethod
    public void showRewardedAds() {
        Yodo1Mas.getInstance().showRewardedAd(Yodo1MASAds.this.getCurrentActivity());
    }

    @ReactMethod
    public void showRewardAdWithPlacement(String tag) {
        Yodo1Mas.getInstance().showRewardedAd(Yodo1MASAds.this.getCurrentActivity(), tag);
    }

    @ReactMethod
    public void isInitialized(final Promise promise) {
        promise.resolve(this.initialized);
    }
    private void setInitialized(boolean initialized) {
        this.initialized = initialized;
    }

    @Override
    public String getName() {
        return "Yodo1MASAds";
    }

    private void sendEvent(String value) {
        WritableMap params = Arguments.createMap();
        params.putString("value", value);
        this.context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("adEvent", params);
    }

}
				
			

4. Replace ‘YourAppKey’ with your MAS Appkey in initMasSdk() method.

7. Comply with the legal frameworks

The following code is already added in Yodo1MASAds.java file. It displays a pop up that asks the users for their age and sets the legal frameworks (COPPA, CCPR, GDPR) accordingly. 

				
					Yodo1MasAdBuildConfig config = new Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).build();
Yodo1Mas.getInstance().setAdBuildConfig(config);
				
			

If you want to use your custom agreement and privacy policy, please use the following code.

1. Custom user agreement (optional)

				
					Yodo1MasAdBuildConfig config = new Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).userAgreementUrl("Your user agreement url").build();
Yodo1Mas.getInstance().setAdBuildConfig(config);
				
			

2. Custom privacy policy (optional)

				
					Yodo1MasAdBuildConfig config = new Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).privacyPolicyUrl("Your privacy policy url").build();
Yodo1Mas.getInstance().setAdBuildConfig(config);
				
			

IMPORTANT 

Failure to comply with these frameworks can lead to Google Play Store rejecting your game, as well as a negative impact of your game’s monetization. 

8. Set up MyAppPackage.java

1. Create a new file named MyAppPackage.java under the same directory as MainActivity.java

2. Replace the package name.

				
					package com.companyname.projectname;
				
			

3. Add the following code.

				
					import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MyAppPackage implements ReactPackage {
    @Override public List < ViewManager > createViewManagers(ReactApplicationContext reactContext) {
        return Collections.emptyList();
    }
    @Override public List < NativeModule > createNativeModules(ReactApplicationContext reactContext) {
        List < NativeModule > modules = new ArrayList < > ();
        modules.add(new Yodo1MASAds(reactContext));
        return modules;
    }
}
				
			

9. Update MainApplication.java

1. Locate getPackages() method in ReactNativeHost and add your package.

				
					@Override
protected List < ReactPackage > getPackages() {
    @SuppressWarnings("UnnecessaryLocalVariable")
    List < ReactPackage > packages = new PackageList(this).getPackages();
    // Packages that cannot be autolinked yet can be added manually here, for example:
    packages.add(new MyAppPackage());
    return packages;
}
				
			

10. Import NativeModules from React Native

1. Open your App.js file and add the following code

				
					import { NativeModules } from 'react-native';
const { Yodo1MASAds } = NativeModules;
				
			

11. Interact with the native code

This is the helper file in order to interact with the native code. This code uses NativeEventEmitter to receive events from the native side (i.e. initialization successful, a reward is earned, etc) and NativeModules in order to call Native functions, e.g. show Interstitial or rewarded Ads.

Create a JS file Yodo1Games.js in the same directory as App.js and add the following code:

				
					import {
    NativeModules,
    NativeEventEmitter,
    Alert
} from 'react-native'
const {
    Yodo1MASAds
} = NativeModules
export const hasReward = () => {
    // Your code here to check if the user has earned a reward
    // From Redux, AsyncStorage
    return true
}
export const setReward = () => {
    // Your code here to confirm that the user earned a reward
    // Redux, AsyncStorage, etc...
}
export const isAdsInitialized = () => {
    // Your code here to check if the ads are initialized from other components
}
export const setAdsInitialized = (isInitialized) => {
    // Your code here to set the adsInitialized state
    // Redux, AsyncStorage, etc...
}
export const showAdExplainer = () =>
    Alert.alert('You must watch the entire Ad to earn the reward!')
export const ShowRewardGivenAlert = () =>
    Alert.alert('Reward Added')
const handleYodoEvent = ({
    value
}) => {
    __DEV__ && console.log(`MAS Event: ${value}`)
    switch (value) {
        // Event received when Ads initialization is successful
        case 'onMasInitSuccessful':
            Yodo1MASAds.showBannerAds() // This has effect only in Android
            // setAdsInitialized(true)
            // isAdsInitialized(true);
            break
        case 'onMasInitFailed':
            setTimeout(() => Yodo1MASAds.initMasSdk(), 5000) // Try again in 5 seconds
            break
            // User earned a reward!
        case 'reward-onRewardAdEarned':
            setTimeout(() => hasReward() ? null : ShowRewardGivenAlert(), 5000)
            setReward()
            break
            // Reward Ad loaded you can check it by this method if ad is loaded or not
        case 'reward-onRewardAdLoaded':
            setTimeout(() => hasReward() ? null : showAdExplainer(), 500)
            break
            // Reward Ad Failed to Open
        case 'reward-onRewardAdOpened':
            setTimeout(() => hasReward() ? null : showAdExplainer(), 500)
            break
            // User closed the Ad, let's check if he earned a reward
        case 'reward-onRewardAdClosed':
            setTimeout(() => hasReward() ? null : showAdExplainer(), 500)
            break
            // Something went wrong, let's skip the checks on reward
        case 'reward-onRewardAdFailedToLoad':
            setReward()
            break
    }
}
// Call me on App Initialization
export const registerYodoAds = () => {
    const eventEmitter = new NativeEventEmitter(Yodo1MASAds)
    const eventListener = eventEmitter.addListener('adEvent', handleYodoEvent)
    Yodo1MASAds.initMasSdk()
    return eventListener
}
export const showBannerAds = async () => {
    //const adsAvailable = await Yodo1MASAds.isInitialized()
    //adsAvailable &&
    Yodo1MASAds.showBannerAds()
}
export const dismissBannerAds = async () => {
    //const adsAvailable = await Yodo1MASAds.isInitialized()
    //adsAvailable &&
    Yodo1MASAds.hideBannerAds()
}
export const showInterstitialAds = async () => {
    //const adsAvailable = await Yodo1MASAds.isInitialized()
    //adsAvailable &&
    Yodo1MASAds.showIntertstialAds()
}
export const showRewardedAds = async () => {
    // const adsAvailable = await Yodo1MASAds.isInitialized()
    // adsAvailable ?
    Yodo1MASAds.showRewardedAds() //: setReward()
}
				
			

12. Initialize the Sdk

Put the following code at the top of your App.js or any other script you’re using:

				
					import { showBannerAds, showInterstitialAds, showRewardedAds } from './Yodo1Games';
				
			

Please initialize the sdk by calling the function Yodo1Games.registerYodoAds() in App.js class at launch. It should be called once.

13. Show the ads

Show a banner

				
					Yodo1Games.showBannerAds();
				
			

Dismiss a banner

				
					Yodo1Games.dismissBannerAds();
				
			

Show an interstitial

				
					Yodo1Games.showInterstitialAds();
				
			

Show a rewarded video

				
					Yodo1Games.showRewardedAds();
				
			

For the next step please test your integration.

CONTENTS