Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How do you use Vungle?
Started by tyrotech123 Mar 31 2015 10:29 AM

18 replies to this topic
vungle ads
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

I'm trying to make a game where a user can gain coins by collecting them when playing the games or by watching video ads. I only want the user to be rewarded if they watch the whole video or click on the ad.

Are there samples of code for this? So far I could only find code samples for displaying the ads, but not to check to see if the user watched the whole video.

 



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,212 posts
  • Enterprise

Here is code I'm using in a game.  The idea here is that when you get an adEnd event, the user watched the whole video or clicked through the ad.  In my case I add 500 the player's energy total and save my settings.  Then update the onscreen text is that screen has the appropriate text object.

 

local function vungleListener(event)
    -- video ad not yet downloaded and available
    if event.type == "adStart" and event.isError then
        print("event.type", event.type, system.getInfo("platformName"))
    elseif event.type == "adEnd" then
        print("ad ended")
        myData.settings.energy = myData.settings.energy + 500
        utility.saveTable(myData.settings, "settings.json")
        if myData.energyText then
            myData.energyText:setText(tostring(myData.settings.energy))
        end
    else
        print( "Received event:")
    end
    return true
end
ads.init("vungle", vendors.vungleID, vungleListener)


[TOPIC: post.html]
#3

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

 

Here is code I'm using in a game.  The idea here is that when you get an adEnd event, the user watched the whole video or clicked through the ad.  In my case I add 500 the player's energy total and save my settings.  Then update the onscreen text is that screen has the appropriate text object.

local function vungleListener(event)
    -- video ad not yet downloaded and available
    if event.type == "adStart" and event.isError then
        print("event.type", event.type, system.getInfo("platformName"))
    elseif event.type == "adEnd" then
        print("ad ended")
        myData.settings.energy = myData.settings.energy + 500
        utility.saveTable(myData.settings, "settings.json")
        if myData.energyText then
            myData.energyText:setText(tostring(myData.settings.energy))
        end
    else
        print( "Received event:")
    end
    return true
end
ads.init("vungle", vendors.vungleID, vungleListener)

Thank you for that code, but whenever I use it event.isError is true.

How am I supposed to implement Vungle into Storyboard (or Composer)? Maybe proper implementation would solve some of my problems? Where do you put ads.init?



[TOPIC: post.html]
#4

jordyn.chuhaloff

[GLOBAL: userInfoPane.html]
jordyn.chuhaloff
  • Enthusiast

  • 49 posts
  • Enterprise

Hi tyrotech123, 

 

I've just created a walk-through guide and a sample app to show a simple integration. Check it out and let me know if it helps, or if anything is unclear. I'll be tweaking it a bit more this week and would appreciate any feedback :)

 

Jordyn

Developer Programs Engineer

Vungle



[TOPIC: post.html]
#5

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

Hi tyrotech123, 

 

I've just created a walk-through guide and a sample app to show a simple integration. Check it out and let me know if it helps, or if anything is unclear. I'll be tweaking it a bit more this week and would appreciate any feedback :)

 

Jordyn

Developer Programs Engineer

Vungle

If you have an ad listener do you still put the ads.init in the main.lua file? Do you need to put the ad listener function in main.lua as well? (I'm using storyboard, so all of my actual code is in different files)



[TOPIC: post.html]
#6

jordyn.chuhaloff

[GLOBAL: userInfoPane.html]
jordyn.chuhaloff
  • Enthusiast

  • 49 posts
  • Enterprise

You'll need to register the ad listener before you call ads.init. You want ads.init to be called as early in the app as possible, so that an ad has time to cache before you call ads.show.  The adListener and init don't necessarily need to be in main, but I believe they should be in the same file.



[TOPIC: post.html]
#7

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

You'll need to register the ad listener before you call ads.init. You want ads.init to be called as early in the app as possible, so that an ad has time to cache before you call ads.show.  The adListener and init don't necessarily need to be in main, but I believe they should be in the same file.

Do you know whether I should put the ads.init in the createScene function or the enterScene function?



[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,212 posts
  • Enterprise

I put my ad listeners and such in main.lua.  You can't guarantee that your storyboard scenes will be in memory when a listener callback fires.

 

I didn't include everything you need since you asked for how to detect when the ad was completed.  You still need to include the Vungle plugin in your build.settings.  You have to require it in main.lua before you call the init call as well.  Then you will need to call ads.show() with the proper parameters to show the ad.

 

Rob



[TOPIC: post.html]
#9

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

I don't know what I'm doing wrong, but it's still not working. I have storyboard.purgeOnSceneChange = true

Could that be messing some stuff up?



[TOPIC: post.html]
#10

jordyn.chuhaloff

[GLOBAL: userInfoPane.html]
jordyn.chuhaloff
  • Enthusiast

  • 49 posts
  • Enterprise

Possibly? It's hard to tell without looking at the project. If you'd like, you can send it to me and I'll see what I can find. Just add @Jordyn somewhere in the email body.

 

tech-support@vungle.com 



[TOPIC: post.html]
#11

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

Possibly? It's hard to tell without looking at the project. If you'd like, you can send it to me and I'll see what I can find. Just add @Jordyn somewhere in the email body.

 

tech-support@vungle.com 

Okay, I sent it



[TOPIC: post.html]
#12

jordyn.chuhaloff

[GLOBAL: userInfoPane.html]
jordyn.chuhaloff
  • Enthusiast

  • 49 posts
  • Enterprise

Thanks for sending that in, looks like it was a very common issue we see- incorrect App ID.

 

When you calls.init, make sure you are passing in the App ID (not the Reporting API ID). You can find your App ID in red on your app's page of the Vungle dashboard. 

 

This is a common mix-up, and we are working on a new dashboard design which will make these more clear.



[TOPIC: post.html]
#13

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

Thanks for sending that in, looks like it was a very common issue we see- incorrect App ID.

 

When you calls.init, make sure you are passing in the App ID (not the Reporting API ID). You can find your App ID in red on your app's page of the Vungle dashboard. 

 

This is a common mix-up, and we are working on a new dashboard design which will make these more clear.

Thank you! Now it works! Is there a way I can force Vungle to load/cache a new ad after one is already seen?



[TOPIC: post.html]
#14

jordyn.chuhaloff

[GLOBAL: userInfoPane.html]
jordyn.chuhaloff
  • Enthusiast

  • 49 posts
  • Enterprise

That will happen automatically, you don't need to do anything :)



[TOPIC: post.html]
#15

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

That will happen automatically, you don't need to do anything :)

It doesn't look like it. Every time I try to see an ad, it gives me the same one (some Vegas slots app).



[TOPIC: post.html]
#16

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

 

Here is code I'm using in a game.  The idea here is that when you get an adEnd event, the user watched the whole video or clicked through the ad.  In my case I add 500 the player's energy total and save my settings.  Then update the onscreen text is that screen has the appropriate text object.

local function vungleListener(event)
    -- video ad not yet downloaded and available
    if event.type == "adStart" and event.isError then
        print("event.type", event.type, system.getInfo("platformName"))
    elseif event.type == "adEnd" then
        print("ad ended")
        myData.settings.energy = myData.settings.energy + 500
        utility.saveTable(myData.settings, "settings.json")
        if myData.energyText then
            myData.energyText:setText(tostring(myData.settings.energy))
        end
    else
        print( "Received event:")
    end
    return true
end
ads.init("vungle", vendors.vungleID, vungleListener)

Also, this code is not working for me. For each condition I want it to change the text of an object, but nothing ever happens. I have all the ad code in one file (the scene in which I am displaying ads). The ad is showing, but it doesn't seem like the ad listener is working

local function adListener(event)
    if (event.type == "adStart" and event.isError) then
	cointext.text="error"
        print("event.type", event.type, system.getInfo("platformName"))
    elseif event.type == "adEnd" then
        dodgestuff.totalcoins = dodgestuff.totalcoins+20
	saver() --Saves the coins coins
	print(coins)
	cointext.text=dodgestuff.totalcoins --should update the coin text
    else
        cointext.text = "else was called..."
    end
    return true
end

ads.init( "vungle", vungleID, adListener )


[TOPIC: post.html]
#17

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,212 posts
  • Enterprise

You might want to put a print at the very top of your listener function to verify what values you're getting.

 

Also make sure you don't have another function called "adListener" too.

 

Rob



[TOPIC: post.html]
#18

tyrotech123

[GLOBAL: userInfoPane.html]
tyrotech123
  • Enthusiast

  • 69 posts
  • Corona SDK

You might want to put a print at the very top of your listener function to verify what values you're getting.

 

Also make sure you don't have another function called "adListener" too.

 

Rob

For some reason it randomly started to work now.

 

Can I used wasCallToActionClicked so the user has to interact with the ad for coins? How would I implement this?



[TOPIC: post.html]
#19

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,212 posts
  • Enterprise

elseif event.type == "adEnd" and event.wasCallToActionClicked then
        dodgestuff.totalcoins = dodgestuff.totalcoins+20
    saver() --Saves the coins coins
    print(coins)
    cointext.text=dodgestuff.totalcoins --should update the coin text

 

When you get an adEnd event, there will be a member variable set called wasCallToActionClicked which is either true or false.  Just check against that condition.

 

Rob




[topic_controls]
[/topic_controls]