Using Google AdMob (Mobile Ads SDK) Unity Plugin to Serve Google Mobile Ads on Android and iOS Games

Using Google AdMob (Mobile Ads SDK) Unity Plugin to Serve Google Mobile Ads on Android and iOS Games

Import the Mobile Ads for Unity Plugin
1) Download the 'GoogleMobileAds-v9.1.0.unitypackage'.
2) Import the '.unitypackage' file by selecting the Unity menu option Assets > Import Package > Custom Package and import all items.

 

Include External Dependencies
1) Go to Project Settings > Player > Android > Publishing Settings > Build and select: Custom Main Gradle Template, Custom Gradle Properties Template
2) Select Assets > External Dependency Manager > Android Resolver > Force Resolve
3) Known Issue: If you are unable to find the External Dependency Manager in the Unity menu after installing the Google Mobile Ads Plugin, try the following step:
Solution: Simply play the game in the Unity Editor and then stop it. This action will activate the External Dependency Manager in the menu. If it doesn't work, restart Unity and play the game again to fix the issue.

 

Set your AdMob app ID

1) Select Assets > Google Mobile Ads > Settings.

2) Enter your Android and iOS AdMob app ID in each field.

- Enable Optimise initialisation, Optimise ad loading
- Add User Tracking Usage Description: "This identifier will be used to deliver personalised ads to you."

 

Initialise the SDK
1) Download the custom scripts & prefabs here.
2) Drag '_GoogleMobileAdsInit.prefab' to the Splash Scene to initialise the scripts only once.

- On initialisation complete, it will currently redirect to the next scene after a 2-second delay. Add your own function to execute after initialization.

 

App Open Ads

1) To display app open ads when transitioning from background to foreground (with a 5-second delay), drag the _AppOpenAds.prefab into both the menu and game scenes.

2) Enter your Android & iOS ad unit ID in each field.
3) Known Issue: 'AppStateEventNotifier.AppStateChanged' not calling when the app goes to the background or foreground on Android devices.
Solution: Update 'GoogleMobileAdsDependencies.xml' with the following link.
4) If you also use in-app purchasing and would like to avoid showing app open ads immediately after purchase close, uncomment the following line 147:

 

Banner Ads
1) To display adaptive banner ads at the bottom for portrait games, drag the _BannerAds.prefab into both the menu and game scenes. This setup is not recommended for landscape games.

2) Enter your Android & iOS ad unit ID in each field.

 

Interstitial Ads
1) To display interstitial ads on scene end transitions, drag _InterstitialAds.prefab into both the menu and game scenes.

2) Enter your Android & iOS ad unit ID in each field.
3) The showAdEveryNTime variable controls the frequency of interstitial ads by specifying how many game cycles to wait between ads (e.g., 1 to show every time, 2 for every alternate time, 3 for every third time).
3) The rewardedAdCooldownTimer variable sets a pause period in seconds to prevent interstitial ads from showing immediately after a rewarded ad.
4) To show an interstitial ad, call 'InterstitialAdController.instance.ShowAd(CallbackMethodName());' from any script.

 

Rewarded Ads
1) To display rewarded ads, drag the _RewardedAds.prefab into both the menu and game scenes. 

2) Enter your Android & iOS ad unit ID in each field on menu scene and game scene.
3) Drag all the rewarded ad buttons into the 'Reward Buttons' Array so the interaction will be enable/disable based on internet availability.
4) To show an rewarded ad, call 'RewardedAdController.instance.ShowAd(CallbackMethodName());' from any script.
5) Use RewardedAdPreferences.cs to unlock a single item by watching multiple ads.

 

AppLovin Bidding Mediation
1) Import the AppLovin SDK and then, select Assets > Play Services Resolver > Android Resolver > Force Resolve.
2) Build Failure: A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction See the Console for details.

Solution: Update Target API Level from 33 to 34.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.