Corona Labs is pleased to announce the immediate availability of the Commercial Break plugin.
Modeled after TV commercial breaks, this new plugin from Appsaholic, a division of Perk.com, allows you to play a series of video ads at logical points in your app and optionally reward users with in-game currency and bonuses. For instance, you could award a player with an extra life for each video watched, award them with various coin packs depending on the number of videos watched, or even unlock a secret level in the game.
Learn more about Appsaholic Commercial Break in this video:
Corona implementation
The Commercial Break plugin is very easy to integrate into your apps.
First, set up your apps by registering for Appsaholic and going to the Appsaholic dashboard. From there, simply get an app’s API key.
Next, include the the plugin in your project by adding an entry to the plugins
table of build.settings
:
plugins =
{
["plugin.combre"] =
{
publisherId = "com.appsaholic",
supportedPlatforms = { iphone=true, android=true, osx=true, ["win32-sim"]=true }
},
},
In addition, if building for iOS, you will need to support App Transport Security (ATS) by adding the NSAppTransportSecurity
key to your iOS plist
table:
settings =
{
iphone =
{
plist =
{
NSAppTransportSecurity = { NSAllowsArbitraryLoads=true },
},
},
}
Initializing the plugin
To initialize Commercial Break in your app, simply require()
the plugin, define a basic event listener, and call init() with your API key:
local combre = require( "plugin.combre" )
local apiKey = "[paste your API key between the quotes]"
-- Commercial Break listener function
local function combreListener( event )
if ( event.phase == "complete" ) then
if ( event.success_ads > 0 ) then
-- At least one Commercial Break ad was played
-- Give in-game rewards here, for example an extra life or free coins
end
end
end
-- Specify the listener function to handle Commercial Break events
combre.setEventListener( combreListener )
-- Initialize the Commercial Break SDK
combre.init( apiKey )
Showing a video ad sequence
When you’re ready to show a commercial break, simply call showVideoAd() with up to three arguments:
combre.showVideoAd( maxAds, showCloseButton, showCountdownScreen )
The value for maxAds
(required) can range from 1
to 5
, indicating the maximum number of commercials to play in sequence. The optional showCloseButton
and showCountdownScreen
arguments are simply boolean true
or false
values which control if these two features are enabled or not.
Video ad sequence events
In your listener function, when you get an event.phase
of "complete"
, you can use event.success_ads
to determine how many ads were watched and reward your users accordingly.
In addition, several other event properties are available, so please proceed to the documentation to learn more about managing and handling video ad sequences.
Final notes
- You can obtain a more complete sample project for the Commercial Break plugin on GitHub.
- For full documentation, see the Commercial Break documentation.
In summary
Commercial Break is a great way to reward your users and keep them engaged in your app. If you have questions or need assistance, please visit appsaholic.com or the Corona forums.