nextjs,tailwindcss,vercel

google admob ํ…Œ์ŠคํŠธ ๊ด‘๊ณ  ID ์„ค์ • (expo router)

์ฃผ์˜ ๐Ÿฑ 2024. 11. 16. 10:33
728x90
๋ฐ˜์‘ํ˜•

์•ˆ๋“œ๋กœ์ด๋“œ ์•ฑ ์ถœ์‹œํ•˜๋Š” ๊ณผ์ •์—์„œ ์• ๋“œ๋ชน ํ…Œ์ŠคํŠธ ID ์„ค์ •ํ•˜๋Š”๋ฒ• ์ •๋ฆฌ

 

 ๊ฐœ๋ฐœ ์ค‘์—๋Š” ํ…Œ์ŠคํŠธ ๊ด‘๊ณ ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ด‘๊ณ ๋ฅผ ํด๋ฆญํ•ด๋„ Google ๊ด‘๊ณ ์ฃผ์—๊ฒŒ ๋น„์šฉ์ด ์ฒญ๊ตฌ๋˜์ง€ ์•Š๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”

์‹ค์ œ ๊ด‘๊ณ ์‚ฌ์šฉํ•˜๊ฒŒ๋˜๋ฉด ๋ฌดํšจ ํด๋ฆญ์œผ๋กœ ๊ณ„์ • ์ •์ง€ ๋‹นํ•  ์ˆ˜ ์žˆ์Œ

 

npx install react-native-google-mobile-ads

 

์• ๋“œ๋ชน์—์„œ ์•ฑ ์ถ”๊ฐ€ ํ•˜๊ณ , ๋‚˜์˜ค๋Š” APP ID ๋ณต์‚ฌ

๊ด‘๊ณ  ํ˜•์‹๋ฐ๋ชจ ๊ด‘๊ณ  ๋‹จ์œ„ ID

์•ฑ ์˜คํ”„๋‹ ๊ด‘๊ณ  ca-app-pub-3940256099942544/9257395921
์ ์‘ํ˜• ๋ฐฐ๋„ˆ ca-app-pub-3940256099942544/9214589741
๊ณ ์ • ํฌ๊ธฐ ๋ฐฐ๋„ˆ ca-app-pub-3940256099942544/6300978111
์ „๋ฉด ๊ด‘๊ณ  ca-app-pub-3940256099942544/1033173712
๋ณด์ƒํ˜• ๊ด‘๊ณ  ca-app-pub-3940256099942544/5224354917
๋ณด์ƒํ˜• ์ „๋ฉด ๊ด‘๊ณ  ca-app-pub-3940256099942544/5354046379
๋„ค์ดํ‹ฐ๋ธŒ ca-app-pub-3940256099942544/2247696110
๋„ค์ดํ‹ฐ๋ธŒ ๋™์˜์ƒ ca-app-pub-3940256099942544/1044960115

 

app.json์— ํ•ด๋‹น ID ์ ์šฉ ( APP ID ์ž„ !! ๊ด‘๊ณ  ๋‹จ์œ„ ID๊ฐ€ ์•„๋‹˜!!!)

"plugins": [
      "expo-router",
      [
        "react-native-google-mobile-ads",
        {
          "androidAppId": "ca-app-pub-xxxxxxxx~xxxxxxxx", // replace with your AppID
          "iosAppId": "ca-app-pub-xxxxxxxx~xxxxxxxx" // replace with your AppID
        }
      ]
    ]

 

testID ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ตœ์ข…์ ์œผ๋กœ ๋ฐฐ๋„ˆ ๊ด‘๊ณ ๋ฅผ ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค

import { Tabs } from 'expo-router';
import { Text, View, StyleSheet, Platform } from 'react-native';
import { BannerAd, BannerAdSize, TestIds } from "react-native-google-mobile-ads";

export default function TabLayout() {
  // Use TestIds in development, real ad unit ID in production
  const adUnitId = __DEV__ 
    ? TestIds.BANNER 
    : "ca-app-pub-3940256099942544/9214589741";

  return (
    <View style={styles.container}>
      <View style={styles.tabContainer}>
        <Tabs
          screenOptions={{
            headerShown: false,
            tabBarActiveTintColor: '#007AFF',
            tabBarInactiveTintColor: '#8E8E93',
          }}
        >
          <Tabs.Screen
            name="index"
            options={{
              title: 'ํ™ˆ',
              tabBarIcon: ({ color }) => (
                <Text style={{ fontSize: 24, color }}>๐Ÿ </Text>
              ),
            }}
          />
          <Tabs.Screen
            name="calculator"
            options={{
              title: '๋ฐฐ๋‹น ํˆฌ์ž ๊ณ„์‚ฐ๊ธฐ',
              tabBarIcon: ({ color }) => (
                <Text style={{ fontSize: 24, color }}>๐Ÿงฎ</Text>
              ),
            }}
          />
          <Tabs.Screen
            name="etf-list"
            options={{
              title: 'ETF ๋ชฉ๋ก',
              tabBarIcon: ({ color }) => (
                <Text style={{ fontSize: 24, color }}>๐Ÿ“ˆ</Text>
              ),
            }}
          />
        </Tabs>
      </View>
      
      <View style={styles.bannerContainer}>
        <BannerAd
          unitId={adUnitId}
          size={BannerAdSize.ANCHORED_ADAPTIVE_BANNER}
          requestOptions={{
            requestNonPersonalizedAdsOnly: true,
            networkExtras: {
              collapsible: "bottom",
            },
          }}
        />
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  tabContainer: {
    flex: 1,
  },
  bannerContainer: {
    width: '100%',
    backgroundColor: 'transparent',
    position: 'absolute',
    bottom: Platform.OS === 'ios' ? 83 : 60, // Adjusted for tab bar height
    alignItems: 'center',
  },
});

 

๋ฐฐ๋„ˆ๊ด‘๊ณ ์™ธ ๋‹ค๋ฅธ๊ฒƒ๋“ค์€ ๊ณต์‹๋ฌธ์„œ ์—์„œ ํ™•์ธ๊ฐ€๋Šฅ

 

 

์‹คํ–‰

*Expo Go ๋Š” ์• ๋“œ๋ชน ํ˜ธํ™˜์ด ์•ˆ๋œ๋‹ค

๋กœ์ปฌ์—์„œ ์ž‘๋™ํ•˜๋Š” EAS ๋นŒ๋“œ ํ™˜๊ฒฝ์„ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ ์—‘์Šคํฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ํด๋ผ์šฐ๋“œ ๋นŒ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค

๊ทธ๋Ÿฌ๋‚˜, EAS๋‚˜ ํด๋ผ์šฐ๋“œ ์„œ๋น„์Šค ์—†์ด๋„ ๋กœ์ปฌ์—์„œ ์—‘์Šคํฌ ์•ฑ์„ ๋นŒ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค

npx expo prebuild

์•ˆ๋“œ๋กœ์ด๋“œ ํ™˜๊ฒฝ์—์„œ๋งŒ ํ•œ๋‹ค๋ฉด, 

npx expo prebuild --platform android

์„ฑ๊ณตํ•˜๋ฉด,

npx expo run:android

 

// if you have iOS
npx expo run:ios

 

Using development build ์ธ์ง€ ํ™•์ธ, EXpo Go๋Š” ์•ˆ๋จ

 

 

์˜ค๋ฅ˜ ๋ฐœ์ƒ ์‹œ

npx expo prebuild --clean

 

๋‚˜์ค‘์— ์‹ค์ œ ์ถœ์‹œ ์‹œ ad unit ID ๋ฐ”๊พธ๋Š” ๊ฒƒ ์žŠ์ง€ ์•Š๊ธฐ!!

๋ฐ˜์‘ํ˜•