Easy Ads
The Starters Core
kit comes with the Easy Ads
modules.
These modules:
- Make it easier to use the Appodeal or AppLovin plugins.
- Help ensure ads show when and where you want them.
- Make it easy to hook rewarded ads to your success and failure code.
- Allow you to test your ad logic in the simulator.
Using Easy Ads
This video demonstrates how to use Easy Ads to show Appodeal ads.
Project Settings
Please see the Corona docs for setting up the build.settings file.
Selecting Helper
AppLovin
_G.adsHelper = require( "easy.ads.applovinAds" )
Appodeal
_G.adsHelper = require( "easy.ads.appodealAds" )
Preparation & Initialization
AppLovin
adsHelper.prepare( enabled, adParams )
enabled
- Passtrue
to enable ads, orfalse
to stub out all functions.- Stubbed functions can still be called, but have no effect, making your code easier to write and maintain.
adParams
- Table of optional named parameters to set up ads.testMode
(true
) - Run ads in test mode. Be sure to set this tofalse
when you go to publish.verbose
(false
) - Set to 'true' for detailed messages from event listenerverboseLogging
(false
) - Set to 'true' for detailed output from AooLovin plugin.initDelay
(30
) - Wait this many milliseconds before initializing plugin. This makes your game behave more nicely and prevents the call toinit()
from blocking your first scene load.androidID
(nil
) - AppLovin ad ID for Android if needed.iosID
(nil
) - AppLovin ad ID for iOS if needed.enableFakeAds
(true
) - Iftrue
, show fake ads in simulator.bannerAfterInit
(nil
) - If set, show a banner ad as soon as possible after initializion completes.- To set this, pass in a table:
{ position = "bottom", placement = nil }
, where position is"top"
or"bottom"
. Theplacement
field is optional.
- To set this, pass in a table:
interstitialAfterInit
(nil
) - If set, show an interstitial ad as soon as possible after initializion completes.- To set this, pass in a table:
{ placement = nil }
, where theplacement
field is optional. - Only this or
bannerAfterInit
can be set. If both are set totrue
,bannerAfterInit
will win.
- To set this, pass in a table:
Example
adParams = {
androidID = "BCD4524908adfADFAVDS234523DSNB",
iosID = "LMND124908adfADFAVDS234523DYND",
interstitialAfterInit = {},
}
adsHelper.prepare( true, adParams )
Appodeal
adsHelper.prepare( enabled, adParams )
Example
enabled
- Passtrue
to enable ads, orfalse
to stub out all functions.- Stubbed functions can still be called, but have no effect, making your code easier to write and maintain.
adParams
- Table of optional named parameters to set up ads.testMode
(true
) - Run ads in test mode. Be sure to set this tofalse
when you go to publish.verbose
(false
) - Set to 'true' for detailed messages from event listenerinitDelay
(30
) - Wait this many milliseconds before initializing plugin. This makes your game behave more nicely and prevents the call toinit()
from blocking your first scene load.androidID
(nil
) - Appodeal ad ID for Android if needed.iosID
(nil
) - Appodeal ad ID for iOS if needed.supportedAdTypes
({ "banner", "interstitial", "rewardedVideo" }
) - You can pass in a custom table to reduce the number of ads types that are supported.isCOPPACompliant
(false
) - Iftrue
, show fake ads in simulator.hasGDPRConsent
(nil
) - Ifnil
, it is left up to the plugin to query for GDPR permission in the EU. Iftrue
you are attesting that you have gotten permission from the user to send their data toe Appodeal and affiliates. Iffalse
you are saying the user declines to have their data sent.enableFakeAds
(true
) - Iftrue
, show fake ads in simulator.bannerAfterInit
(nil
) - If set, show a banner ad as soon as possible after initializion completes.- To set this, pass in a table:
{ position = "bottom", placement = nil }
, where position is"top"
or"bottom"
. Theplacement
field is optional.
- To set this, pass in a table:
interstitialAfterInit
(nil
) - If set, show an interstitial ad as soon as possible after initializion completes.- To set this, pass in a table:
{ placement = nil }
, where theplacement
field is optional. - Only this or
bannerAfterInit
can be set. If both are set totrue
,bannerAfterInit
will win.
- To set this, pass in a table:
adParams = {
testMode = true,
verbose = false,
initDelay = 30,
androidID = "BCD4524908adfADFAVDS234523DSNB",
iosID = "LMND124908adfADFAVDS234523DYND",
supportedAdTypes = { "banner", "rewardedVideo" },
isCOPPACompliant = false,
hasGDPRConsent = true,
enableFakeAds = true,
bannerAfterInit = { position = "bottom" },
}
adsHelper.prepare( true, adParams )
Showing Ads
Banners
showBanner( [ position [, placement ] ] )
position
("bottom"
) - Optional argument for position of ad"bottom"
or"top"
placement
(nil
) - Optional argument:
_G.adsHelper.showBanner( "bottom" )
Interstitials
showInterstitial( [ position [, placement ] ] )
onComplete
(nil
) - Function to call when ad is done showing.placement
(nil
) - Optional argument:
local function onComplete()
print("Showed interstital!")
end
_G.adsHelper.showInterstitial( onComplete )
Rewarded Ads
showRewarded( [ onSuccess [, onFailure [, placement ] ] ] )
onSuccess
(nil
) - Function to call when user successfully watches rewarded ad.onFailure
(nil
) - Function to call when user fails to watch rewarded ad.placement
(nil
) - Optional argument:
local function onSuccess()
print("Give reward!")
end
local function onFailure()
print("No Twinky For You!")
end
_G.adsHelper.showRewarded( onSuccess, onFailure, "earn_coins_button" )
Hiding Banners
_G.adsHelper.hideBanner()
Advanced Features
You will probably never need these features, but just in case here are the docs.
Temporary Listeners
You can set up unique listeners that are transient in nature. Once the specific event you are waiting for occurs, these listeners can be removed. Alternately, you can clear them manually.
listen( name, aListener )
Call this function to add a temporary ad listener. You can then clear it as needed.
Example
local function clear()
_G.adsHelper.ignore( "interstitial" )
end
local function interstitialListener( event )
local isError = event.isError
local phase = event.phase
--
if( isError and phase == "rewardedVideo" ) then
clear()
return
end
--
-- Catch all 'ended' equivalent phases and assume that
-- the first one means we have shown the interstitial.
if( phase == "hidden" or phase == "playbackEnded" ) then
clear()
print("Yay! Showed interstial.")
end
end
_G.adsHelper.listen( "interstitial", interstitialListener )
ignore( name )
Call this function to remove a previously added temporary listner.
_G.adsHelper.ignore( "interstitial" )
ignoreAll()
Call this function to remove all temporary listner.
_G.adsHelper.ignoreAll( )
AppLovin Specific Helpers
The AppLovin helper also exposes these functions:
Appodeal Specific Helpers
The Appodeal helper also exposes these functions:
Disabling Helper
If you find that you want to disable all features of the active helper for the remainder of the app run, you can do so with the disableModule()
function. (It can only be called once. Subsequen calls do nothing.)
disableModule( [doCleaning] )
doCleaning
(nil
) - Iftrue
cleanup any temporary listeners that may be active.- This is an advanced feature of the module. Unless you are an expert, always pass
true
if you call this.
- This is an advanced feature of the module. Unless you are an expert, always pass
_G.adsHelper.disableModule( true )
Standard Plugin Features?
You can always use the other features of the AppLovin and Appodeal plugins just like you normally would.
Please see the Corona docs:
Copyright © Roaming Gamer, LLC. 2008-2018; All Rights Reserved