I've been trying to use AdMob in my cordova project for a few months, at first I managed to use it using the "cordova-plugin-admob-free" plugin, but it was out of date and after putting the version in the play console they asked me to remove it and update it, so it was that hell started,
I started looking for the correct plugin and saw that the free creator was now using AdMob Plus, I tried to follow the documentation and I simply can't, I don't know if it's because of consent (I'm in Brazil) or something else, but when I click on the button to run the ad it only returns to me in the console.
log that the ad was not loaded, in fact Admob was not even initialized either, my code is basically this, please someone save me with this.
const buyDark = document.getElementById('buyDark')
const btnPlayAdTrue = document.getElementById('btnPlayAdTrue')
const btnPlayAdFalse = document.getElementById('btnPlayAdFalse')
const boxAD = document.getElementById('boxQuestionPlayAd')
let rewarded
document.addEventListener(
'deviceready',
async () => {
if (cordova.platformId === 'android') {
const status = await consent.trackingAuthorizationStatus()
const statusNew = await consent.requestTrackingAuthorization()
}
const consentStatus = await consent.getConsentStatus()
if (consentStatus === consent.ConsentStatus.Required) {
await consent.requestInfoUpdate()
const form = await consent.showForm()
}
await consent.loadAndShowIfRequired()
await admob
.start()
.then(() => {
console.log('AdMob started.')
})
.catch(e => console.log(e))
if (await consent.canRequestAds()) {
rewarded = new admob.RewardedAd({
adUnitId: 'ca-app-pub-3940256099942544/5224354917', npa: '1'
})
rewarded.on('load', async evt => {
await rewarded.load()
})
await rewarded.load()
}
},
false
)
btnPlayAdTrue.addEventListener('click', async () => {
boxAD.classList.add('hidden')
if (rewarded && (await rewarded.isLoaded())) {
await rewarded.show()
} else {
console.log('O anúncio recompensado ainda não foi carregado.')
}
})
buyDark.addEventListener('click', function () {
boxAD.classList.remove('hidden')
})
btnPlayAdFalse.addEventListener('click', function () {
boxAD.classList.add('hidden')
})
document.addEventListener('admob.rewarded.dismiss', async () => {
await rewarded.load()
})
document.addEventListener('admob.rewarded.reward', () => {
window.playerQuantDarkValue = 20
})