invertase / react-native-google-mobile-ads

React Native Google Mobile Ads enables you to monetize your app with AdMob.
https://docs.page/invertase/react-native-google-mobile-ads
Other
625 stars 121 forks source link

[🐛] AdsConsent error messages on Android #583

Open LukasMod opened 1 month ago

LukasMod commented 1 month ago

What happened?

Hey, we use this library to show the CMP consent form.

The application is production and available in stores. We just get a lot of errors and I can't find the cause, maybe someone knows what they can be caused by. Errors that result from offline mode should not be logged by us anymore, so I assume it is something else.

Errors I cant figure out (code - message), these are errors on Android:

  1. consent-update-failed - The server timed out. / Error making request.
  2. consent-form-error - Web view timed out.
  3. null-activity - Attempted to request a consent info update but the current Activity was null.

On my test and private devices I do not have these errors, everything works properly. I see in logs that these are from different android versions from 8-14, different brands like samsung (mostly), oppo, motorola, xiaomi, huawei. Majority installed from Google Store.

Do you have any idea how to debug these errors or where they come from?

Implementation looks like that:

     public getConsent = async (): Promise<GDPRConsent | null> => {
        try {
            await checkInternetConnection(); <<< throws custom error if offline, none of these above

            const consentInfo = await AdsConsent.requestInfoUpdate();

            if (
                (consentInfo.status === AdsConsentStatus.REQUIRED ||
                    consentInfo.status === AdsConsentStatus.UNKNOWN) &&
                consentInfo.isConsentFormAvailable
            ) {
                const consentInfoAfterForm = await AdsConsent.loadAndShowConsentFormIfRequired();
                const userChoices = await AdsConsent.getUserChoices();

                return {
                    consentInfo: consentInfoAfterForm,
                    userChoices,
                };
            } else if (consentInfo.status === AdsConsentStatus.OBTAINED) {
                // already filled
                const userChoices = await AdsConsent.getUserChoices();

                return {
                    consentInfo,
                    userChoices,
                };
            } else if (consentInfo.status === AdsConsentStatus.NOT_REQUIRED) {
                return {
                    consentInfo,
                    userChoices: approvedConsent,
                };
            } else {
                return null;
            }
        } catch (e: any) {
            Logging.error('[getConsent] error', {
                message: e?.message,
                code: e?.code,
                data: e,
            });
            return null;
        }
    };

Platforms

Only on Android

React Native Info

System:
  OS: macOS 14.4.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 79.16 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.2
    path: ~/.nvm/versions/node/v18.18.2/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v18.18.2/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.2/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/userName/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK:
    API Levels:
      - "29"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-33 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10811636
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/userName/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.8
    wanted: ^0.73.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Are your using Typescript?

package.json

react-native-google-mobile-ads@^13.2.0
react-native: ^0.73.6

app.json

{
    "name": "...",
    "displayName": "...",
    "react-native-google-mobile-ads": {
        "delay_app_measurement_init": true,
        "android_app_id": "ca-app-pub-...",
        "ios_app_id": "ca-app-pub-..."
    }
}

ios/Podfile

No response

android/build.gradle

No response

android/app/build.gradle

No response

android/settings.gradle

No response

AndroidManifest.xml

No response

dylancom commented 1 month ago

For error 3 you can do some investigation / logging in: https://github.com/invertase/react-native-google-mobile-ads/blob/main/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java#L114

For the others I think you could simulate a bad network connection in Android Studio. You can find all related code in: ReactNativeGoogleMobileAdsConsentModule.java. Could be related to the underlying SDK...

LukasMod commented 1 month ago

The problem is that these errors occur at the end user, so logging in my build doesn't do anything for me. I verified in Android Studio that after setting up a slow connection I get one of listed errors:

    "message": "Error making request.",
    "code": "consent-update-failed"

But so far I have not been able to get the others.

github-actions[bot] commented 3 days ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.