capacitor-community / admob

Community plugin for using Google AdMob
MIT License
213 stars 66 forks source link

AdMob methods (requestConsentInfo, showConsentForm) called on web despite platform checks #332

Closed ThomasOrgeval closed 2 hours ago

ThomasOrgeval commented 2 hours ago

Describe the bug

Despite implementing platform checks to only initialize AdMob on mobile platforms (iOS, Android), the methods requestConsentInfo and showConsentForm are being called repeatedly on the web version of my application. These calls should not be triggered in a web environment.

To Reproduce

Steps to reproduce the behavior:

Expected behavior

AdMob methods should not be called on the web platform. These methods should only be triggered when the app is running on mobile devices (iOS, Android). On the web, AdMob initialization should be skipped entirely.

Desktop:

OS: Windows 11 Browser: Chrome 131 Version: Capacitor v6, AdMob plugin v6

Additional context

The platform detection seems correct, as logs indicate that AdMob initialization is skipped on the web (Skipping AdMob initialization on web). However, the requestConsentInfo and showConsentForm methods are still being triggered, leading me to believe there may be an issue with the plugin automatically calling these methods, even in the web environment.

Platform detection code:

export function isMobileApp(): boolean {
  return Capacitor.getPlatform() === 'ios' && Capacitor.isNativePlatform() ||
         Capacitor.getPlatform() === 'android' && Capacitor.isNativePlatform();
}

if (isMobileApp()) { // It returns false in my case, which is good
  // I never call admob anywhere else 
  this.admobService.init().subscribe();
}
distante commented 2 hours ago

There is nothing called automatically on the plugin side. If you use a browser in responsive mode with iOS or Android, capacitor will still think you are on device.

Calling or not init doesn't prevent calls to another methods by the consumer code.

ThomasOrgeval commented 1 hour ago

I never call another methods by myself, how is it possible then?

distante commented 1 hour ago

The message "Skipping AdMob initialization on web" just appear when you call init on web. Something is wrong with you code. It is not part of the plugin.

I am 100% sure of this friend.

ThomasOrgeval commented 1 hour ago

Okay, I'll take a look at what's wrong, thanks for your reply!