Admob GDPR consent message

Today I received a request to add consent-form to my application. I created an application form in admob and added the following to the code (I used code from this forum). I want to ask if I can publish this calmly? Isn’t there something that needs to be done? I am quite confused.

local function adListener( event )
  if ( event.phase == "init" ) then
    admob.updateConsentForm({ underage=false })

    timer.performWithDelay( 1000, function()
        formStatus, consentStatus = admob.getConsentFormStatus()

        if (formStatus == "available") then
            admob.loadConsentForm()
        end
    end )
  end

  if (event.phase == "loaded" and event.type == "ump" and consentStatus=="required") then
    admob.showConsentForm()
  end
  
  if (not admob.isLoaded( "interstitial" ) ) then
    if ( event.phase == "init" ) then
        -- Load an AdMob interstitial ad
      admob.load( "interstitial", { adUnitId="..." } )
    elseif ( event.phase == "closed" ) then
      -- Preload the ad again
      admob.load( "interstitial", { adUnitId="..." } )
    elseif ( event.phase == "failed" ) then
      -- Preload the ad again
      admob.load( "interstitial", { adUnitId="..." } )
    end
  end
end

admob.init( adListener, { appId=... )
1 Like

Hi, in theory, that’s all you need to do in order for your ad to appear in the game, but for example, displaying the banner ad doesn’t work for me after I accept the gdpr message, I’ve tried many codes and none of them worked, did you manage to solve it? can i ask for help

In my applications, after consent is displayed, I use this code to display ads. It works for me.

local admob = require( “plugin.admob” )
local interstitialAppID = “ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxxx”

local function adListener( event )

if (event.phase == "init") then  
   admob.load( "interstitial", { adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx" } )
end

if event.phase == "closed" then
if event.type == "interstitial" then
   admob.load( "interstitial", { adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx"} )
    end
end

end

admob.init( adListener, { appId=“ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx” } )

local formStatus, consentStatus = admob.getConsentFormStatus()

if consentStatus == “obtained” and formStatus == “available” then

if ( admob.isLoaded( “interstitial” ) ) then
admob.show( “interstitial” )
end
admob.show( “interstitial”, { appId=interstitialAppID } )
end

1 Like

I must be the stupid one, but this code doesn’t work for me at all, and yes, I think the code still needs to be completed to make it work, but the truth is that although I understand the lua language, I don’t understand how to implement plugins. :joy:

For example, I would like to display a banner ad and this is how I tried to convert your code.

local admob = require( "plugin.admob" )
local bannerAppID = "ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx"

local function adListener( event )

if (event.phase == "init") then  
   admob.load( "banner", { adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx" } )
end

if event.phase == "closed" then
if event.type == "banner" then
   admob.load( "banner", { adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx"} )
    end
end
end

admob.init( adListener, { appId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx" } )

local formStatus, consentStatus = admob.getConsentFormStatus()

if consentStatus == "obtained" and formStatus == "available" then

if ( admob.isLoaded( "banner" ) ) then
admob.show( "banner" )
end
admob.show( "banner", { appId=bannerAppID } )
end

I tested for quite a long time until the consent was displayed and then the ads were displayed.

Check if you really have consentStatus == “obtained” and formStatus == “available” , because in my code only then ads are displayed.

To check the statuses, I used the code below, cut from some other application

local _, admob = pcall(require, “plugin.admob”)

local interstitialAppID = “ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx” --for your ANDROID interstitial

– AdMob listener function

local function adListener( event )
if ( event.phase == “init” ) then – Successful initialization
– Load an AdMob interstitial ad
admob.load( “interstitial”, { adUnitId=“ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx” } )
end

if event.phase == "closed" then
if event.type == "interstitial" then
   admob.load( "interstitial", { adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx"} )
            end
end

end

– Initialize the AdMob plugin
– Sometime later, show the interstitial ad

–admob.init( adListener, { appId=“ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx” } )

– pokaż formularz

– Set UMP Form for debug
–admob.updateConsentForm ({ underage=false ,debug= { geography = “EEA”} })
admob.updateConsentForm ({ underage=false })
–local function adListener( event )
– if ( event.phase == “init” ) then – Successful initialization
local formStatus, consentStatus = admob.getConsentFormStatus()

  if consentStatus == "required" and formStatus == "available" then
		admob.loadConsentForm()
	end
	
--    end

admob.init( adListener, { appId=“ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx” } )
– if(event.phase == “loaded” and event.type == “ump”)then
if consentStatus == “required” and formStatus == “available” then
admob.showConsentForm()
end
–end

local subTitle = display.newText {
text = “plugin for Corona SDK”,
font = display.systemFont,
fontSize = 14
}
subTitle:setTextColor( 0.2, 0.2, 0.2 )

eventDataTextBox = native.newTextBox( 250, 500, 500, 300)
eventDataTextBox.placeholder = “Event data will appear here”
eventDataTextBox.hasBackground = true

local processEventTable = function(event)
local logString = json.prettify(event):gsub("\","")
logString = “\nPHASE: “…event.phase…” - - - - - - - - - \n” … logString
print(logString)
eventDataTextBox.text = logString … eventDataTextBox.text
end

local formLabel = display.newText {
text = “F O R M”,
font = display.systemFontBold,
fontSize = 38,
}
formLabel:setTextColor(1)

local loadFormButton = widget.newButton {
label = “Load Form”,
font = display.systemFontBold,
fontSize = 34,
width = 100,
height = 40,
labelColor = { default={ 255, 255, 255 }, over={ 0.7, 0.7, 0.7 } },
onRelease = function(event)
admob.loadConsentForm()
end
}

local showFormButton = widget.newButton {
label = “Show Form”,
fontSize = 34,
font = display.systemFontBold,
width = 100,
height = 40,
labelColor = { default={ 255, 255, 255 }, over={ 0.7, 0.7, 0.7 } },
onRelease = function(event)
admob.showConsentForm()
end
}

local getStatusFormButton = widget.newButton {
label = “Print Consent Status”,
fontSize = 34,
font = display.systemFontBold,
width = 100,
height = 40,
labelColor = { default={ 255, 255, 255 }, over={ 0.7, 0.7, 0.7 } },
onRelease = function(event)
local formStatus, consentStatus = admob.getConsentFormStatus()
logString = “\nForm Status: - - - - - - - - - \n” … "Form Status: “… formStatus …” Consent Status: "…consentStatus
eventDataTextBox.text = logString … eventDataTextBox.text
end
}

formLabel.x, formLabel.y = display.contentCenterX - 80, 60

loadFormButton.x, loadFormButton.y = display.contentCenterX - 130, 850

showFormButton.x, showFormButton.y = display.contentCenterX + 110, 850

getStatusFormButton.x, getStatusFormButton.y = display.contentCenterX - 80, -10

Thank you for sending it, my biggest problem with this whole thing is that I’m specifically blind on the subject, I’ve been trying to solve it for more than 1 month, but it’s quite difficult, so I’ll leave it at that :sweat_smile: