It just doesn't matter what I do, I can't use Admob in my cordova project

95 views
Skip to first unread message

Macaco Branco

unread,
Dec 27, 2023, 12:07:02 PM12/27/23
to Google Mobile Ads SDK Developers
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
})

Mobile Ads SDK Forum Advisor

unread,
Dec 27, 2023, 12:27:42 PM12/27/23
to prone...@gmail.com, google-adm...@googlegroups.com

Hi, 

Thank you for contacting the Mobile Ads SDK support team.

Please note that we can only provide assistance to Android, iOS, Unity and Flutter. If you can replicate the same issue in any of the supported platforms, kindly share the sample project for further assistance.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02r3v4h:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


Reply all
Reply to author
Forward
0 new messages