EMI-INDO / emi-indo-cordova-plugin-admob

Cordova Plugin Admob Android | IOS
ISC License
13 stars 2 forks source link

Interstitial ads dont show from 19 october 2024 (show only with unit id test) - tested plugin 1.4.9 and 1.5.3 #27

Open netlogica opened 2 weeks ago

netlogica commented 2 weeks ago

Bug report

Current behavior:

On my Android and iOS application (with previous version of plugin emi-indo-cordova-plugin-admob 1.4.8) from 19 october 2024 the insterstitial ads show only if I set a Google AdMob test unit id - ca-app-pub-3940256099942544/1033173712- and nothing with my production ads unit-id ((which worked fine until October 19 2024).

My environment is: MaxOS Sonoma 14.6.1 Xcode 15.4 cordova 13.0.0 node 20.16.0 Cocoapods 1.16.0 Running cordova-ios@7.1.1

Updated to the plugin version 1.5.4 the result is the same: with the test unit id the interstitial ads banner is displayed; with the production unit id I get an error on console (below is the execution console log on the simulator, but it is similar on a physical iPhone).

I would like to point out that the app is always correctly published on the Apple Store, that the app-ads.txt file is always present, and that the app is approved on AdMob (see attached images) and Unit-id correctly defined (until October 19 the ads will be displayed correctly)..

To make a test, I created with cordova an app called test where I installed only the emi-indo-cordova-plugin-admob 1.5.3 plugin with app id production and inserted the following javascript to instantiate the object and call the insterstitial banner:

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
    // Cordova is now initialized. Have fun!

    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    document.getElementById('deviceready').classList.add('ready');
    setTimeout(function() {
        setAdMob();
    }, 3000);
}

function setAdMob() {
    const config_globalSettings = {
        setAppMuted: false,
        setAppVolume: 1.0,
        publisherFirstPartyIdEnabled: false,
        npa: 1,
        enableCollapsible: false,
        responseInfo: false,
        setDebugGeography: false
    }

    const config_initializeSettings = {
        isUsingAdManagerRequest: false,
        isResponseInfo: false, // Default false (Debug true)
        isConsentDebug: false // Default false (Debug true)
    }

    cordova.plugins.emiAdmobPlugin.globalSettings(config_globalSettings);
    console.log('after globalSettings call');

    cordova.plugins.emiAdmobPlugin.initialize(config_initializeSettings);
    console.log('after initialize call');

    //TEST ID UNIT
    var interstitialIdUnit = 'ca-app-pub-3940256099942544/1033173712';

    // inizializza la configurazione della unit per il plugin
    const config_Interstitial = {
        adUnitId: interstitialIdUnit,
        autoShow: false
    };

    cordova.plugins.emiAdmobPlugin.loadInterstitialAd(config_Interstitial);
    console.log('after load call');

    // Show Interstitial Ad
    document.addEventListener('on.interstitial.loaded', () => {
        console.log("on interstitial Ad loaded");
        setTimeout(function() {
            cordova.plugins.emiAdmobPlugin.showInterstitialAd();
            console.log('after show call');
        }, 1000);
    });

    document.addEventListener('on.sdkInitialization', (data) => {
        const sdkVersion = data.version;
        console.log("On Sdk Initialization version: " + sdkVersion);
    });

    document.addEventListener('on.interstitial.failed.load', () => {
        console.log("ERROR on interstitial Ad loaded");
    });

    document.addEventListener('on.interstitial.failed.show', () => {
        console.log("ERROR on interstitial Ad show");
    });     
}

My config.xml is:

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloCordova</name>
    <description>Sample Apache Cordova App</description>
    <author email="dev@cordova.apache.org" href="https://cordova.apache.org">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <platform name="ios">
         <config-file target="*-Info.plist" parent="GADApplicationIdentifier">
            <string>SUBSTITUTE WITH YOUR APP ID</string>
     </config-file>
      <config-file target="*-Info.plist" parent="NSAppTransportSecurity">
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
    </config-file>
    <edit-config target="GADApplicationIdentifier" file="*-Info.plist" mode="merge">
        <string>SUBSTITUTE WITH YOUR APP ID</string>
    </edit-config>
    <edit-config target="GADIsAdManagerApp" file="*-Info.plist" mode="merge"> 
        <true /> 
    </edit-config>
    </platform>
</widget>

Opening app on Xcode with ".xcworkspace" file, I can build without errors. On console:

WITH TEST UNIT ID ca-app-pub-3940256099942544/1033173712 (INTERSTITIAL ADS SHOW)
The preference key "AutoHideSplashScreen" is not defined and will default to "TRUE"
Running cordova-ios@7.1.1
after globalSettings call
after initialize call
after load call
on interstitial Ad loaded
after show call
WITH PRODUCTION UNIT ID (INTERSTITIAL ADS DON'T SHOW)
Running cordova-ios@7.1.1
The preference key "AutoHideSplashScreen" is not defined and will default to "TRUE"
after globalSettings call
after initialize call
after load call
on interstitial Ad loaded
after show call
ERROR on interstitial Ad show

Please, can you help me with this? Has anyone had the same issue?

Thank you all,

Mario

admob_app_id_OK admob_unit_id_OK

EMI-INDO commented 2 weeks ago

@netlogica

What version of the plugin do you think this problem occurs in? and this problem does not occur in what version

Unfortunately I don't have an apple developer account, so I can only test in xcode.

And I noticed that your code has some errors, like I have to make a sample code including documentation for iOS and android simple, Maybe in the next day or two.

In the next release, I will update the code to send an error response to the event block, so it's easier to find out what the problem is.

// example of the next release
document.addEventListener('on.interstitial.failed.load', (event) => {
        console.log("ERROR on interstitial Ad loaded", JSON.stringify(event));
    });

    document.addEventListener('on.interstitial.failed.show', (event) => {
        console.log("ERROR on interstitial Ad show", JSON.stringify(event));
    });
netlogica commented 2 weeks ago

@EMI-INDO

Thank you for reply: a sample code for intertitial implementation and a catch for error response on next version of your plugin is very useful.

@netlogica

What version of the plugin do you think this problem occurs in? and this problem does not occur in what version

The versions of plugin I tested show the same behavior, they are 1.4.9 and 1.5.3: on both I see test ADS but not the production one.

In the meantime, while you make the implementation example into the documentation, I made a (dirty) workaround and ads will show into 1 minute.

// Initizlize, load and show interstitial ads
function setAdMob() {
    console.log('begin setAdMob');

    // Remove existing event listeners before adding them
    document.removeEventListener('on.interstitial.loaded', onInterstitialLoaded);
    document.removeEventListener('on.interstitial.failed.show', onInterstitialFailedShow);

    const config_globalSettings = {
        setAppMuted: false,
        setAppVolume: 1.0,
        publisherFirstPartyIdEnabled: false,
        npa: 1,
        enableCollapsible: false,
        responseInfo: false,
        setDebugGeography: false
    }

    const config_initializeSettings = {
        isUsingAdManagerRequest: false,
        isResponseInfo: true,
        isConsentDebug: true
    }

    cordova.plugins.emiAdmobPlugin.globalSettings(config_globalSettings);
    cordova.plugins.emiAdmobPlugin.initialize(config_initializeSettings);

    var interstitialIdUnit = 'ca-app-pub-3940256099942544/1033173712';
    const config_Interstitial = {
        adUnitId: interstitialIdUnit,
        autoShow: false
    };

    cordova.plugins.emiAdmobPlugin.loadInterstitialAd(config_Interstitial);

    // add event listener
    document.addEventListener('on.interstitial.loaded', onInterstitialLoaded);
    document.addEventListener('on.interstitial.failed.show', onInterstitialFailedShow);
}

// Function to manage interstitial loading
function onInterstitialLoaded() {
    setTimeout(function() {
        cordova.plugins.emiAdmobPlugin.showInterstitialAd();
    }, 1000);
}

// Function to handle failure of interstitial display and reload if show fail
function onInterstitialFailedShow(data) {
    setTimeout(function() {
        removeTimer();
        setAdMob(); // recursive call
    }, 1000);
}

// Clear all setTimeouts and setInterval
function removeTimer() {
    let id = window.setTimeout(() => {}, 0);
    while (id--) {
      window.clearTimeout(id);
    }

    id = window.setInterval(() => {}, 0);
    while (id--) {
        window.clearInterval(id);
    }
}

In this way, after about 50 seconds, the ads with production unit-id shown.

I contacted Google AdMob support so I will insert their reply here, as soon as they have answered me, so that they - I hope - can be useful to others.

Thanks again, I await your doc update with example for the correct implementation of interstitial ads on 1.5.3. version.

Greetings from Italy

Mario

EMI-INDO commented 2 weeks ago

@netlogica

netlogica commented 2 weeks ago

@EMI-INDO Thank you very much for new release and for implementation example (very important).

I will be able to do some tests in the next 24 hours to give feedback. For now, with only your testing code and with my production unit-id I see on console "Request Error: no ad to show" but with test id work like a charm. In my previous workaround, with recursive recall on fail with a sleep of 1 second, ads production show after 40-50 seconds. Very strange...

I await AdMob support reply (I hope by 1 or 2 day) to update this thread with new information.

Anyway, thank you for your availability, I will send you a "beer" on Paypal :)

Mario software [at] netlogica.it

EMI-INDO commented 2 weeks ago

@netlogica

https://groups.google.com/g/google-admob-ads-sdk/c/1YonZJ3No4Y

/ https://support.google.com/admob/answer/9493252?hl=en Best practice when using ad original ID unit, the app must be uploaded to the play store or app store, and you must upload it from there, otherwise you may be subject to ad serving restrictions, if it happens often, it is possible that your admob account will be permanently disabled. /

Don't show ads too often in too short a time span.

Frequ