# Ads Wrapper

**URL:** <https://forum.defold.com/t/ads-wrapper/70718>\
**Category:** The Defoldmine\
**Created:** [April 14, 2022, 4:36pm UTC](https://forum.defold.com/t/ads-wrapper/70718 "2022-04-14T16:36:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [April 14, 2022, 4:36pm UTC](https://forum.defold.com/t/ads-wrapper/70718/1 "2022-04-14T16:36:38Z")

</div>

![ads_wrapper](https://forum-defold-uploads.b-cdn.net/original/3X/b/5/b5368e5725a55fc1735f2ba53f9ff72466e8b86b.png)

### 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:

- [Admob](https://github.com/potatojam/defold-ads-wrapper#ads-wrapper-for-defold)
- [Unity Ads](https://github.com/potatojam/defold-ads-wrapper#ads-wrapper-for-defold)
- [Poki](https://github.com/potatojam/defold-ads-wrapper#ads-wrapper-for-defold)
- [Yandex](https://github.com/potatojam/defold-ads-wrapper#ads-wrapper-for-defold)
- [Yandex Mobile Ads](https://github.com/potatojam/defold-ads-wrapper#ads-wrapper-for-defold)
- [Vk Bridge](https://github.com/potatojam/defold-ads-wrapper#ads-wrapper-for-defold)
- [Applovin Max](https://github.com/potatojam/defold-ads-wrapper#ads-wrapper-for-defold)

Github: [GitHub - potatojam/defold-ads-wrapper: Universal wrapper for ADS on different platforms · GitHub](https://github.com/potatojam/defold-ads-wrapper)

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/a/f/afb0923291cdc45bdcc2f52292964667013d1bfd.png)

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [April 14, 2022, 6:06pm UTC](https://forum.defold.com/t/ads-wrapper/70718/2 "2022-04-14T18:06:43Z")

</div>

This is amazing! Thank you for sharing! ❤

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 15, 2022, 4:33am UTC](https://forum.defold.com/t/ads-wrapper/70718/3 "2022-04-15T04:33:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Miko-Laj](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/miko-laj/32/26128_2.png) [@Miko-Laj](https://forum.defold.com/u/Miko-Laj)\
**Post date:** [April 16, 2022, 10:37am UTC](https://forum.defold.com/t/ads-wrapper/70718/4 "2022-04-16T10:37:55Z")

</div>

Is there any method like “is\_ads\_loaded”?

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [April 17, 2022, 9:50am UTC](https://forum.defold.com/t/ads-wrapper/70718/5 "2022-04-17T09:50:11Z")

</div>

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**.

---

<div class="post-metadata">

**Author:** ![LimitlessDonald](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/limitlessdonald/32/25524_2.png) [@LimitlessDonald](https://forum.defold.com/u/LimitlessDonald)\
**Post date:** [April 17, 2022, 10:09am UTC](https://forum.defold.com/t/ads-wrapper/70718/6 "2022-04-17T10:09:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [April 17, 2022, 10:50am UTC](https://forum.defold.com/t/ads-wrapper/70718/7 "2022-04-17T10:50:18Z")

</div>

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:  
[https://github.com/potatojam/defold-ads-wrapper#network-creation](https://github.com/potatojam/defold-ads-wrapper#network-creation)

---

<div class="post-metadata">

**Author:** ![Miko-Laj](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/miko-laj/32/26128_2.png) [@Miko-Laj](https://forum.defold.com/u/Miko-Laj)\
**Post date:** [April 17, 2022, 7:26pm UTC](https://forum.defold.com/t/ads-wrapper/70718/8 "2022-04-17T19:26:39Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [April 18, 2022, 9:17am UTC](https://forum.defold.com/t/ads-wrapper/70718/9 "2022-04-18T09:17:39Z")

</div>

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:  
[https://github.com/potatojam/defold-ads-wrapper#ads\_wrapperis\_interstitial\_loadedcheck\_current](https://github.com/potatojam/defold-ads-wrapper#ads_wrapperis_interstitial_loadedcheck_current)

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

---

<div class="post-metadata">

**Author:** ![Miko-Laj](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/miko-laj/32/26128_2.png) [@Miko-Laj](https://forum.defold.com/u/Miko-Laj)\
**Post date:** [April 18, 2022, 9:23am UTC](https://forum.defold.com/t/ads-wrapper/70718/10 "2022-04-18T09:23:10Z")

</div>

Awesome!!! Thank you!!!

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [August 24, 2022, 8:09pm UTC](https://forum.defold.com/t/ads-wrapper/70718/11 "2022-08-24T20:09:27Z")

</div>

New version 1.0.0 released.

Added **Applovin Max** network.  
It use next extension: [GitHub - alexeyfeskov/defold-maxsdk · GitHub](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.  
⚠ These functions need to be fixed if you use your own networks.

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [December 6, 2022, 5:53pm UTC](https://forum.defold.com/t/ads-wrapper/70718/12 "2022-12-06T17:53:30Z")

</div>

New version 1.1.0 released.

Added support for Yandex Mobile Ads SDK  
It use next extension: [GitHub - osov/defold-yandex-sdk-ads · GitHub](https://github.com/osov/defold-yandex-sdk-ads)

---

<div class="post-metadata">

**Author:** ![OURABIG](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ourabig/32/29701_2.png) [@OURABIG](https://forum.defold.com/u/OURABIG)\
**Post date:** [May 20, 2023, 7:01pm UTC](https://forum.defold.com/t/ads-wrapper/70718/13 "2023-05-20T19:01:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [May 20, 2023, 8:11pm UTC](https://forum.defold.com/t/ads-wrapper/70718/14 "2023-05-20T20:11:49Z")

</div>

Hi! You need to add this extension:  
[https://github.com/AGulev/DefVideoAds/archive/refs/tags/4.6.1.zip](https://github.com/AGulev/DefVideoAds/archive/refs/tags/4.6.1.zip)

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)

```

---

<div class="post-metadata">

**Author:** ![OURABIG](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ourabig/32/29701_2.png) [@OURABIG](https://forum.defold.com/u/OURABIG)\
**Post date:** [May 21, 2023, 11:12am UTC](https://forum.defold.com/t/ads-wrapper/70718/16 "2023-05-21T11:12:28Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [May 21, 2023, 11:46am UTC](https://forum.defold.com/t/ads-wrapper/70718/17 "2023-05-21T11:46:57Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![OURABIG](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ourabig/32/29701_2.png) [@OURABIG](https://forum.defold.com/u/OURABIG)\
**Post date:** [May 21, 2023, 12:25pm UTC](https://forum.defold.com/t/ads-wrapper/70718/18 "2023-05-21T12:25:55Z")

</div>

```
{ --[[0x7f446a487b70]]
  result = hash: [SUCCESS],
  message = "Tryed to initialize networks",
  data = { --[[0x7f446a487a20]]
    result = hash: [SUCCESS],
    message = "Networks are missing.",
    responses = { } --[[0x7f446a487ab0]]
  }
}

```

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [May 21, 2023, 12:41pm UTC](https://forum.defold.com/t/ads-wrapper/70718/19 "2023-05-21T12:41:02Z")

</div>

What did you get in **unity\_net\_id**?  
Are you running on a mobile device?

---

<div class="post-metadata">

**Author:** ![OURABIG](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ourabig/32/29701_2.png) [@OURABIG](https://forum.defold.com/u/OURABIG)\
**Post date:** [May 21, 2023, 12:46pm UTC](https://forum.defold.com/t/ads-wrapper/70718/20 "2023-05-21T12:46:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sergeysinyavsky](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sergeysinyavsky/32/20991_2.png) [@sergeysinyavsky](https://forum.defold.com/u/sergeysinyavsky)\
**Post date:** [May 21, 2023, 12:58pm UTC](https://forum.defold.com/t/ads-wrapper/70718/21 "2023-05-21T12:58:50Z")

</div>

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:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/6/5/655e721454bb982007b7a282233eed9bbbc33e88.png)

[Next page](https://forum.defold.com/t/ads-wrapper/70718.md?page=2)
