google mobile ad
DESCRIPTION
Google Mobile AdTRANSCRIPT
-
GoogleMobileAd(AdMob)Anyonecancomment
Note:Thedocumentationisdeprecated,pleaseusenewwebdocumentationinstead.ShortOverview SetupHowtoupdateReleasedAppswiththepluginGettingStarted
BeforeyoubeginGeneralInfoSettingupgoogleadwithyourAppSettingupanApp
SetupforIOSRequirementsPluginSetup
SetupforAndroidRequirementsPluginsSetup
SetupforWP8Requirements
APIReferencesInAppPurchaseListenerPlayMakerActions
ActionsListImplementationGuide
FrequentlyAskedQuestionsExampleScenes
ExampleNoCodingExample
Howtogetsupport
-
Short Overview
PluginprovidestheeasyandflexiblefunctionalityavailableinGoogleMobileAdSDK.Youwillbeabletomanageandreceivingeventsfrombannersofallsizes,andinterstitialad.PluginCanbeusedwithAndroidandIOSplatforms.Pleasereadfulldocumentationbeforeusingtheplugin.Ifyou'renewtoIOSappdevelopment,pleasealsoreadIOSApplicationSetupGuide.YoumaywanttoreadaboutCompilationandsigningAndroidApplicationsWithUnity.
-
Setup Pluginmayrequiresomesmallsetupactioninordertocompileinyourdevicewithnoissue.IfpluginisntinstalledthesettingswindowwillbeopenedautomaticallyintheInspectorview.Itforsomereasonitwasntopenedafteryouimportedtheplugin,goto:WindowGoogleMobileAdEditSettings
AndjustpressInstallPluginbutton.Ifinstallationwascompletedsuccessfullyyoushouldseemessageasonpicturebelow.
IfyouhaveotherpluginsinyourprojectwithrequirestooverridemainactivityyouneedtomergesuchpluginswithGoogleMobileAd.Youcanfindnecessaryinfobelow.CanIusethispluginwithotherAndroidPluginsfromAssetStoreHowtocompileandroidnative.jarfromeclipseprojectHowtomergemanifestwithanotherandroidpluginIfthepluginhasconflictwiththeIOS/WP8/Android(withnotoverridesmainactivity)Pleasecontactsupportteam.
-
How to update
1.VersionNotes
WitheverynewupdateImaketrytomakepluginbetter.Addnewfeatures,improvestability,usabilityandcodebasestructure.
Whennewversionisavailable,youcanfindoutwhatsnewintheversionandversionhistorybypressingversionnumberonAssetStorePluginPage:
2.Updating
It'srecommendedtocheckVersionNotesbeforeupdating.SometimesinordertoimplementnewfeatureorimprovecodestructureIhavetochangesomeofpluginfiles/folderormethodnames.
-
Itwillbeofcoursedescribedinversionnotes.ButifyousimpleclickupdateintheAssetStore,youmaygetduplicatedorconflictedfiles.
AfternewpluginversionisdownloadedandunpackedtoyourprojectthesettingswindowwillbeopenedautomaticallyintheInspectorview.Itforsomereasonitwasntopenedafteryouimportedtheplugin,goto:WindowGoogleMobileAdEditSettings
AndjustpressUpdatebutton.Ifinstallationwascompletedsuccessfullyyoushouldseemessageasonpicturebelow.
-
Released Apps with the plugin
SkyHoops HyperHavoc POPISLANDS BestBottleShoot
HighFiveHERO! BattleofLegends NinjaKarateDefenceHungryZombieSaga
FishTank
-
Getting Started
Beforeyoubegin
1. SignupasanAdMoborDFPpublisher.2. DownloadtheSDKforyourparticulardevelopmentplatform.3. FamiliarizeyourselfwiththeAdMobadvertisingnetworkorDoubleClickFor
Publishers(DFP)mobileadvertisingsolution.
GeneralInfo
TheGoogleMobileAdsSDKallowsdeveloperstoeasilyincorporatemobilefriendlytextandimagebannersaswellasrich,fullscreenwebappsknownasinterstitials.Anevergrowingsetof"callstoaction"aresupportedinresponsetousertouchincludingdirectaccesstotheAppStore,GooglePlay,WindowsPhone8Marketplace,iTunes,maps,videoandthedialer.Adscanbetargetedbylocationanddemographicdata.TheGoogleMobileAdsSDKcanbeusedbythefollowingpublishertypes:AdMobpublishers
AccesstheGoogleAdMobnetworktoeasilymonetizeyourapplication.DoubleClickForPublishers(DFP)users
LeverageDFPtotraffic,target,andservedirectlysoldads.TheSDKisavailabletoupgradedDFP(www.google.com/dfp)usersforAndroidandiOSplatforms.AdSensepublishers
MonetizeyoursearchresultspageswithGooglesearchads.
-
SettingupgoogleadwithyourAppOnceyouareregistered,youcanlogintotheyouradmobaccount.1)Addappformonetization
2)Createtheappformonetization:
Setnameforyourapp(namewillnotbeusedincode.soyoucanspecifyanynameyoulike).
ChoosePlatform,currentlypluginssupportAndroidandIOSplatform.
-
3)Providethefollowingdetailsfortheadunit: Adunitname:Enterauniquenameanddescriptionthatwillhelpyoufindthis
adunitlater(e.g.,TopBanneronHome). Textadstyle:Selectatextadstylethatcomplementsyourapp.Youcanuse
thestandardstyleorcustomizeyourownstyle. AutomaticrefreshDeterminehowoftenanewadimpressionisgenerated.
Youcanchoosenottorefreshortorefreshadsevery30to120seconds.Werecommendedrefreshratebetween45and60seconds.
Googleads:Selectwhetherornotyou'dliketousekeywordtargetedGoogleadsandGooglecertifiedadnetworkstoimproveyourapp'sfillrate.
ClickSave.You'llseetheadunitIDforthisadunit.
-
4)CopyyourAdunitidandclickDone.AdunityIdwillbeusedfordisplayingtheadinyourapplication.
-
Setup for IOS
Requirements
iOSversion4.3orlater Xcode4.5orlater
PluginSetup
Note:Thisstepisautomaticafter2.5version.Allframeworksanddependencies
willbeaddedautomaticallyonbuildingphase.
1.TheSDKlibraryreferencesthefollowingiOSdevelopmentframeworkswhichmaynotalreadybepartofyourproject:
CoreTelephony MessageUI StoreKit AdSupport
Toaddtheseframeworks,doubleclicktheyourprojectname.OpentheLinkBinaryWithLibrariesdropdownundertheBuildPhasestab.AddtheframeworksfromtheiOSSDKusingthe+buttonthatbecomesvisible.
-
2.YounowneedtoaddObjCtotheOtherLinkerFlagsofyourapplicationtarget'sbuildsetting:
1. InXcode'sprojectnavigator,pressthebluetoplevelprojecticon.2. Clickonyourtarget,thentheBuildSettingstab.3. UnderOtherLinkerFlags,addObjCtobothDebugandRelease.
Youshouldnowbeabletorebuildyourprojectwithoutanyerrors.Andstartusingpluginfunctions.
-
Setup for Android Requirements
MakesureyouhavethelatestcopyoftheAndroidSDKandthatyou'recompilingagainstatleastAndroidv3.2(settargetinproject.propertiestoandroid13).
TheGoogleMobileAdsSDKforAndroidrequiresaruntimeofAndroid2.3orlater(setandroid:minSdkVersiontoatleast9inyourAndroidManifest.xml).ThismeansyoucandevelopwiththelatestversionoftheAndroidSDKandyourappwillstillrunonanearlierAndroidversion(2.3minimum).
PluginsSetup
Makesurethatandroidnative.jarandAndroidManifest.xmlisinsideyourAssets/Plugins/Androidfolder.OpenAndroidManifest.xmlandenteryourpackagenameinthepackageattributeoftheelement.package="REPLACE_WITH_YOUR_PACKAGE_ID"replacethislinewithyourPackageID
-
Setup for WP8 Requirements
Windows8orlater VisualStudio2012orlater
Beforerunningtheapplicationonadevice,makesurethatfollowingcapabilitiesareincluded.
ID_CAP_IDENTITY_USER.(Providesreadaccessusedidentity) ID_CAP_WEBBROWSERCOMPONENT(RequiredsincetheAdViewisawebbrowser) ID_CAP_IDENTITY_DEVICE ID_CAP_NETWORKING(Accesstonetworkservicesisrequiredwhenrequestingads.) ID_CAP_MEDIALIB_PLAYBACK(Providesaccessforcurrentlyplayingmediaitems) ID_CAP_MEDIALIB_AUDIO(Providesreadaccesstoaudioitemsinmedialibrary)
-
API References
GoogleMobileAd:Singletonclass.
APImethods:Init ad with your ad unit id. This function should be called before any other function of this class.publicstaticvoidInit(stringios_unit_id,stringandroid_unit_id)Changes ad unity id for bannerspublicstaticvoidSetBannersUnitID(stringad_unit_id)Changes ad unity id for interstitialspublicstaticvoidSetInterstisialsUnitID(stringad_unit_id)Creates banner ad using TextAnchor
publicstaticGoogleMobileAdBannerCreateAdBanner(TextAnchoranchor,GADBannerSizesize)Creates banner ad using custom x/y positionpublicstaticGoogleMobileAdBannerCreateAdBanner(intx,inty,GADBannerSizesize)Destroy banner by idpublicstaticvoidDestroyBanner(intid)Add keyword for targeting purposes publicstaticvoidAddKeyword(stringkeyword) Sets the user's birthday for targeting purposes. publicstaticvoidSetBirthday(intyear,AndroidMonthmonth,intday)
Set gender for targeting purposes, use GADGenger publicstaticvoidSetGender(GoogleGengergender)
-
This method allows you to specify whether you would like your app to be treated as child-directed for purposes of the Childrens Online Privacy Protection Act (COPPA) - http://business.ftc.gov/privacy-and-security/childrens-privacy.
If you set this method to true, you will indicate that your app should be treated as child-directed for purposes of the Childrens Online Privacy Protection Act (COPPA).
If you set this method to false, you will indicate that your app should not be treated as child-directed for purposes of the Childrens Online Privacy Protection Act (COPPA).
If you do not set this method, ad requests will include no indication of how you would like your app treated with respect to COPPA.
By setting this method, you certify that this notification is accurate and you are authorized to act on behalf of the owner of the app. You understand that abuse of this setting may result in termination of your Google account.
Note: it may take some time for this designation to be fully implemented in applicable Google services.
publicstaticvoidTagForChildDirectedTreatment(boolval)Causes a device to receive test ads. The deviceId can be obtained by viewing the logcat output after creating a new ad.
The device ID that AdMob accepts is a hashed value (I'm not sure, but it might also include a salt) of your actual device ID. The way to get this hashed device ID is to make a live request on your device and check logcat for a message like "To get ads no this device, call adRequest.addTestDevice("YOUR_HASHED_DEVICE_ID")". This ID is what you should use. It should be a 32-digit HEX number like the numbers the OP has.
publicstaticvoidAddTestDevice(stringdeviceId)publicstaticvoidAddTestDevices(paramsstring[]ids)
-
Function will start interstitials banner request and will show it as soon as banner loaded.publicstaticvoidStartInterstitialAd()Function will send interstitials banner request. publicstaticvoidLoadInterstitialAd()Shows interstitial banner if it was previously loadedpublicstaticvoidShowInterstitialAd()Record IAP resolutions. Read More.publicstaticvoidRecordInAppResolution(GADInAppResolutionresolution)CalledwheninterstitialanadisreceivedON_INTERSTITIAL_AD_LOADEDCalledwheninterstitialanadrequestfailedON_INTERSTITIAL_AD_FAILED_LOADINGCalledwheninterstitialanadopensanoverlaythatcoversthescreen.ON_INTERSTITIAL_AD_OPENEDCalledwhentheuserisabouttoreturntotheapplicationafterclickingonanad.ON_INTERSTITIAL_AD_CLOSEDCalledwhenanadinterstitialleavestheapplication(e.g.,togotothebrowser).ON_INTERSTITIAL_AD_LEFT_APPLICATIONCalledwhenadactiontrigersinapprequest.ReadMoreON_AD_IN_APP_REQUESTWarning:GoogleMobileAdnoteventdispatherbyitself.TobeabletolistenfortheeventssignonpublicstaticGoogleMobileAdInterfacecontrollergettereventsofGoogleMobileAdclass.ControllerwillbecreatedafterGoogleMobileAdinitfunction.
GoogleMobileAdBannerinterface.
-
APImethods:Hide ad banner publicvoidHideAd()Show ad banner (only if it was hidden by HideAdfunction)publicvoidShowAd()Refresh ad content (will send new request to google)publicvoidRefresh()Change Banner Position without destroying the bannerpublicvoidSetBannerPosition(intx,inty)publicvoidSetBannerPosition(TextAnchoranchor)Get/Set:Banner idintid{get}Banner widthintwidth{get}Banner heightintheight{get}true if banner was loadedboolIsLoaded{get}true if banner currently on screenboolIsOnScreen{get}Defines show or not banner when its loaded.boolShowOnLoad{getset}Events:
-
CalledwhenanadisreceivedON_BANNER_AD_LOADEDCalledwhenanadrequestfailedON_BANNER_AD_FAILED_LOADINGCalledwhenanadopensanoverlaythatcoversthescreen.ON_BANNER_AD_OPENEDCalledwhentheuserisabouttoreturntotheapplicationafterclickingonanad.ON_BANNER_AD_CLOSEDCalledwhenanadleavestheapplication(e.g.,togotothebrowser).ON_BANNER_AD_LEFT_APPLICATION
-
InAppPurchaseListener Note:Youwillonlyreceiveinapppurchase(IAP)adsifyouspecificallyconfigureanIAPadcampaignintheAdMobfrontend.ImplementtheonInAppPurchaselistener,isreallyeasy,allyouhavetodoistosubscribetoON_AD_IN_APP_REQUESTeventGoogleMobileAd.addEventListener(GoogleMobileAdEvents.ON_AD_IN_APP_REQUEST, OnInAppRequest); ImplementEventdatawillcontainproductid.YoushoudstartyourgamepurchaseflowwiththisidassoonasyouwillreceiveON_AD_IN_APP_REQUESTevent private void OnInAppRequest(CEvent e) {
//getting product id string productId = (string) e.data; Debug.Log ("In App Request for product Id: " + productId + " received"); //Start purchase flow with productId here
} Oncethepurchaseiscomplete,youshouldcallRecordInAppResolutionwithoneofthefollowingconstantsdefinedinGADInAppResolution:public enum GADInAppResolution { RESOLUTION_SUCCESS = 0, // Purchase was a success RESOLUTION_FAILURE = 1, // Error while processing purchase RESOLUTION_INVALID_PRODUCT = 2, // Error while looking up product RESOLUTION_CANCELLED = 3 // Purchase was cancelled by user } Anexampleofasuccesscallwouldlooklikethis:GoogleMobileAd.RecordInAppResolution(GADInAppResolution.RESOLUTION_SUCCESS);
-
PlayMaker Actions Thepluginnowcontainsplaymakeractions.Theactionsscriptscanbefoundintheziparchiveat:Assets/Extensions/GoogleMobileAd/Addons/PlayMakerActionsYoucansimplyunrarittothesamefolderandGoogleMobileAdactionswillappearunderplaymakeractionsmenu.YoualwayswelcomeonthePlayMakerActionsForumThreadtorequestnewactionsorreportabugThecurrentactionlistis:
GAD_InitGoogleAd GAD_BannerEvents GAD_InterstitialEvents GAD_SetAdTargeting GAD_SetAdTestDevices GAD_CreateBanner GAD_ShowBanner GAD_HideBanner GAD_RefreshBanner GAD_DestroyBanner GAD_StartInterstisialAd GAD_LoadInterstisialAd GAD_ShowInterstisialAd
ImplementationGuide
MakesureyoureadtheGoogleMobileAdGuidesectionfirst.
WithiAdyoucanusetwotypesofadinterstitialandbanners.Butfirstofallyouneedto
initgoogleadusingtheGAD_InitGoogleAdaction.
1.Interstitial
Thereistwowaystouseinterstitial.
GAD_StartInterstisialAdaction.WillstartAdloadrequestandassoonthead
-
loadedwillshowtheinterstitialad.
UseGAD_LoadInterstisialAdtoloadtheAdcontent.SuccessEventwillbe
firedifcontentwasloadedsuccessfullyandfailEventifnot.Aftercontentwas
successfullyloadedyoumayuseGAD_ShowInterstisialAdactiontoshowthe
ad.
Youshoulduseoneofthoseapproacheseverytimeyouwanttoshowtheinterstitial
ad.
2.Banners
1)CreateadbannerusingGAD_CreateBanneraction.Ifbannerissuccessfully
createdSuccessEventwillbefiredandFailEventifcreationfailed.
DonotfillthebannerIdsection.Itwillbefilledafterbanneriscreate.Storethisid.Itwill
beusedtocontrolcreatebannerwithfollowingplaymakeractions
GAD_HideBannerwillhidethebanner
GAD_ShowBannerwillshowthebanner
GAD_RefreshBannerwillrefreshthebanner
GAD_DestroyBannerwilldestroythebanner
-
Frequently Asked Questions
Ihaveoneunitidforbannersadandoneforinterstitial,butinitfunctionistakingonlyoneid.HowshouldIspecifybothofthem?
Ifyouhavetwoidstospecify,youcaninitadmobcontrollerwithforexamplebannersid,andthensetidspecificallyforinterstitial
HowdoIgetanAdMobadunitID?
DirectionsforhowtocreateanAdMobadunitIDcanbefoundhere.AdMobadunitIDshavetheformca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN.
Ikeepgettingtheerror'TheGooglePlayservicesresourceswerenotfound.Checkyourprojectconfigurationtoensurethattheresourcesareincluded.
Youcansafelyignorethismessage.Yourappwillstillfetchandservebannerads.
Ikeepgettingtheerror'Invalidunknownrequesterror:Cannotdeterminerequesttype.Isyouradunitidcorrect?'
MakesureyouradunitIDiscorrect.ForpublishersusingthenewAdMobfrontend,theadunitIDwillbeintheformca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN.Youwillgetthiserrorifyouusetheformpub-XXXXXXXXXXXXXXXX.
Myappsupportautorotation.Butadbannerisnotchangingwhentheappisrotated.
Theautorotationforbannersisnotsupported.Butyoucanimplementitbyyourself,Iwilldescribealgorithmbelow.Mostofgameappshaveoneorientation,andthosewhosupportbothasusualus
-
differentbannerpositionandsizefordifferentorientation.thatwhyIdonotseethereasontoimplementautomationautorotation.1)95%ifuserwillnotbeusethis2)Userswhowillneedthisfeaturewouldlovetoaddextraenchantments
SoIdecidedtogiveyoufullcontrolonbannersinsteadofimplementingfeaturesthatyouwillnotuse.Hereisalgorithmhowyoucanusetoimplementcustomautorotatebannertoyourapp.1)Appstartedatlandscape.2)CreatebannerandassignittoLandscapeBannervariable3)Detectedrotationtoportrait4)hideLandscapeBanner5)CreatenewbannerandassignittoPortraitBannervariable6)Detectedrotationtobacktolandscape7)checkifLandscapeBannerwascreated,ifnoseethestep2.8)HidePortraitBanner.ShowLandscapeBanner
-
Example Scenes
ExampleThisexamplescenecanbefoundatAssets/Extensions/GoogleMobileAd/Example/Scenes/Example.
ScenewilldemonstrateusageofGoogleMobileAdAPI.ThecontrollerscriptGoogleAdsExample.csisattachedtotheGoogleAdUseExamplegameobjectandprovidesexampleforAPIcalls.
[Setup]Scenewillworkoutoftheboxafterplugininstallation.Howeverexamplescenewilluseunity_idsfrommytestaccount.Getyourownidsaftergoogleadaccountsetup.OpentheWindow>GoogleMobileAds>EditSettingsandenteridsinfollowinglines.//replace with your ids
BannerAdUnitAd ="ca-app-pub-6101605888755494/1824764765";
InterstitialsAdUnitAd= "ca-app-pub-6101605888755494/3301497967";
NoCodingExample
ThisexamplescenecanbefoundatAssets/Extensions/GoogleMobileAd/Example/Scenes/NoCodingExample.
ScenewilldemonstrateusageofGoogleMobileAdAPIwithoutanyactions.ThecontrollerscriptsforBannerAdMobBanner.csandforInterstitialAdMobBannerInterstitial.csareattachedtotheMyBanner/MyInterstitialgameobjectsandprovidesexamplesforAPIcalls.
[Setup]Scenewillworkoutoftheboxafterplugininstallation.Howeverexamplescenewilluseunity_idsfrommytestaccount.