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
710 stars 148 forks source link

[๐Ÿ›] ADmob Reward AD No amount returned for the advertisement you watched (์• ๋“œ๋ชน ๋ฆฌ์›Œ๋“œ ๊ด‘๊ณ  ์‹œ์ฒญํ•œ ๊ด‘๊ณ ์— ๋Œ€ํ•œ ๊ธˆ์•ก ๋ฆฌํ„ด ์•ˆ๋จ) #504

Closed vvhj806 closed 9 months ago

vvhj806 commented 11 months ago

What happened?

์• ๋“œ๋ชน์—์„œ ๋ฆฌ์›Œ๋“œ ๊ด‘๊ณ  ๋‹จ์œ„๋ฅผ ๋“ฑ๋กํ•œ ํ›„ ์‹ค์ œ ๊ด‘๊ณ ๊ฐ€ ๋œจ๋Š” ๊ฒƒ ๊นŒ์ง€ ํ™•์ธํ–ˆ๋‹ค.

TestIds.REWARDED ๋ฅผ ์‚ฌ์šฉ ํ–ˆ์„ ๊ฒฝ์šฐ์—๋Š” payloadAd์—์„œ ๊ด‘๊ณ  ํด๋ฆญ ํ›„ type์ด 'paid'๋กœ ์ „๋‹ฌ๋˜๊ณ  if (type === AdEventType.PAID) ์—ฌ๊ธฐ ์กฐ๊ฑด์œผ๋กœ ๋“ค์–ด๊ฐ€๋ฉด์„œ payload ๊ฐ’์ด ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ฐํžŒ๋‹ค.

(type์ด 'paid'์ผ๋•Œ payload ๊ฐ’ -> {precision: 0, currency: 'USD', value: 0})

AdEventType์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. {CLICKED: "clicked", CLOSED: "closed", ERROR: "error", LOADED: "loaded", OPENED: "opened", PAID: "paid"}

ํ•˜์ง€๋งŒ 'ca-app-pub-' ์œผ๋กœ ์‹œ์ž‘๋˜๋Š” ์‹ค์ œ ๊ด‘๊ณ  ID๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์‹ค์ œ ๊ด‘๊ณ ๋ฅผ ์‹œ์ฒญํ–ˆ์„ ๊ฒฝ์šฐ์—๋Š” type ๊ฐ’์— paid๊ฐ€ ์ฐํžˆ์ง€ ์•Š๋Š”๋‹ค.

๋ฆฌ์›Œ๋“œ ๊ด‘๊ณ ์—์„œ๋Š”paid ๊ฐ’์ด ์›๋ž˜ ์ „๋‹ฌ ๋˜์ง€ ์•Š๋Š” ๊ฒƒ์ธ์ง€, ์œ„ ์ฝ”๋“œ๊ฐ€ ์ž˜๋ชป๋œ ๊ฒƒ์ธ์ง€ ๋ฌธ์˜๋ฅผ ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์•ฑ ์‚ฌ์šฉ์ž๊ฐ€ ์‹œ์ฒญํ•œ ๊ด‘๊ณ ์— ๋Œ€ํ•œ ๊ด‘๊ณ  ๊ธˆ์•ก์„ ์ „๋‹ฌ ๋ฐ›๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. (์„ค์ •ํ•œ ๋ฆฌ์›Œ๋“œ ๊ฐ’์ด ์•„๋‹Œ)

(์ฝ”๋“œ)

import React, { useEffect, useState } from 'react'; import { Button, View, Text } from 'react-native'; import { viewAdmobApi } from '../../api/Common'; import { RewardedAd, RewardedAdEventType, TestIds, AdEventType } from 'react-native-google-mobile-ads'; import { ISToast } from '../ISToast';

const adUnitId = DEV ? TestIds.REWARDED : 'ca-app-pub-';

const rewarded = RewardedAd.createForAdRequest(adUnitId, { keywords: ['fashion', 'clothing'], });

function RewardAd() { const [loaded, setLoaded] = useState(false); const [payloadData, setPayloadData] = useState({});

useEffect(() => {
    const unsubscribeLoaded = rewarded.addAdEventListener(RewardedAdEventType.LOADED, () => {
        console.log(RewardedAdEventType);
        setLoaded(true);
    });

    const unsubscribeEarned = rewarded.addAdEventListener(
        RewardedAdEventType.EARNED_REWARD,
        reward => {
            console.log('User earned reward of ', reward);
            sendSSVCallback(reward.amount);
        },
    );

    const payloadAd = rewarded.addAdEventsListener(({type, payload}) => {
        console.log(`${Platform.OS} rewarded ad event: ${type}`);
        console.log('type : ', type);
        console.log('RewardedAdEventType : ', AdEventType);
        console.log('payload : ', payload);

        if (type === AdEventType.PAID) {
            console.log(payload);
            setPayloadData(payload);
        }
        if (type === AdEventType.ERROR) {
            console.log(`${Platform.OS} rewarded error: ${payload}`);
        }
        if (type === RewardedAdEventType.LOADED) {
            console.log(`${Platform.OS} reward: ${JSON.stringify(payload)})`);
            setLoaded(true);
        }
    });

    rewarded.load();

    return () => {
        payloadAd();
        unsubscribeLoaded();
        unsubscribeEarned();
    };
}, [payloadData]);

const sendSSVCallback = async (rewardAmount) => {
    const data = {
        // rewardAmount: rewardAmount,
        rewardAmount: 1,
    }

    console.log(data);

    viewAdmobApi(data).then((response) => {
        const returnData = response.data;
        console.log(returnData);

        if (returnData.state == 200) {
          ISToast.show({ text: 'Rewards have been given to you.', duration: 2000 });
        } else {
          ISToast.show({ text: 'An error occurred while watching the ad.', duration: 2000 });
        }
    });
};

if (!loaded) {
    return null;
}

return (
    <>
        <Button
            title="Show Rewarded Ad"
            onPress={() => {
            rewarded.show();
            }}
        />

        <Text>Loaded? {loaded ? 'true' : 'false'}</Text>

        <View style={{marginTop: 30}}>
            <Text>currency : {payloadData.currency}</Text>
            <Text>precision : {payloadData.precision}</Text>
            <Text>value : {payloadData.value}</Text>
        </View>
    </>
);

}

export default RewardAd;

Platforms

Android, but have not tested behavior on iOS

React Native Info

System:
  OS: Windows 11 10.0.22621
  CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13500
  Memory: 11.51 GB / 31.77 GB
Binaries:
  Node:
    version: 20.10.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn: Not Found
  npm:
    version: 10.2.4
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: AI-223.8836.35.2231.11090377
  Visual Studio: Not Found
Languages:
  Java: 11.0.21
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 11.3.10
    wanted: ^11.3.9
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.71.7
    wanted: 0.71.7
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Are your using Typescript?

package.json

{
  "name": "mymoments",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "android:prod": "react-native run-android --variant=release",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@actbase/react-daum-postcode": "^1.0.4",
    "@react-native-async-storage/async-storage": "^1.18.1",
    "@react-native-community/checkbox": "^0.5.16",
    "@react-native-community/cli": "^11.3.9",
    "@react-native-community/datetimepicker": "^7.6.1",
    "@react-native-community/push-notification-ios": "^1.11.0",
    "@react-native-firebase/app": "^18.6.1",
    "@react-native-firebase/messaging": "^18.6.1",
    "@react-native-picker/picker": "^2.5.1",
    "@react-navigation/material-top-tabs": "^6.6.4",
    "@react-navigation/native-stack": "^6.9.12",
    "@reduxjs/toolkit": "^1.9.7",
    "@rneui/base": "github:react-native-elements/react-native-elements#base",
    "@rneui/themed": "github:react-native-elements/react-native-elements#themed",
    "android": "^0.0.8",
    "axios": "^1.4.0",
    "deprecated": "^0.0.2",
    "deprecated-react-native-prop-types": "^5.0.0",
    "eslint-config-prettier": "^8.8.0",
    "eslint-plugin-prettier": "^4.2.1",
    "ffmpeg-kit-react-native": "^6.0.2",
    "inherits": "^2.0.4",
    "moment": "^2.29.4",
    "querystring": "^0.2.1",
    "react": "18.2.0",
    "react-jwt": "^1.2.0",
    "react-native": "0.71.7",
    "react-native-audio-recorder-player": "^3.6.4",
    "react-native-avoid-softinput": "^4.0.2",
    "react-native-bouncy-checkbox": "^3.0.7",
    "react-native-checkbox": "^2.0.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-debugger": "^1.1.0",
    "react-native-device-info": "^10.11.0",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.13.4",
    "react-native-google-mobile-ads": "^12.6.0",
    "react-native-image-crop-picker": "^0.40.2",
    "react-native-image-picker": "^7.0.3",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-localize": "^3.0.0",
    "react-native-mime-types": "^2.4.0",
    "react-native-pager-view": "^6.2.1",
    "react-native-paper": "^5.11.0",
    "react-native-permissions": "^3.10.1",
    "react-native-picker-select": "^8.1.0",
    "react-native-progress-bar-animated": "^1.0.6",
    "react-native-push-notification": "^8.1.1",
    "react-native-reanimated-carousel": "^3.5.1",
    "react-native-safe-area-context": "^4.7.2",
    "react-native-screens": "^3.20.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-splash-screen": "^3.3.0",
    "react-native-sqlite-storage": "^6.0.1",
    "react-native-swipe-list-view": "^3.2.9",
    "react-native-tab-view": "^3.5.2",
    "react-native-toast-message": "^2.1.6",
    "react-native-tts": "^4.1.0",
    "react-native-vector-icons": "^10.0.2",
    "react-native-webview": "^13.6.3",
    "react-native-youtube": "^2.0.2",
    "react-native-youtube-iframe": "^2.3.0",
    "react-redux": "^8.1.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "babel-plugin-module-resolver": "^5.0.0",
    "eslint": "^8.40.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-jsx-a11y": "^6.7.1",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-native": "^4.0.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.9",
    "prettier": "^2.4.1",
    "react-native-dotenv": "^3.4.8",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

app.json

{
  "name": "ilsonApp",
  "displayName": "ilsonApp",
  "react-native-google-mobile-ads": {
    "android_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

github-actions[bot] commented 10 months 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.