Admob
Last updated
{
"react-native": {
"admob_android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
"admob_ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
}
}import admob, { MaxAdContentRating } from '@react-native-firebase/admob';
admob()
.setRequestConfiguration({
// Update all future requests suitable for parental guidance
maxAdContentRating: MaxAdContentRating.PG,
// Indicates that you want your content treated as child-directed for purposes of COPPA.
tagForChildDirectedTreatment: true,
// Indicates that you want the ad request to be handled in a
// manner suitable for users under the age of consent.
tagForUnderAgeOfConsent: true,
})
.then(() => {
// Request config successfully set!
});import { RewardedAd, TestIds } from '@react-native-firebase/admob';
const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
const rewarded = RewardedAd.createForAdRequest(adUnitId, {
requestNonPersonalizedAdsOnly: true,
keywords: ['fashion', 'clothing'],
});
componentDidMount() {
const eventListener = rewarded.onAdEvent((type, error, reward) => {
if (type === RewardedAdEventType.LOADED) {
console.log('ad loaded');
rewarded.show();
}
if (type === RewardedAdEventType.EARNED_REWARD) {
console.log('User earned reward of ', reward);
}
});
handleShowAd() {
rewarded.load();
}
......
<Button onPress={() => this.handleShowAd()}>
<Text>觀看</Text>
</Button>