Pablo D.
Pablo D.

Reputation: 303

Cordova app not showing apps using admob-plus-cordova

Ads are not showing using this plugin. Let me describe the steps I followed from scratch, maybe you can assist me.
First, I created a new cordova project:

cordova create AdmobProject
cd AdmobProject

Then, I add the plugin

cordova plugin add admob-plus-cordova --save --variable APP_ID_ANDROID=ca-app-pub-3940256099942544~3347511713

I got this ID from Google website. Then, I modify the index.html inside AdmobProject/www folder. I leave it like this:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
    <meta name="color-scheme" content="light dark">
    <link rel="stylesheet" href="css/index.css">
    <title>Joputa</title>
</head>

<body>
    <script src="cordova.js"></script>
</body>

</html>

And now I follow the instructions from plugin website and add the instructions for the banner. The index.html file is now:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
    <meta name="color-scheme" content="light dark">
    <link rel="stylesheet" href="css/index.css">
    <title>Joputa</title>
</head>

<body>
    <script src="cordova.js"></script>
    <script>
        let banner

        document.addEventListener('deviceready', async () => {
            banner = new admob.BannerAd({
                adUnitId: 'ca-app-pub-3940256099942544/6300978111',
            })

            banner.on('impression', async (evt) => {
                await banner.hide()
            })

            await banner.show()
        }, false)
    </script>
</body>

</html>

I entered the test unitAdId provided by plugin website.
When I add android platform and build using cordova, the app does not display anything at all.
Suggestions about how to fix this, please?

Upvotes: 0

Views: 213

Answers (2)

Chetan
Chetan

Reputation: 196

Please first check for any errors related to load event

admob.on('admob.banner.load', (evt) => {
   console.log('Banner ad loaded successfully.');
 });
 admob.on('admob.banner.load_fail', (evt) => {
   console.error('Banner ad failed to load:', evt);
 });

Upvotes: 0

godrien
godrien

Reputation: 1

Try adding these properties on your config.xml

<platform name="android">
    <preference name="PLAY_SERVICES_VERSION" default="23.2.0" />
    <preference name="AndroidXEnabled" value="true" />
    <preference name="GradlePluginKotlinEnabled" value="true" />

Upvotes: 0

Related Questions