Need help to show a banner ad

Hey,

I’m trying to add a banner ad to my video game. So I used this code and I also set the extension (https://github.com/Lerg/extension-admob/archive/master.zip) in my game.project file.

My problem is that the banner doesn’t display once the game is on my phone.
However, I have the message INFO:ADMOB: init in my console…
Of course, in my code, I replaced the ca-app-pub-3940256099942544/2934735716 IDs with my own.

My code :

-- Banner id for iOS and Android.
local banner_id = {
	['iPhone OS'] = 'ca-app-pub-3940256099942544/2934735716',
	Android = 'ca-app-pub-3940256099942544/6300978111'
}
local sysinfo = sys.get_sys_info()

local function listener(event)
	print('admob event type', event.type)
	print('admob event phase', event.phase)
	if event.phase == 'init' then -- Admob has been initialized, now it's safe to load a banner.
		admob.load{
			type = 'banner',
			id = banner_id[sysinfo.system_name],
			size = 'smart',
			position = 'bottom',
			keywords = {'puzzle', 'game'}
		}
	end
end

-- Init Admob.
admob.init{
	test = true, -- ALWAYS use test ads, only disable when submitting to the stores.
	listener = listener
}

Anyone have an idea please ?

What does the device log say?

How to check the device log ? :sweat_smile:

Check this manual: Debugging - game and system logs

Sent u the logs in private message :slight_smile:

We can’t really spend time on one-on-one support so please share logs here in the public so that everyone can help out. Redact any private information if needed.

The logs you sent me didn’t show anything of interest. An unfiltered log (you filtered on info coming from Defold) may help.

But first please try the official AdMob extension and see if that makes any difference:

There’s an example project bundled with the extension. Please try the example and verify that it works on your phone.

1 Like

No problems, i understand.
So, i tested the example projec t on my phone and it works perfectly.
This is the script i must use to show a banner ?

local dirtylarry = require "dirtylarry/dirtylarry"

local MAX_LOG_LINES = 10

--log logic
local gprint = print
local log = {}
local text = ""
_G.print = function(...)
    gprint(...)
    local args = {...}
    local num = #log+1
    log[num] = "--"
    for k, v in pairs(args) do
        log[num] = log[num] .. tostring(v) .. " "
    end
    log[num] = log[num] .. "\n"
    text = ""
    if num > MAX_LOG_LINES then
        table.remove(log, 1)
    end
    for k, v in pairs(log) do
        text = text .. v
    end
end

function update()
    gui.set_text(gui.get_node("console"), text)
end
-- end log logic

local function update_ui(self)
    gui.set_enabled(gui.get_node("inited"), self.initialized)
    gui.set_enabled(gui.get_node("initialization_box"), not self.initialized)
    if self.ad_type then
        gui.set_enabled(gui.get_node("load_ad/larrybutton"), true)
        gui.set_enabled(gui.get_node("hide_ad/larrybutton"), false)
        gui.set_enabled(gui.get_node("destroy_ad/larrybutton"), false)
        if self.ad_type == admob.MSG_INTERSTITIAL then
            gui.set_enabled(gui.get_node("show_ad/larrybutton"), admob.is_interstitial_loaded())
        elseif self.ad_type == admob.MSG_REWARDED then
            gui.set_enabled(gui.get_node("show_ad/larrybutton"), admob.is_rewarded_loaded())
        elseif self.ad_type == admob.MSG_BANNER then
            local is_banner_loaded = admob.is_banner_loaded()
            gui.set_enabled(gui.get_node("show_ad/larrybutton"), is_banner_loaded)
            gui.set_enabled(gui.get_node("hide_ad/larrybutton"), is_banner_loaded)
            gui.set_enabled(gui.get_node("destroy_ad/larrybutton"), is_banner_loaded)
        end
    else
        gui.set_enabled(gui.get_node("load_ad/larrybutton"), false)
        gui.set_enabled(gui.get_node("show_ad/larrybutton"), false)
        gui.set_enabled(gui.get_node("hide_ad/larrybutton"), false)
        gui.set_enabled(gui.get_node("destroy_ad/larrybutton"), false)
    end
end

local function set_block_height(height)
    -- use banner height in gui
    local screen_width, screen_height = window.get_size()
    local settings_height = tonumber(sys.get_config("display.height"))
    local mult = screen_height/settings_height
    local height_b_node = gui.get_node("height_b")
    local size = gui.get_size(height_b_node)
    size.y = height/mult
    gui.set_size(height_b_node, size)
end

local function admob_callback(self, message_id, message)
    if message_id == admob.MSG_INITIALIZATION then
        self.initialized = true
        if message.event == admob.EVENT_COMPLETE then
            print("EVENT_COMPLETE: Initialization complete")
        elseif message.event == admob.EVENT_JSON_ERROR then
            print("EVENT_JSON_ERROR: Internal NE json error "..message.error)
        end
    elseif message_id == admob.MSG_IDFA then
        if message.event == admob.EVENT_STATUS_AUTORIZED then
            print("EVENT_STATUS_AUTORIZED: ATTrackingManagerAuthorizationStatusAuthorized")
        elseif message.event == admob.EVENT_STATUS_DENIED then
            print("EVENT_STATUS_DENIED: ATTrackingManagerAuthorizationStatusDenied")
        elseif message.event == admob.EVENT_STATUS_NOT_DETERMINED then
            print("EVENT_STATUS_NOT_DETERMINED: ATTrackingManagerAuthorizationStatusNotDetermined")
        elseif message.event == admob.EVENT_STATUS_RESTRICTED then
            print("EVENT_STATUS_RESTRICTED: ATTrackingManagerAuthorizationStatusRestricted")
        elseif message.event == admob.EVENT_NOT_SUPPORTED then
            print("EVENT_NOT_SUPPORTED: IDFA request not supported on this platform or OS version")
        end
    elseif message_id == admob.MSG_INTERSTITIAL then
        if message.event == admob.EVENT_CLOSED then
            print("EVENT_CLOSED: Interstitial AD closed")
        elseif message.event == admob.EVENT_FAILED_TO_SHOW then
            print("EVENT_FAILED_TO_SHOW: Interstitial AD failed to show\nCode: "..message.code.."\nError: "..message.error)
        elseif message.event == admob.EVENT_OPENING then
            -- on android this event fire only when ADS activity closed =(
            print("EVENT_OPENING: Interstitial AD is opening")
        elseif message.event == admob.EVENT_FAILED_TO_LOAD then
            print("EVENT_FAILED_TO_LOAD: Interstitial AD failed to load\nCode: "..message.code.."\nError: "..message.error)
        elseif message.event == admob.EVENT_LOADED then
            print("EVENT_LOADED: Interstitial AD loaded")
        elseif message.event == admob.EVENT_NOT_LOADED then
            print("EVENT_NOT_LOADED: can't call show_interstitial() before EVENT_LOADED\nError: "..message.error)
        elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
            print("EVENT_IMPRESSION_RECORDED: Interstitial did record impression")
        elseif message.event == admob.EVENT_CLICKED then
            print("EVENT_CLICKED: Interstitial clicked")
        elseif message.event == admob.EVENT_JSON_ERROR then
            print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
        end
    elseif message_id == admob.MSG_REWARDED then
        if message.event == admob.EVENT_CLOSED then
            print("EVENT_CLOSED: Rewarded AD closed")
        elseif message.event == admob.EVENT_FAILED_TO_SHOW then
            print("EVENT_FAILED_TO_SHOW: Rewarded AD failed to show\nCode: "..message.code.."\nError: "..message.error)
        elseif message.event == admob.EVENT_OPENING then
            -- on android this event fire only when ADS activity closed =(
            print("EVENT_OPENING: Rewarded AD is opening")
        elseif message.event == admob.EVENT_FAILED_TO_LOAD then
            print("EVENT_FAILED_TO_LOAD: Rewarded AD failed to load\nCode: "..message.code.."\nError: "..message.error)
        elseif message.event == admob.EVENT_LOADED then
            print("EVENT_LOADED: Rewarded AD loaded")
        elseif message.event == admob.EVENT_NOT_LOADED then
            print("EVENT_NOT_LOADED: can't call show_rewarded() before EVENT_LOADED\nError: "..message.error)
        elseif message.event == admob.EVENT_EARNED_REWARD then
            print("EVENT_EARNED_REWARD: Reward: " .. tostring(message.amount) .. " " .. tostring(message.type))
        elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
            print("EVENT_IMPRESSION_RECORDED: Rewarded did record impression")
        elseif message.event == admob.EVENT_CLICKED then
            print("EVENT_CLICKED: Rewarded clicked")
        elseif message.event == admob.EVENT_JSON_ERROR then
            print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
        end
    elseif message_id == admob.MSG_BANNER then
        if message.event == admob.EVENT_LOADED then
            print("EVENT_LOADED: Banner AD loaded. Height: "..message.height.."px Width: "..message.width.."px")
            set_block_height(message.height)
        elseif message.event == admob.EVENT_OPENING then
            print("EVENT_OPENING: Banner AD is opening")
        elseif message.event == admob.EVENT_FAILED_TO_LOAD then
            print("EVENT_FAILED_TO_LOAD: Banner AD failed to load\nCode: "..message.code.."\nError: "..message.error)
        elseif message.event == admob.EVENT_CLICKED then
            print("EVENT_CLICKED: Banner AD clicked")
        elseif message.event == admob.EVENT_CLOSED then
            print("EVENT_CLOSED: Banner AD closed")
        elseif message.event == admob.EVENT_DESTROYED then
            print("EVENT_DESTROYED: Banner AD destroyed")
        elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
            print("EVENT_IMPRESSION_RECORDED: Banner did record impression")
        elseif message.event == admob.EVENT_JSON_ERROR then
            print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
        end
    end
    update_ui(self)
end

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

    local engine_info = sys.get_engine_info()
    self.is_debug = engine_info.is_debug

    if self.is_debug then
        -- Always test ONLY with test ads units when you test integration!
        if sys.get_sys_info().system_name == 'iPhone OS' then
            -- https://developers.google.com/admob/ios/test-ads
            self.banner_ad_unit = "ca-app-pub-3940256099942544/2934735716" -- test unit for banners
            self.interstitial_ad_unit = "ca-app-pub-3940256099942544/4411468910" -- test unit for interstitial
            self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/1712485313" -- test unit for rewarded
        else --Android
            -- From https://developers.google.com/admob/android/test-ads
            self.banner_ad_unit = "ca-app-pub-3940256099942544/6300978111" -- test unit for banners
            self.interstitial_ad_unit = "ca-app-pub-3940256099942544/1033173712" -- test unit for interstitial
            self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/5224354917" -- test unit for rewarded
        end
    else
        -- Always test ONLY with test ads units when you test integration!
        --  !!! Replace this keys with your own keys : 
        -- https://developers.google.com/admob/android/quick-start#set_up_your_app_in_your_admob_account
        if sys.get_sys_info().system_name == 'iPhone OS' then
            self.banner_ad_unit = "ca-app-pub-3940256099942544/2934735716" -- !!! replace it with iOS banner unit
            self.interstitial_ad_unit = "ca-app-pub-3940256099942544/4411468910" -- !!! replace it with iOS interstitial unit
            self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/1712485313" --  !!! replace it with iOS rewarded unit
        else --Android
            self.banner_ad_unit = "ca-app-pub-3940256099942544/6300978111" --  !!! replace it with Android banner unit
            self.interstitial_ad_unit = "ca-app-pub-3940256099942544/1033173712" -- !!! replace it with Android interstitial unit
            self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/5224354917" -- !!! replace it with Android rewarded unit
        end
    end

    self.show_pos = 1
    self.banner_positions = {
        "POS_BOTTOM_CENTER",
        "POS_BOTTOM_LEFT",
        "POS_BOTTOM_RIGHT",
        "POS_NONE",
        "POS_TOP_LEFT",
        "POS_TOP_CENTER",
        "POS_TOP_RIGHT",
        "POS_CENTER"
    }

    -- `admob` works only on iOS and Android, make sure the extension is available
    if admob then
        -- !!! Set callback before initialization
        admob.set_callback(admob_callback)
        -- !!! Read documentation about privacy settings and use the following method if you need to apply it
        -- https://developers.google.com/admob/ios/ccpa
        -- https://developers.google.com/admob/android/ccpa
        admob.set_privacy_settings(true)
    end
    update_ui(self)
end

function on_input(self, action_id, action)
    if not admob then
        return
    end
    
    local prev_type = self.ad_type

    if gui.is_enabled(gui.get_node("initialization_box")) then
        dirtylarry:button("initialization", action_id, action, function ()
            print("admob.initialize()")
            admob.initialize()
        end)

        dirtylarry:button("idfa", action_id, action, function ()
            print("admob.request_idfa()")
            admob.request_idfa()
        end)
    end
    
    self.ad_type = dirtylarry:radio("ad_type_interstitial", action_id, action, admob.MSG_INTERSTITIAL, self.ad_type)
    self.ad_type = dirtylarry:radio("ad_type_rewarded", action_id, action, admob.MSG_REWARDED, self.ad_type)
    self.ad_type = dirtylarry:radio("ad_type_banner", action_id, action, admob.MSG_BANNER, self.ad_type)
    
    if prev_type ~= self.ad_type then
        update_ui(self)
    end

    if gui.is_enabled(gui.get_node("load_ad/larrybutton")) then
        dirtylarry:button("load_ad", action_id, action, function ()
            if self.ad_type == 0 then
            elseif self.ad_type == admob.MSG_INTERSTITIAL then
                print("admob.load_interstitial()")
                admob.load_interstitial(self.interstitial_ad_unit)
            elseif self.ad_type == admob.MSG_REWARDED then
                print("admob.load_rewarded()")
                admob.load_rewarded(self.rewardedvideo_ad_unit)
            elseif self.ad_type == admob.MSG_BANNER then
                print("admob.load_banner()")
                -- 2nd parameter size, adaptive banner by default:
                -- https://developers.google.com/admob/android/banner/adaptive?hl=en
                admob.load_banner(self.banner_ad_unit)
            end
        end)
    end

    if gui.is_enabled(gui.get_node("show_ad/larrybutton")) then
        dirtylarry:button("show_ad", action_id, action, function ()
            if self.ad_type == 0 then
            elseif self.ad_type == admob.MSG_INTERSTITIAL then
                print("admob.show_interstitial()")
                admob.show_interstitial()
            elseif self.ad_type == admob.MSG_REWARDED then
                print("admob.show_rewarded()")
                admob.show_rewarded()
            elseif self.ad_type == admob.MSG_BANNER then
                print("admob.show_banner( admob."..self.banner_positions[self.show_pos]..")")
                admob.show_banner(admob[self.banner_positions[self.show_pos]])
                self.show_pos = self.show_pos + 1
                if self.show_pos > #self.banner_positions then
                    self.show_pos = 1
                end
            end
        end)
    end
    
    if gui.is_enabled(gui.get_node("hide_ad/larrybutton")) then
        dirtylarry:button("hide_ad", action_id, action, function ()
            if self.ad_type == admob.MSG_BANNER then
                print("admob.hide_banner()")
                admob.hide_banner()
            end
        end)
    end

    if gui.is_enabled(gui.get_node("destroy_ad/larrybutton")) then
        dirtylarry:button("destroy_ad", action_id, action, function ()
            if self.ad_type == admob.MSG_BANNER then
                print("admob.destroy_banner()")
                admob.destroy_banner()
            end
        end)
    end

    if gui.is_enabled(gui.get_node("show_ad_inspector/larrybutton")) then
        dirtylarry:button("show_ad_inspector", action_id, action, function ()
            print("admob.show_ad_inspector()")
            admob.show_ad_inspector()
        end)
    end

end

Good to hear that it worked. You don’t need that full script since it’s for showcasing all of the functionality. Extract what you need from the script. Use it as an example!

1 Like

Thanks!
So this script should work fine ?

local function admob_callback(self, message_id, message)
	if message_id == admob.MSG_INITIALIZATION then
		self.initialized = true
		if message.event == admob.EVENT_COMPLETE then
			print("EVENT_COMPLETE: Initialization complete")
		end
	elseif message_id == admob.MSG_BANNER then
		if message.event == admob.EVENT_LOADED then
			print("EVENT_LOADED: Banner AD loaded. Height: "..message.height.."px Width: "..message.width.."px")
			set_block_height(message.height)
		elseif message.event == admob.EVENT_OPENING then
			print("EVENT_OPENING: Banner AD is opening")
		elseif message.event == admob.EVENT_FAILED_TO_LOAD then
			print("EVENT_FAILED_TO_LOAD: Banner AD failed to load\nCode: "..message.code.."\nError: "..message.error)
		elseif message.event == admob.EVENT_CLICKED then
			print("EVENT_CLICKED: Banner AD clicked")
		elseif message.event == admob.EVENT_CLOSED then
			print("EVENT_CLOSED: Banner AD closed")
		elseif message.event == admob.EVENT_DESTROYED then
			print("EVENT_DESTROYED: Banner AD destroyed")
		elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
			print("EVENT_IMPRESSION_RECORDED: Banner did record impression")
		elseif message.event == admob.EVENT_JSON_ERROR then
			print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
		end
	end
end

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

	local engine_info = sys.get_engine_info()
	self.is_debug = engine_info.is_debug

	if self.is_debug then
		-- Always test ONLY with test ads units when you test integration!
		if sys.get_sys_info().system_name == 'iPhone OS' then
			-- https://developers.google.com/admob/ios/test-ads
			self.banner_ad_unit = "ca-app-pub-3940256099942544/2934735716" -- test unit for banners
			self.interstitial_ad_unit = "ca-app-pub-3940256099942544/4411468910" -- test unit for interstitial
			self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/1712485313" -- test unit for rewarded
		else --Android
			-- From https://developers.google.com/admob/android/test-ads
			self.banner_ad_unit = "ca-app-pub-3940256099942544/6300978111" -- test unit for banners
			self.interstitial_ad_unit = "ca-app-pub-3940256099942544/1033173712" -- test unit for interstitial
			self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/5224354917" -- test unit for rewarded
		end
	else
		-- Always test ONLY with test ads units when you test integration!
		--  !!! Replace this keys with your own keys : 
		-- https://developers.google.com/admob/android/quick-start#set_up_your_app_in_your_admob_account
		if sys.get_sys_info().system_name == 'iPhone OS' then
			self.banner_ad_unit = "ca-app-pub-3940256099942544/2934735716" -- !!! replace it with iOS banner unit
			self.interstitial_ad_unit = "ca-app-pub-3940256099942544/4411468910" -- !!! replace it with iOS interstitial unit
			self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/1712485313" --  !!! replace it with iOS rewarded unit
		else --Android
			self.banner_ad_unit = "ca-app-pub-3940256099942544/6300978111" --  !!! replace it with Android banner unit
			self.interstitial_ad_unit = "ca-app-pub-3940256099942544/1033173712" -- !!! replace it with Android interstitial unit
			self.rewardedvideo_ad_unit = "ca-app-pub-3940256099942544/5224354917" -- !!! replace it with Android rewarded unit
		end
	end

	self.show_pos = 1
	self.banner_positions = {
		"POS_BOTTOM_CENTER",
		"POS_BOTTOM_LEFT",
		"POS_BOTTOM_RIGHT",
		"POS_NONE",
		"POS_TOP_LEFT",
		"POS_TOP_CENTER",
		"POS_TOP_RIGHT",
		"POS_CENTER"
	}

	-- `admob` works only on iOS and Android, make sure the extension is available
	if admob then
		-- !!! Set callback before initialization
		admob.set_callback(admob_callback)
		-- !!! Read documentation about privacy settings and use the following method if you need to apply it
		-- https://developers.google.com/admob/ios/ccpa
		-- https://developers.google.com/admob/android/ccpa
		admob.set_privacy_settings(true)
	end
end

function on_input(self, action_id, action)
	if not admob then
		return
	end

	local prev_type = self.ad_type
	admob.initialize()
end

self.ad_type = dirtylarry:radio("ad_type_banner", action_id, action, admob.MSG_BANNER, self.ad_type)
admob.load_banner(self.banner_ad_unit)
print("admob.show_banner( admob."..self.banner_positions[self.show_pos]..")")
admob.show_banner(admob[self.banner_positions[self.show_pos]])
self.show_pos = self.show_pos + 1
if self.show_pos > #self.banner_positions then
	self.show_pos = 1
end

this code is in a ads.gui_script

You probably shouldn’t call admod.initialize() for all inputs.

It’s hard for us to guess the specifics without spending time on reading and analyzing your script.

If you have an issue, it’s better to mention the issue, and what errors you get.

Otherwise, I recommend you try the example script, and then removing parts of the functionality you think you don’t need, and debugging the behavior on your end.

when i call it so?

Okay so, i debugged my project and i don’t get any errors but ads are not showing.
Also, here is my game.project file configuration for Admob :

[admob]
app_id_ios = ca-app-pub-1641647182019187~HERE-I-REPLACED-BY-MY-ID
app_id_android = ca-app-pub-1641647182019187~HERE-I-REPLACED-BY-MY-ID
ios_tracking_usage_description = Your data will be used to provide you a better and personalized ad experience.

Here my ads.gui_script :

local function admob_callback(self, message_id, message)
	if message_id == admob.MSG_INITIALIZATION then
		self.initialized = true
		if message.event == admob.EVENT_COMPLETE then
			print("EVENT_COMPLETE: Initialization complete")
		end
	elseif message_id == admob.MSG_BANNER then
		if message.event == admob.EVENT_LOADED then
			print("EVENT_LOADED: Banner AD loaded. Height: "..message.height.."px Width: "..message.width.."px")
			set_block_height(message.height)
		elseif message.event == admob.EVENT_OPENING then
			print("EVENT_OPENING: Banner AD is opening")
		elseif message.event == admob.EVENT_FAILED_TO_LOAD then
			print("EVENT_FAILED_TO_LOAD: Banner AD failed to load\nCode: "..message.code.."\nError: "..message.error)
		elseif message.event == admob.EVENT_CLICKED then
			print("EVENT_CLICKED: Banner AD clicked")
		elseif message.event == admob.EVENT_CLOSED then
			print("EVENT_CLOSED: Banner AD closed")
		elseif message.event == admob.EVENT_DESTROYED then
			print("EVENT_DESTROYED: Banner AD destroyed")
		elseif message.event == admob.EVENT_IMPRESSION_RECORDED then
			print("EVENT_IMPRESSION_RECORDED: Banner did record impression")
		elseif message.event == admob.EVENT_JSON_ERROR then
			print("EVENT_JSON_ERROR: Internal NE json error: "..message.error)
		end
	end
end

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

	local engine_info = sys.get_engine_info()
	self.is_debug = engine_info.is_debug

	if self.is_debug then
		-- Always test ONLY with test ads units when you test integration!
		if sys.get_sys_info().system_name == 'iPhone OS' then
			-- https://developers.google.com/admob/ios/test-ads
			self.banner_ad_unit = "ca-app-pub-1641647182019187/HERE-I-REPLACED-BY-MY-ID" -- test unit for banners
		else --Android
			-- From https://developers.google.com/admob/android/test-ads
			self.banner_ad_unit = "ca-app-pub-1641647182019187/HERE-I-REPLACED-BY-MY-ID" -- test unit for banners
		end
	else
		-- Always test ONLY with test ads units when you test integration!
		--  !!! Replace this keys with your own keys : 
		-- https://developers.google.com/admob/android/quick-start#set_up_your_app_in_your_admob_account
		if sys.get_sys_info().system_name == 'iPhone OS' then
			self.banner_ad_unit = "ca-app-pub-1641647182019187/HERE-I-REPLACED-BY-MY-ID" -- !!! replace it with iOS banner unit
		else --Android
			self.banner_ad_unit = "ca-app-pub-1641647182019187/HERE-I-REPLACED-BY-MY-ID" --  !!! replace it with Android banner unit
		end
	end

	self.show_pos = 1
	self.banner_positions = {
		"POS_BOTTOM_CENTER",
		"POS_BOTTOM_LEFT",
		"POS_BOTTOM_RIGHT",
		"POS_NONE",
		"POS_TOP_LEFT",
		"POS_TOP_CENTER",
		"POS_TOP_RIGHT",
		"POS_CENTER"
	}

	-- `admob` works only on iOS and Android, make sure the extension is available
	if admob then
		-- !!! Set callback before initialization
		admob.set_callback(admob_callback)
		-- !!! Read documentation about privacy settings and use the following method if you need to apply it
		-- https://developers.google.com/admob/ios/ccpa
		-- https://developers.google.com/admob/android/ccpa
		admob.set_privacy_settings(true)
	end
end

function on_input(self, action_id, action)
	if not admob then
		return
	end

	local prev_type = self.ad_type
	admob.initialize()
end

self.ad_type = dirtylarry:radio("ad_type_banner", action_id, action, admob.MSG_BANNER, self.ad_type)
admob.load_banner(self.banner_ad_unit)
print("admob.show_banner( admob."..self.banner_positions[self.show_pos]..")")
admob.show_banner(admob[self.banner_positions[self.show_pos]])
self.show_pos = self.show_pos + 1
if self.show_pos > #self.banner_positions then
	self.show_pos = 1
end

Obviously, i replaced the ca-app-pub-1641647182019187/HERE-I-REPLACED-BY-MY-ID by the reals Android & IOS ID’s.

And, does it work with the test id?

I’m gonna try

nah, ads are not showing when i debug but i get this in my console :
INFO:Admob: Registered extension Admob (null)

You need to figure out what you changed, since the example was working, and now it doesn’t.

This code is outside of the lifecycle functions. You can’t run that type of code there. All code must be run as a response to a lifecycle function, for instance on init, on_message or on_input.