Google Firebase Unity Admob Plugin
Google Firebase Unity Admob Plugin provides a way to integrate firebase analyze and admob ads in Unity3D Game and u3d app. You can use it for Unity iOS and Android App with the same c# or js code.It support all native firebase admob features and firebase core
Google Firebase Unity Admob Plugin Features
Platforms supported in one plugin :
- Android, Based Admob SDK v18.3.0 (part of Google Firebase service)
- iOS, via SDK v7.53.1
- Support all native events
- AdRequest targeting methods,such as children target,test mode
- Not need change Android package name
- Very simple API
- Based on FireBase SDK Version
- Firebase Analyze
Ad Types:
- Banner(All Banner Type and Custom banner sizes)
- Interstitial (text, picture, video)
- Rewarded Video
- Native Advance Ad
- Rewarded Video
Downloads Firebase Admob Unity Plugin
Assets/Plugins is reqired
admob_unity_plugin.unitypackage contain all required files and demo files
Download those files from Admob Unity3d Plugin Project Home https://github.com/unity-plugins/Firebase-Admob-Unity
or Download all the Unity admob plugin project https://github.com/unity-plugins/Firebase-Admob-Unity/archive/master.zip
Installation Firebase Admob Unity
- Open your project in the Unity editor.
- Navigate to Assets -> Import Package -> Custom Package.
- Select the admob_unity_plugin.unitypackage file.
- Import all of the files for the plugins by selecting Import. Make sure to check for any conflicts with files.
- Edit AndroidManifest.xml change the appid to your
- Edit /res/values/strings.xml change google_app_id to your
- Replace GoogleService-Info.plist with your file ,and add this this to your xcode project
- Edit Info.plist Add Google Admob id
- Add other link flag -ObjC in xcode project
Unity Plugin Wiki and Documentation
Quick Start
Google Firebase Analyze
FirebaseAnalytic firebase=FirebaseAnalytic.Instance();//init and start basic analysis
//you can set more info as follow ,but this is optional
firebase.logEvent("startevent", "{\"player\":\"yingke\"}");
firebase.setUserId("232324432");
firebase.setUserProperty("age", "20");
// firebase.setAnalyticsCollectionEnabled(true);
1.Init Firebase Admob Unity Plugin
Create A C# script ,drag the script to a object on scene , add the follow code in the script file,new version admob required configurate app id in info.plist and AndroidManifest
using admob;
Admob.Instance().initSDK(new AdProperties());//admob id with format ca-app-pub-279xxxxxxxx~xxxxxxxx
2.Add Admob Banner in Unity App
Here is the minimal code needed to show admob banner.
Admob.Instance().showBannerRelative("your banner id",AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);
The AdPosition class specifies where to place the banner. AdSize specifies witch size banner to show
3.Remove Banner
By default, banners are visible. To temporarily hide a banner, call:
Admob.Instance().removeBanner();
4.How to integrate Interstitial into Unity 3d app?
Here is the minimal code to create an interstitial.
Admob.Instance().loadInterstitial("your interstitial id");
Unlike banners, interstitials need to be explicitly shown. At an appropriate stopping point in your app, check that the interstitail is ready before showing it:
if (Admob.Instance().isInterstitialReady()) {
Admob.Instance().showInterstitial();
}
5.Custom Admob Banner Ad Sizes
In addition to constants on AdSize, you can also create a custom size:
//Create a 250x250 banner.
AdSize adSize = new AdSize(250, 250);
Admob.Instance().showBannerAbsolute("your banner id",adSize,0,30);
6.Admob settings
If you want to test the ads ,non personalize ads,set tag for family or set tag for children market,you can set with admob unity plugin easy
AdProperties adProperties = new AdProperties();
adProperties.isTesting(false);
adProperties.isAppMuted(true);
adProperties.isUnderAgeOfConsent(false);
adProperties.appVolume(100);
adProperties.maxAdContentRating(AdProperties.maxAdContentRating_G);
string[] keywords = { "diagram", "league", "brambling" };
adProperties.keyworks(keywords);
7.Ad Events
Both Banner and Interstitial contain the same ad events that you can register for. Here we'll demonstrate setting ad events on a interstitial,and show interstitial when load success:
Admob.Instance().interstitialEventHandler += onInterstitialEvent;
void onInterstitialEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobEvent---" + eventName + " " + msg);
if (eventName == AdmobEvent.onAdLoaded)
{
Admob.Instance().showInterstitial();
}
}
You only need to register for the events you care about.
8.How to integrate Admob Rewarded Video to Unity3d app?
Here is the minimal code to create an admob video.
Admob.Instance().loadRewardedVideo("ca-app-pub-xxxxxxxxxxxxx/xxxxxxxxxxxx");
Simular with interstitial,video need to be explicitly shown at an appropriate stopping point in your app, check that the video is ready before showing it:
if (Admob.Instance().isRewardedVideoReady()) {
Admob.Instance().showRewardedVideo();
}
9.Show Admob Advance Native Ad in IOS and Android App
Here is the minimal code needed to show admob banner. This is implemented with Admob Native Advanced as AdMob announced stop the express format ads
Admob.Instance().showNativeBannerRelative("native ad id",new AdSize(360,100), AdPosition.BOTTOM_CENTER, 0,"defaultNativeBanner");
The AdPosition class specifies where to place the banner. AdSize specifies witch size banner to show
10.Remove Admob Native Banner
By default, banners are visible. To temporarily hide a banner, call:
Admob.Instance().removeBanner("defaultNativeBanner");
Important Tips
- If you not config AndroidManifest.xml,APP will crash
- Attach admob to Object on scene,init admob before call admob fun
- Add GoogleService-Info.plist to your xcode project,otherwise,APP will crash
- Add Link Flag -ObjC to your xcode project,otherwise,APP will crash
- Unzip GoogleMobileAds.framework.zip to GoogleMobileAds.framework
- Edit res/values/string.xml and set the appid to your
