You are on page 1of 28

GoogleMobileAd(AdMob)

Anyonecancomment

Note
:Thedocumentationisdeprecated,pleaseuse
newwebdocumentation
instead.

ShortOverview
Setup
Howtoupdate
ReleasedAppswiththeplugin
GettingStarted
Beforeyoubegin
GeneralInfo
SettingupgoogleadwithyourApp
SettingupanApp
SetupforIOS
Requirements
PluginSetup
SetupforAndroid
Requirements
PluginsSetup
SetupforWP8
Requirements
APIReferences
InAppPurchaseListener
PlayMakerActions
ActionsList
ImplementationGuide
FrequentlyAskedQuestions
ExampleScenes
Example
NoCodingExample
Howtogetsupport

Short Overview

PluginprovidestheeasyandflexiblefunctionalityavailableinGoogleMobileAdSDK.
Youwillbeabletomanageandreceivingeventsfrombannersofallsizes,and
interstitialad.
PluginCanbeusedwithAndroidandIOSplatforms.

Pleasereadfulldocumentationbeforeusingtheplugin.
Ifyou'renewtoIOSappdevelopment,pleasealsoread
IOSApplicationSetupGuide.
Youmaywanttoreadabout
CompilationandsigningAndroidApplicationsWithUnity
.

Setup
Pluginmayrequiresomesmallsetupactioninordertocompileinyourdevicewithno
issue.Ifpluginisntinstalledthesettingswindowwillbeopenedautomaticallyinthe
Inspectorview.Itforsomereasonitwasntopenedafteryouimportedtheplugin,goto:
WindowGoogleMobileAdEditSettings

Andjustpress
InstallPlugin
button.Ifinstallationwascompletedsuccessfullyyou
shouldseemessageasonpicturebelow.

Ifyouhaveotherpluginsinyourprojectwithrequirestooverridemainactivityyou
needtomergesuchpluginswithGoogleMobileAd.Youcanfindnecessaryinfo
below.
CanIusethispluginwithotherAndroidPluginsfromAssetStore
Howtocompileandroidnative.jarfromeclipseproject
Howtomergemanifestwithanotherandroidplugin

IfthepluginhasconflictwiththeIOS/WP8/Android(withnotoverridesmain
activity)Please
contactsupportteam
.

How to update

1.VersionNotes
WitheverynewupdateImaketrytomakepluginbetter.Addnewfeatures,improve
stability,usabilityandcodebasestructure.

Whennewversionisavailable,youcanfindoutwhatsnewintheversionandversion
historybypressingversionnumberon
AssetStorePluginPage
:

2.Updating
It'srecommendedtocheck
VersionNotes
beforeupdating.
SometimesinordertoimplementnewfeatureorimprovecodestructureIhaveto
changesomeofpluginfiles/folderormethodnames.

Itwillbeofcoursedescribedinversionnotes.ButifyousimpleclickupdateintheAsset
Store,youmaygetduplicatedorconflictedfiles.

Afternewpluginversionisdownloadedandunpackedtoyourprojectthesettings
windowwillbeopenedautomaticallyintheInspectorview.Itforsomereasonitwasnt
openedafteryouimportedtheplugin,goto:
WindowGoogleMobileAdEditSettings

Andjustpress
Update
button.Ifinstallationwascompletedsuccessfullyyoushould
seemessageasonpicturebelow.

Released Apps with the plugin

SkyHoops

HyperHavoc

POPISLANDS

BestBottleShoot

HighFiveHERO! BattleofLegends

FishTank

NinjaKarateDefence

HungryZombieSaga

Getting Started

Beforeyoubegin
Signupasan
AdMob
or
DFP
publisher.
2. Download
theSDKforyourparticulardevelopmentplatform.
3. Familiarizeyourselfwiththe
AdMobadvertisingnetwork
or
DoubleClickFor
Publishers(DFP)mobileadvertisingsolution
.
1.

GeneralInfo
TheGoogleMobileAdsSDKallowsdeveloperstoeasilyincorporate
mobilefriendlytextandimagebannersaswellasrich,fullscreenwebappsknownas
interstitials.Anevergrowingsetof"callstoaction"aresupportedinresponsetouser
touchincludingdirectaccesstotheAppStore,GooglePlay,WindowsPhone8
Marketplace,iTunes,maps,videoandthedialer.Adscanbetargetedbylocationand
demographicdata.TheGoogleMobileAdsSDKcanbeusedbythefollowingpublisher
types:

AdMobpublishers
AccesstheGoogleAdMobnetworktoeasilymonetizeyourapplication.
DoubleClickForPublishers(DFP)users
LeverageDFPtotraffic,target,andservedirectlysoldads.TheSDKis
availabletoupgradedDFP(
www.google.com/dfp
)usersfor
Android
and
iOS
platforms.
AdSensepublishers
MonetizeyoursearchresultspageswithGooglesearchads.

SettingupgoogleadwithyourApp

Onceyouareregistered,youcanlogintotheyouradmobaccount.

1)Addappformonetization

2)Createtheappformonetization:
Setnameforyourapp(namewillnotbeusedincode.soyoucanspecifyany
nameyoulike).
ChoosePlatform,currentlypluginssupportAndroidandIOSplatform.

3)Providethefollowingdetailsfortheadunit:
Adunitname:
Enterauniquenameanddescriptionthatwillhelpyoufindthis
adunitlater(e.g.,TopBanneronHome).
Textadstyle:
Selectatextadstylethatcomplementsyourapp.Youcanuse
thestandardstyleorcustomizeyourownstyle.
Automaticrefresh
Determinehowoftenanewadimpressionisgenerated.
Youcanchoosenottorefreshortorefreshadsevery30to120seconds.We
recommendedrefreshratebetween45and60seconds.
Googleads:
Selectwhetherornotyou'dliketousekeywordtargetedGoogle
adsandGooglecertifiedadnetworkstoimproveyourapp'sfillrate.
ClickSave.
You'llseetheadunitIDforthisadunit.

4)Copyyour
Adunitid
andclickDone.AdunityIdwillbeusedfordisplayingthead
inyourapplication.

Setup for IOS

Requirements

iOSversion
4.3
orlater
Xcode
4.5
orlater

PluginSetup
Note:
Thisstepisautomaticafter
2.5
version.Allframeworksanddependencies
willbeaddedautomaticallyonbuildingphase.
1.TheSDKlibraryreferencesthefollowingiOSdevelopmentframeworkswhich
maynotalreadybepartofyourproject:
CoreTelephony
MessageUI
StoreKit
AdSupport

Toaddtheseframeworks,doubleclicktheyourprojectname.O
pentheLink
BinaryWithLibraries
dropdownunderthe
BuildPhases
tab.Addthe
frameworksfromtheiOSSDKusingthe+buttonthatbecomesvisible.

2.Younowneedtoadd
ObjC
tothe
OtherLinkerFlags
ofyourapplication
target'sbuildsetting:

1. InXcode'sprojectnavigator,pressthebluetoplevelprojecticon.
2. Clickonyourtarget,thenthe
BuildSettings
tab.
3. Under
OtherLinkerFlags
,add
ObjC
toboth
Debug
and
Release
.

Youshouldnowbeabletorebuildyourprojectwithoutanyerrors.Andstartusing
pluginfunctions.

Setup for Android


Requirements
Makesureyouhavethe
latestcopyoftheAndroidSDK
andthatyou're
compilingagainstatleastAndroid
v3.2
(set
target
in
project.properties
to
android13
).
TheGoogleMobileAdsSDKforAndroidrequiresaruntimeofAndroid
2.3
or
later(set
android:minSdkVersion
toatleast
9
inyour
AndroidManifest.xml
).
ThismeansyoucandevelopwiththelatestversionoftheAndroidSDKand
yourappwillstillrunonanearlierAndroidversion(
2.3
minimum).

PluginsSetup
Makesurethat
androidnative.jar
and
AndroidManifest.xml
isinsideyour
Assets/Plugins/Android
folder.

Open
AndroidManifest.xml
andenteryourpackagenameinthe
package
attributeof
the
<manifest>
element.
package="REPLACE_WITH_YOUR_PACKAGE_ID"replacethislinewithyour
PackageID

Setup for WP8


Requirements
Windows8orlater
VisualStudio2012orlater

Beforerunningtheapplicationonadevice,makesurethatfollowingcapabilitiesare
included.

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:Singleton<GoogleMobileAd>class.

APImethods:

Init ad with your ad unit id. This function should be called before any
other function of this class.

public

static

void
Init(
string
ios_unit_id,
string
android_unit_id)

Changes ad unity id for banners


public

static

void
SetBannersUnitID(
string
ad_unit_id)

Changes ad unity id for interstitials


public

static

void
SetInterstisialsUnitID(
string
ad_unit_id)

Creates banner ad using


TextAnchor
public

static
GoogleMobileAdBannerCreateAdBanner(
TextAnchor
anchor,
GADBannerSizesize)

Creates banner ad using custom x/y position


public

static
GoogleMobileAdBannerCreateAdBanner(
int
x,
int
y,GADBannerSize
size)

Destroy banner by id
public

static

void
DestroyBanner(
int
id)

Add keyword for targeting purposes

publicstatic

void
AddKeyword(
string
keyword)
Sets the user's birthday for targeting purposes.

publicstatic
void
SetBirthday(
int
year,AndroidMonthmonth,
int
day)
Set gender for targeting purposes, use
GADGenger

publicstatic

void
SetGender(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.

publicstatic

void
TagForChildDirectedTreatment(
bool
val)

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.

publicstatic

void
AddTestDevice(
string
deviceId)
public

static

void
AddTestDevices(
params

string
[]ids)

Function will start interstitials banner request and will show it as soon
as banner loaded.

publicstatic

void
StartInterstitialAd()

Function will send interstitials banner request.

publicstatic

void
LoadInterstitialAd()

Shows interstitial banner if it was previously loaded

publicstatic

void
ShowInterstitialAd()

Record IAP resolutions. R


ead More
.
public

static

void
RecordInAppResolution(GADInAppResolutionresolution)

Calledwheninterstitialanadisreceived
ON_INTERSTITIAL_AD_LOADED

Calledwheninterstitialanadrequestfailed
ON_INTERSTITIAL_AD_FAILED_LOADING

Calledwheninterstitialanadopensanoverlaythatcoversthescreen.
ON_INTERSTITIAL_AD_OPENED

Calledwhentheuserisabouttoreturntotheapplicationafterclickingonanad.
ON_INTERSTITIAL_AD_CLOSED

Calledwhenanadinterstitialleavestheapplication(e.g.,togotothebrowser).
ON_INTERSTITIAL_AD_LEFT_APPLICATION

Calledwhenadactiontrigersinapprequest.
ReadMore
ON_AD_IN_APP_REQUEST

Warning:

GoogleMobileAd
noteventdispatherbyitself.Tobeabletolistenforthe
eventssignon
public

static
GoogleMobileAdInterfacecontroller
gettereventsof
GoogleMobileAd
class.Controllerwillbecreatedafter
GoogleMobileAd
init

function.

GoogleMobileAdBannerinterface.


APImethods:

Hide ad banner

public
void
HideAd()

Show ad banner (only if it was hidden by


HideAd
function)

public
void
ShowAd()

Refresh ad content (will send new request to google)

public
void
Refresh()

Change Banner Position without destroying the banner

public

void
SetBannerPosition(
int
x,
int
y)
public

void
SetBannerPosition(
TextAnchor
anchor)

Get/Set
:

Banner id

int
id{
get
}

Banner width

int
width{
get
}

Banner height

int
height{
get
}

true if banner was loaded

bool
IsLoaded{
get
}

true if banner currently on screen

bool
IsOnScreen{
get
}

Defines show or not banner when its loaded.

bool
ShowOnLoad{
get

set
}

Events
:


Calledwhenanadisreceived
ON_BANNER_AD_LOADED

Calledwhenanadrequestfailed
ON_BANNER_AD_FAILED_LOADING

Calledwhenanadopensanoverlaythatcoversthescreen.
ON_BANNER_AD_OPENED

Calledwhentheuserisabouttoreturntotheapplicationafterclickingonanad.
ON_BANNER_AD_CLOSED

Calledwhenanadleavestheapplication(e.g.,togotothebrowser).
ON_BANNER_AD_LEFT_APPLICATION

InAppPurchaseListener

Note:Youwillonlyreceiveinapppurchase(IAP)adsifyouspecificallyconfigureanIAPadcampaignin
theAdMobfrontend.

Implementthe
onInAppPurchase
listener,isreallyeasy,allyouhavetodoistosubscribeto
ON_AD_IN_APP_REQUEST
event

GoogleMobileAd
.
addEventListener
(
GoogleMobileAdEvents
.
ON_AD_IN_APP_REQUEST
,
OnInAppRequest
);

ImplementEventdatawillcontainproductid.Youshoudstartyourgamepurchaseflowwiththisidassoon
asyouwillreceive
ON_AD_IN_APP_REQUEST
event
private
void
OnInAppRequest
(
CEvente
){
//getting product id
stringproductId
=
(
string
)e
.
data;
Debug
.
Log
(
"In App Request for product Id: "
+productId
+
" received"
);
//Start purchase flow with
productId here
}

Oncethepurchaseiscomplete,youshouldcall
RecordInAppResolution
withoneofthefollowingconstants
definedin
GADInAppResolution
:

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/PlayMakerActions

YoucansimplyunrarittothesamefolderandGoogleMobileAdactionswillappear
underplaymakeractionsmenu.Youalwayswelcomeonthe
PlayMakerActions
ForumThread
torequestnewactionsorreportabug
Thecurrentactionlistis:

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
Makesureyoureadthe
GoogleMobileAdGuide
sectionfirst.
WithiAdyoucanusetwotypesofadinterstitialandbanners.Butfirstofallyouneedto
initgoogleadusingthe
GAD_InitGoogleAd
action.
1.Interstitial
Thereistwowaystouseinterstitial.
GAD_StartInterstisialAd
action.WillstartAdloadrequestandassoonthead

loadedwillshowtheinterstitialad.
Use
GAD_LoadInterstisialAd
toloadtheAdcontent.
SuccessEvent
willbe
firedifcontentwasloadedsuccessfullyand
failEvent
ifnot.Aftercontentwas
successfullyloadedyoumayuse
GAD_ShowInterstisialAd
actiontoshowthe
ad.
Youshoulduseoneofthoseapproacheseverytimeyouwanttoshowtheinterstitial
ad.

2.Banners
1)Createadbannerusing
GAD_CreateBanner
action.Ifbannerissuccessfully
created
SuccessEvent
willbefiredand
FailEvent
ifcreationfailed.
DonotfillthebannerIdsection.Itwillbefilledafterbanneriscreate.Storethisid.Itwill
beusedtocontrolcreatebannerwithfollowingplaymakeractions
GAD_HideBanner
willhidethebanner
GAD_ShowBanner
willshowthebanner
GAD_RefreshBanner
willrefreshthebanner
GAD_DestroyBanner
willdestroythebanner

Frequently Asked Questions

Ihaveoneunitidforbannersadandoneforinterstitial,butinitfunctionistaking
onlyoneid.HowshouldIspecifybothofthem?
Ifyouhavetwoidstospecify,youcaninitadmobcontrollerwithforexample
bannersid,andthensetidspecificallyforinterstitial
HowdoIgetanAdMobadunitID?
DirectionsforhowtocreateanAdMobadunitIDcanbefound
here
.AdMobad
unitIDshavetheform
ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN
.

Ikeepgettingtheerror'TheGooglePlayservicesresourceswerenotfound.
Checkyourprojectconfigurationtoensurethattheresourcesareincluded.
Youcansafelyignorethismessage.Yourappwillstillfetchandservebannerads.

Ikeepgettingtheerror'Invalidunknownrequesterror:Cannotdeterminerequest
type.Isyouradunitidcorrect?'
MakesureyouradunitIDiscorrect.ForpublishersusingthenewAdMobfrontend,
theadunitIDwillbeintheform
ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN
.Youwillgetthiserrorif
youusetheform
pub-XXXXXXXXXXXXXXXX
.

Myappsupportautorotation.Butadbannerisnotchangingwhentheappis
rotated.
Theautorotationforbannersisnotsupported.Butyoucanimplementitby
yourself,Iwilldescribealgorithmbelow.
Mostofgameappshaveoneorientation,andthosewhosupportbothasusualus

differentbannerpositionandsizefordifferentorientation.thatwhyIdonotseethe
reasontoimplementautomationautorotation.
1)95%ifuserwillnotbeusethis
2)Userswhowillneedthisfeaturewouldlovetoaddextraenchantments
SoIdecidedtogiveyoufullcontrolonbannersinsteadofimplementingfeatures
thatyouwillnotuse.
Hereisalgorithmhowyoucanusetoimplementcustomautorotatebannertoyour
app.

1)Appstartedatlandscape.
2)Createbannerandassignitto
LandscapeBanner
variable
3)Detectedrotationtoportrait
4)hide
LandscapeBanner
5)Createnewbannerandassignitto
PortraitBanner
variable
6)Detectedrotationtobacktolandscape
7)checkif
LandscapeBanner
wascreated,ifnoseethestep2.
8)Hide
PortraitBanner.
Show
LandscapeBanner

Example Scenes

Example
Thisexamplescenecanbefoundat
Assets/Extensions/GoogleMobileAd/Example/Scenes/Example.

Scenewilldemonstrateusageof
GoogleMobileAdAPI
.
Thecontrollerscript
GoogleAdsExample.cs
isattachedtothe
GoogleAdUseExample
gameobjectandprovidesexampleforAPIcalls.

[
Setup
]
Scenewillworkoutoftheboxafterplugininstallation.Howeverexamplescenewill
useunity_idsfrommytestaccount.

Getyourownidsafter
googleadaccountsetup
.Openthe
Window>
GoogleMobileAds>EditSettings
andenteridsinfollowinglines.
//replace with your ids
BannerAdUnitAd
=
"ca-app-pub-6101605888755494/1824764765"
;
InterstitialsAdUnitAd
=
"ca-app-pub-6101605888755494/3301497967"
;

NoCodingExample
Thisexamplescenecanbefoundat
Assets/Extensions/GoogleMobileAd/Example/Scenes/NoCodingExample.

Scenewilldemonstrateusageof
GoogleMobileAdAPI
withoutanyactions.
ThecontrollerscriptsforBanner
AdMobBanner.cs
andforInterstitial
AdMobBannerInterstitial.cs
areattachedtothe
MyBanner/MyInterstitial
gameobjectsandprovidesexamplesforAPIcalls.

[
Setup
]
Scenewillworkoutoftheboxafterplugininstallation.Howeverexamplescenewill
useunity_idsfrommytestaccount.

You might also like