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
702 stars 142 forks source link

[🐛] Following the docs, Ads does not showing #543

Closed IgorBaio closed 7 months ago

IgorBaio commented 9 months ago

What happened?

following the documentation, the use of Banner and Interstitial is not appearing

Examples:

Banner: import React, { useEffect } from "react"; import { FeedContainer, GalleryContainer, SearchContainer, InputContainer, InputCheckBox, InputCheckBoxContainer, InputCheckBoxLabel, BannerContainer, } from "./styles"; import { Gallery } from "../../Organisms/Gallery"; import { useFilters } from "../../stores/Filters"; import { colors } from "../../Styles/theme"; import { MaterialIcons } from '@expo/vector-icons'; import { useUser } from "../../stores/User"; import { GenericInput } from "../../Molecules/GenericInput"; import mobileAds, { AppOpenAd, InterstitialAd, RewardedAd, BannerAd, TestIds } from "react-native-google-mobile-ads"; import { heightPercentageToDP } from "react-native-responsive-screen"; import { verifyPlatform } from "../../functions/verifyPlatform";

export function SearchStructure({ navigation }: any) { const { users } = useUser((state) => state); const [search, setSearch] = React.useState(""); const [searchResult, setSearchResult] = React.useState<any[]>(users.filter((user, index) => index < 10) || []); const { user, setUser } = useUser(state => state) const [nationality, setNationality] = React.useState(user?.country || "");

const getFilter = () => { let usersAux = users.filter((userList, index) => (userList.displayName.toLowerCase().includes(search.toLowerCase()) || userList.services.join().toLowerCase().includes(search.toLowerCase())) ) if (!!nationality) usersAux = usersAux.filter(userList => userList.country === nationality) usersAux = usersAux.filter((userList, index) => index < 10) setSearchResult(usersAux); }

useEffect(() => { getFilter() }, [search, nationality])

useEffect(() => { setNationality(user.country) }, [user])

return (

setSearch(e)} value={search} /> { if (!!nationality) setNationality("") else setNationality(user.country) }}> {nationality && } Mesma nacionalidade

); }

Interstitial:

import React, { useEffect } from "react"; import { Text,

HStack, Center, Pressable, } from "native-base"; import { MaterialIcons, AntDesign } from '@expo/vector-icons'; import { useScreen } from "../stores/screen"; import { colors } from "../Styles/theme"; import { useCounterClickAd } from "../stores/CounterClickAd"; import { AdEventType, InterstitialAd } from "react-native-google-mobile-ads"; import { Platform } from "react-native";

interface MyTabBarProps { initialScreen: number; navigation: any; } const verifyPlatform = () => { if (Platform.OS === 'ios') { return 'ca-app-pub-2814259275801960~8712799152' } else if (Platform.OS === 'android') { return 'ca-app-pub-9674908168811233~5829755601' }

return 'ca-app-pub-9674908168811233~5829755601' }

const interstitialAd = InterstitialAd.createForAdRequest(verifyPlatform(), { keywords: ['fashion', 'clothing'], });

export function MyTabBar({ navigation, initialScreen = 0 }: MyTabBarProps) { const { screen = initialScreen, setScreen } = useScreen((state) => state);

const { setClicks, clicks } = useCounterClickAd(state => state) const [interstitialAds, setInterstitialAds] = React.useState(null) const initInterstitialAd = () => { // const interstitialAd = InterstitialAd.createForAdRequest(verifyPlatform()) console.log('interstitialAd pre evento', interstitialAd) interstitialAd.addAdEventListener(AdEventType.LOADED, () => { setInterstitialAds(interstitialAd) console.warn('interstitialAd loaded') } ) interstitialAd.addAdEventListener(AdEventType.CLOSED, () => { console.warn('interstitialAd loaded') } ) interstitialAd.load() }

const showInterstitialAd = async () => { console.log('interstitialAds', interstitialAds) if (interstitialAds) { interstitialAds.show() } }

useEffect(() => { initInterstitialAd()

}, [clicks]);

const selectScreen = (page: number, screen: string) => { setScreen(page) console.log('clicks', clicks) if (clicks >= 2) { showInterstitialAd() setClicks(0) } else {

  setClicks(clicks + 1)
}
navigation.navigate(screen)

}

return ( <>

{ selectScreen(0, 'HomeScreen'); }} >
Início
{ selectScreen(1, 'Search'); }} >
Procurar
{ selectScreen(2, 'Profile'); }} >
Perfil
</>

); }

Platforms

Android and iOS

React Native Info

System:
  OS: macOS 14.3.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 65.03 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.6.1
    path: ~/.nvm/versions/node/v20.6.1/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v20.6.1/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v20.6.1/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/igorbaiosoares/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10671973
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.20.1
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/igorbaiosoares/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.6
    wanted: 0.72.6
  react-native-macos: 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": "getservicesapp",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@bam.tech/react-native-image-resizer": "^3.0.7",
    "@react-native-async-storage/async-storage": "^1.19.8",
    "@react-navigation/bottom-tabs": "^6.5.11",
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.17",
    "@reduxjs/toolkit": "^1.9.7",
    "@types/utf8": "^3.0.3",
    "axios": "^1.6.2",
    "expo": "~49.0.15",
    "expo-build-properties": "~0.8.3",
    "expo-image-manipulator": "~11.3.0",
    "expo-image-picker": "~14.3.2",
    "expo-splash-screen": "~0.20.5",
    "expo-status-bar": "~1.6.0",
    "firebase": "^10.6.0",
    "native-base": "^3.4.28",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-flexbox-grid": "^0.3.2",
    "react-native-gesture-handler": "~2.12.0",
    "react-native-google-mobile-ads": "^11.6.4",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-modal": "^13.0.1",
    "react-native-pager-view": "^6.2.2",
    "react-native-paper": "^5.11.2",
    "react-native-permissions": "^4.0.2",
    "react-native-reanimated": "~3.3.0",
    "react-native-responsive-screen": "^1.4.2",
    "react-native-safe-area-context": "3.3.2",
    "react-native-screens": "^3.27.0",
    "react-native-splash-screen": "^3.3.0",
    "react-native-super-grid": "^5.0.0",
    "react-native-svg": "12.1.1",
    "react-native-tab-view": "^3.5.2",
    "react-native-toast-message": "^2.1.7",
    "react-native-vector-icons": "^10.0.2",
    "react-native-view-shot": "^3.8.0",
    "react-native-web": "0.17.1",
    "react-native-webview": "^13.6.3",
    "react-redux": "^8.1.3",
    "styled-components": "^6.1.1",
    "utf8": "^3.0.0",
    "zustand": "^4.4.6"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "@testing-library/react-native": "^11.0.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^26.0.23",
    "@types/react": "~18.2.14",
    "@types/react-native": "^0.70.6",
    "@types/react-native-auth0": "^2.13.1",
    "@types/react-native-vector-icons": "^6.4.18",
    "@types/react-redux": "^7.1.24",
    "@types/react-test-renderer": "^18.0.0",
    "@types/styled-components": "^5.1.26",
    "@types/styled-components-react-native": "^5.2.1",
    "@typescript-eslint/eslint-plugin": "^5.37.0",
    "@typescript-eslint/parser": "^5.37.0",
    "babel-jest": "^26.6.3",
    "babel-plugin-module-resolver": "^4.1.0",
    "eslint": "^7.32.0",
    "eslint-config-airbnb": "19.0.4",
    "eslint-config-prettier": "^8.5.0",
    "eslint-import-resolver-typescript": "^3.5.1",
    "eslint-plugin-import": "^2.25.3",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-react": "^7.28.0",
    "eslint-plugin-react-hooks": "^4.3.0",
    "husky": "0.14.3",
    "jest": "^26.6.3",
    "jest-styled-components": "^7.1.1",
    "lint-staged": "^13.2.1",
    "metro-react-native-babel-preset": "0.72.3",
    "prettier": "^2.7.1",
    "react-test-renderer": "18.1.0",
    "typescript": "^5.1.3"
  },
  "private": true,
  "reactNativePermissionsIOS": [
    "AppTrackingTransparency",
    "BluetoothPeripheral",
    "Calendars",
    "Camera",
    "Contacts",
    "FaceID",
    "LocationAccuracy",
    "LocationAlways",
    "LocationWhenInUse",
    "MediaLibrary",
    "Microphone",
    "Motion",
    "Notifications",
    "PhotoLibrary",
    "PhotoLibraryAddOnly",
    "Reminders",
    "Siri",
    "SpeechRecognition",
    "StoreKit"
  ]
}

app.json

{
  "expo": {
    "name": "getservicesapp",
    "slug": "getservicesapp",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.cogitus.getservicesapp"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "package": "com.cogitus.getservicesapp"
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "plugins": [
      [
        "expo-build-properties",
        {
          "ios": {
            "useFramerworks": "static"
          }
        }
      ]
    ],
    "extra": {
      "eas": {
        "projectId": "79e2ecb5-e3b7-479b-8b66-d014a9d1a446"
      }
    }
  },
  "react-native-google-mobile-ads": {
    "ios_app_id": "ca-app-pub-2814259275801960~8712799152",
    "android_app_id": "ca-app-pub-9674908168811233~5829755601",
    "sk_ad_network_items": [
      "cstr6suwn9.skadnetwork",
      "4fzdc2evr5.skadnetwork",
      "4pfyvq9l8r.skadnetwork",
      "2fnua5tdw4.skadnetwork",
      "ydx93a7ass.skadnetwork",
      "5a6flpkh64.skadnetwork",
      "p78axxw29g.skadnetwork",
      "v72qych5uu.skadnetwork",
      "ludvb6z3bs.skadnetwork",
      "cp8zw746q7.skadnetwork",
      "3sh42y64q3.skadnetwork",
      "c6k4g5qg8m.skadnetwork",
      "s39g8k73mm.skadnetwork",
      "3qy4746246.skadnetwork",
      "f38h382jlk.skadnetwork",
      "hs6bdukanm.skadnetwork",
      "v4nxqhlyqp.skadnetwork",
      "wzmmz9fp6w.skadnetwork",
      "yclnxrl5pm.skadnetwork",
      "t38b2kh725.skadnetwork",
      "7ug5zh24hu.skadnetwork",
      "gta9lk7p23.skadnetwork",
      "vutu7akeur.skadnetwork",
      "y5ghdn5j9k.skadnetwork",
      "n6fk4nfna4.skadnetwork",
      "v9wttpbfk9.skadnetwork",
      "n38lu8286q.skadnetwork",
      "47vhws6wlr.skadnetwork",
      "kbd757ywx3.skadnetwork",
      "9t245vhmpl.skadnetwork",
      "eh6m2bh4zr.skadnetwork",
      "a2p9lx4jpn.skadnetwork",
      "22mmun2rn5.skadnetwork",
      "4468km3ulz.skadnetwork",
      "2u9pt9hc89.skadnetwork",
      "8s468mfl3y.skadnetwork",
      "klf5c3l5u5.skadnetwork",
      "ppxm28t8ap.skadnetwork",
      "ecpz2srf59.skadnetwork",
      "uw77j35x4d.skadnetwork",
      "pwa73g5rt2.skadnetwork",
      "mlmmfzh3r3.skadnetwork",
      "578prtvx9j.skadnetwork",
      "4dzt52r2t5.skadnetwork",
      "e5fvkxwrpn.skadnetwork",
      "8c4e2ghe7u.skadnetwork",
      "zq492l623r.skadnetwork",
      "3rd42ekr43.skadnetwork",
      "3qcr597p9d.skadnetwork"
    ]
  }
}

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 8 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.