0

Hi I am working on a game on corona SDK. I just can't figure out how to add vungle or chartboost incentivized ads on it and add virtual rewards after callback.

I searched out for Corona Tutorials but did not find any. I can switch to other SDKs but I don't want to because Corona SDK is my favorite SDK and can never think of using any other SDK. Thank you

Playpunk
  • 13
  • 3

2 Answers2

2

The username for vungle ads is optional, you can view it here: https://docs.coronalabs.com/plugin/vungle/show.html#parameter-reference

You can put your reward code on the "adEnd" event type.

Below is the sample code:

--import vungle ads

local ads = require "ads"

--GET YOUR APP ID FROM VUNGLE
--TEST_Android for Android devices
local appID = "TEST_iOS"

--VUngle ADS Listener
local function vungleAdListener( event )
  if ( event.type == "adStart" and event.isError ) then
    -- Ad has not finished caching and will not play
  end
  if ( event.type == "adStart" and not event.isError ) then
    -- Ad will play
  end
  if ( event.type == "cachedAdAvailable" ) then
    -- Ad has finished caching and is ready to play
  end
  if ( event.type == "adView" ) then
    -- An ad has completed
  end
  if ( event.type == "adEnd" ) then
    -- The ad experience has been closed- this
    -- is a good place to resume your app
    -- Place your reward code here like extra lives, coins etc    

  end
end

--initialize vungle ads
--THIS MUST BE CALLED EARLY SO THAT VUNGLE WILL CACHE THE ADS TO PLAY
--USUALLY TAKES 30 SECS OR LESS ACCORDING TO THE DOCS
ads.init("vungle", appID)

--to show the ads somewhere on your game 
ads.show( "interstitial", { isAnimated=false, isBackButtonEnabled=true } )

EDIT

TO show the ads on a button you can add a widget. To customize a widget you can view more here: https://docs.coronalabs.com/api/library/widget/newButton.html

--INIT WIDGET
local widget = require("widget")

--BUTTON EVENT LISTENER
local function handleButtonEvent( event )

    if ( "ended" == event.phase ) then
    --SHOW ADS        
    ads.show( "interstitial", { isAnimated=false, isBackButtonEnabled=true } )
    end
end


--ADD YOUR BUTTON
local button1 = widget.newButton
{
    left = display.contentWidth/2,
    top = display.contentHeight/2,
    id = "adsButton",
    label = "CLICK ME FOR ADS",
    onEvent = handleButtonEvent
}
JLONG
  • 805
  • 10
  • 20
0

You should look at the Chartboost example project and Vungle example project, those are sample apps that you can adapt in your code.

About the callbacks, do you mean server-to-server callbacks? You have to look at the Vungle/Chartboost websites for more info on how to configure the callbacks in their dashboards.

johlo
  • 5,422
  • 1
  • 18
  • 32
  • I have checked out. But I can't figure out what user stands for in vungle incentivized and how to fill this parameter. – Playpunk Sep 08 '15 at 01:20
  • The `username` parameter you can give in the Corona `ads.show()` is a unique user identifier that your server and the app agrees on. The app needs to get the identifier from the server (by somehow logging in the user). Then you configure Vungle to send the `%user%` parameter in the server-server callback. That way the server knows which user watched an ad. – johlo Sep 08 '15 at 07:29