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
624 stars 121 forks source link

I can't under stand how to establish European user consent #587

Open Gul7333 opened 2 weeks ago

Gul7333 commented 2 weeks ago

Documentation Feedback

Documentation you provide is very minimal and does not provide code .... For beginners like it is my first app... I am stuck at consent .... You didn't provide any code to make it work....

radekzz commented 2 weeks ago

Go to AdMob and create a message in Privacy and Communications then you can use it like this:

  1. Create a consent call:
import {AdsConsent} from 'react-native-google-mobile-ads';
import {saveToMMKV} from '../storage';

export const callGdprConsent = async () => {
  // Request an update for the consent information.
  AdsConsent.requestInfoUpdate().then(() => {
    AdsConsent.loadAndShowConsentFormIfRequired().then(adsConsentInfo => {
      // Consent has been gathered.
      if (adsConsentInfo.canRequestAds) {
        saveToMMKV('gdprConsentStatus', true);
        return true;
      }
    });
  });

  // Check if you can initialize the Google Mobile Ads SDK in parallel
  // while checking for new consent information. Consent obtained in
  // the previous session can be used to request ads.
  // So you can start loading ads as soon as possible after your app launches.
  const {canRequestAds} = await AdsConsent.getConsentInfo();
  if (canRequestAds) {
    saveToMMKV('gdprConsentStatus', true);
    return true;
  }
  saveToMMKV('gdprConsentStatus', false);
};
  1. call consent check before loading the ads
    export const showRewardAd = (rewardEarnedCallback: () => void) => {
    callGdprConsent();
    const gdprConsentStatus = readFromMMKV('gdprConsentStatus', 'boolean');
    // Create a new instance
    const rewardAd = RewardedAd.createForAdRequest(
    ....
    };
Gul7333 commented 2 weeks ago

I used hooks provided by this library to load ads.... Even though I haven't initialized the mobilead sdk.... ads are are still showing even in release build.... Does hooks provided by this library automatically initialize the Google ad sdk or its google ad are automatically initialized

dylancom commented 2 weeks ago

The docs are full of code examples so you didn't read well.... Yes it works without initialization but it is better to do so.... If you think this library could be better in any way, you can submit PR's as this is a community effort....