Ads Wrapper

Ads Wrapper

Ads Wrapper is a wrapper for advertising services. It allows you to use one interface for different services and show ads from different sources. We use this extension all the time in our projects. It simplifies development for different platforms and allows you to create advertising mediation.

Supported services:

Github: https://github.com/potatojam/defold-ads-wrapper

21 Likes

This is amazing! Thank you for sharing! :heart:

5 Likes

Indeed, this is really great! I’ve been thinking of something like this for a while. Thank you!

3 Likes

Is there any method like “is_ads_loaded”?

There is no direct function.
You can manually save the value when using the ad function. Example:

local is_rewarded_loaded = false
ads_wrapper.load_rewarded(function(response)
    if response.result == events.SUCCESS then
          is_rewarded_loaded = true
    end
end)

Or you can find it out for a specific network:

local admob_network = require("ads_wrapper.ads_networks.admob")
admob_network.is_rewarded_loaded()
admob_network.is_interstitial_loaded()
admob_network.is_banner_loaded()

I have not come across a situation where they were needed. I can add such functions for the network pointed to by the mediator, if you need them specifically in ads_wrapper.

3 Likes

Thanks for your work @sergeysinyavsky, would you be kind to please include Appodeal in your extension?

Haven’t worked with Appodeal yet. Maybe I’ll take a look in my free time.
You can add the service you need yourself. You need to implement these functions:

7 Likes

Thanks for the explanation!

These methods are needed, for example

  1. when the game prompts the player to continue playing the level for virtual currency (1) or viewing ADS (2),
  2. or offers to collect a free daily gift (1) or X2 daily gift when viewing ads (2)
    and etc

It’ll be great if you add these methods, or I can add them myself and make pull request :wink:

3 Likes

New version 0.6.2 released.

Some bugs have been fixed.
When loading, the pointer moved to the next network. For now, he remains on the network for which he loaded.

Now you can find out if the ad was loaded. Also you can get used networks.
Functions:

ads_wrapper.is_interstitial_loaded(check_current)
ads_wrapper.is_rewarded_loaded(check_current)
ads_wrapper.is_banner_loaded(check_current)
ads_wrapper.get_current_network(check_banner)
ads_wrapper.get_next_network(check_banner)

If you are using only one network, then the check_current parameter is not needed.

More info about functions:

If you want to add something, feel free to make a pull request. I will be glad!

6 Likes

Awesome!!! Thank you!!!

1 Like

New version 1.0.0 released.

Added Applovin Max network.
It use next extension: https://github.com/alexeyfeskov/defold-maxsdk

Fixed M.show_banner(callback) and M.hide_banner(callback) functions for networks.
Now they should call a function, not return a value.
:warning: These functions need to be fixed if you use your own networks.

8 Likes

New version 1.1.0 released.

Added support for Yandex Mobile Ads SDK
It use next extension: https://github.com/osov/defold-yandex-sdk-ads

10 Likes

hello please what are the steps to add ads to my code i already fetch the library and i am a quite slow learner and i don’t understand examples so how to add interstitial ads or banner ads using unity ads

Hi! You need to add this extension:

Next, you need to configure the Ads Wrapper. For example:

local ads_wrapper = require("ads_wrapper.ads_wrapper")
local unity = require("ads_wrapper.ads_networks.unity")
local platform = require("ads_wrapper.platform")
local unity_net_id = ads_wrapper.register_network(unity, {
    ids = {[platform.PL_ANDROID] = "1401815", [platform.PL_IOS] = "1425385"}, ---Set your id. These are test keys
    [ads_wrapper.T_REWARDED] = "rewardedVideo",
    [ads_wrapper.T_INTERSTITIAL] = "video",
    [ads_wrapper.T_BANNER] = {id = "banner", size = {width = 720, height = 90}, position = unityads.BANNER_POSITION_BOTTOM_RIGHT}
})
ads_wrapper.setup_video({ { id = unity_net_id , count = 1 } })
ads_wrapper.setup_banner({ { id = unity_net_id , count = 1 } })
ads_wrapper.init(true, true, function(response)
        pprint(response)
end)

Then use the following functions to show ads:

ads_wrapper.show_interstitial(callback)
ads_wrapper.show_rewarded(callback)
ads_wrapper.show_banner(callback)
ads_wrapper.hide_banner(callback)
3 Likes

well it’s not showing ads this is my gui_script:

local ads_wrapper = require("ads_wrapper.ads_wrapper")
local unity = require("ads_wrapper.ads_networks.unity")
local platform = require("ads_wrapper.platform")
local unity_net_id = ads_wrapper.register_network(unity, {
	ids = {[platform.PL_ANDROID] = "5283423", [platform.PL_IOS] = "5283422"}, ---Set your id. These are test keys
	[ads_wrapper.T_REWARDED] = "rewardedVideo",
	[ads_wrapper.T_INTERSTITIAL] = "video",
	[ads_wrapper.T_BANNER] = {id = "banner", size = {width = 720, height = 90}, position = unityads.BANNER_POSITION_BOTTOM_RIGHT}
})


function init(self)
	msg.post(".", "acquire_input_focus")

	ads_wrapper.setup_video({ { id = unity_net_id , count = 1 } })
	ads_wrapper.setup_banner({ { id = unity_net_id , count = 1 } })
	ads_wrapper.init(true, true, function(response)
		pprint(response)
	end)
end

function final(self)
	
end

function update(self, dt)
	-- Add update code here
	-- Learn more: https://defold.com/manuals/script/
	-- Remove this function if not needed
end

function on_message(self, message_id, message, sender)
	-- Add message-handling code here
	-- Learn more: https://defold.com/manuals/message-passing/
	-- Remove this function if not needed
end

function on_input(self, action_id, action)
	if action_id == hash("touch") and action.pressed then -- <2>
		local button = gui.get_node("button") -- <3>
		local text = gui.get_node("text") -- <4>
		if gui.pick_node(button, action.x, action.y) then -- <5>
			gui.set_text(text, "HELLO!") -- <6>
			ads_wrapper.show_interstitial(callback)
		end
	end
end

function on_reload(self)
	-- Add reload-handling code here
	-- Learn more: https://defold.com/manuals/hot-reload/
	-- Remove this function if not needed
end

What do you get in response in the init function?

Also here you have to send your callback to see the result of the function. For example:

ads_wrapper.show_interstitial(function(response)
	pprint(response)
end)
{ --[[0x7f446a487b70]]
  result = hash: [SUCCESS],
  message = "Tryed to initialize networks",
  data = { --[[0x7f446a487a20]]
    result = hash: [SUCCESS],
    message = "Networks are missing.",
    responses = { } --[[0x7f446a487ab0]]
  }
}

What did you get in unity_net_id?
Are you running on a mobile device?

this one is not running from my android phone but when i runned from my phone it didn’t show any video ads

We need to look at the errors in the android.
If you have compiled a debug build and are connected to the same network, then you can select a mobile one and see what the errors are there:

1 Like