React Native 네이티브 광고
앱의 UI에 자연스럽게 통합되는 맞춤형 광고입니다. 광고의 각 요소(제목, 본문, 이미지 등)를 개별적으로 배치하여 앱의 디자인에 맞게 표시할 수 있습니다.
시작하기 전에
기본 구조
1
2
네이티브 광고 구현하기
import React, { useEffect, useState, useMemo } from 'react';
import { View, StyleSheet, Dimensions } from 'react-native';
import {
AdropNativeAd,
AdropNativeAdView,
AdropHeadLineView,
AdropBodyView,
AdropProfileLogoView,
AdropProfileNameView,
AdropMediaView,
type AdropNativeAdListener,
} from 'adrop-ads-react-native';
const NativeAdExample = () => {
const [nativeAd, setNativeAd] = useState<AdropNativeAd>();
const [isLoaded, setIsLoaded] = useState(false);
const listener: AdropNativeAdListener = useMemo(() => ({
onAdReceived: (ad) => {
console.log('광고 로드됨:', ad.properties);
setIsLoaded(true);
},
onAdFailedToReceive: (ad, errorCode) => {
console.log('광고 로드 실패:', errorCode);
},
onAdClicked: (ad) => {
console.log('광고 클릭됨');
},
onAdImpression: (ad) => {
console.log('광고 노출됨');
},
}), []);
useEffect(() => {
const ad = new AdropNativeAd('YOUR_UNIT_ID');
ad.listener = listener;
setNativeAd(ad);
return () => {
ad.destroy();
};
}, [listener]);
const handleLoad = () => nativeAd?.load();
if (!isLoaded) {
return (
<View>
<Button title="네이티브 광고 로드" onPress={handleLoad} />
</View>
);
}
return (
<AdropNativeAdView
nativeAd={nativeAd}
style={{ width: Dimensions.get('window').width }}
>
<View style={styles.adContainer}>
<View style={styles.header}>
<AdropProfileLogoView style={styles.logo} />
<AdropProfileNameView style={styles.profileName} />
</View>
<AdropHeadLineView style={styles.headline} />
<AdropBodyView style={styles.body} />
{/* Backfill 광고인 경우 AdropMediaView 사용 */}
{nativeAd.isBackfilled ? (
<AdropMediaView style={styles.media} />
) : (
/* 일반 광고인 경우 WebView로 크리에이티브 표시 */
<WebView
source={{ html: nativeAd.properties.creative ?? '' }}
style={styles.media}
javaScriptEnabled={true}
onNavigationStateChange={(event) => {
if (event.url && !event.url.startsWith('data:')) {
openUrl(event.url);
}
}}
/>
)}
</View>
</AdropNativeAdView>
);
};
const styles = StyleSheet.create({
adContainer: {
padding: 16,
},
header: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 8,
},
logo: {
width: 40,
height: 40,
marginRight: 8,
},
profileName: {
fontSize: 14,
fontWeight: 'bold',
},
headline: {
fontSize: 18,
fontWeight: 'bold',
marginBottom: 8,
},
body: {
fontSize: 14,
color: '#666',
marginBottom: 12,
},
media: {
width: '100%',
height: 200,
},
});Prop
타입
필수
설명
개별 뷰 컴포넌트
컴포넌트
설명
스타일 타입
AdropNativeAd
const nativeAd = new AdropNativeAd(
unitId: string,
useCustomClick?: boolean // 커스텀 클릭 사용 여부 (기본값: false)
);Properties
속성
타입
설명
AdropNativeProperties 타입
type AdropNativeProperties = {
headline?: string; // 제목
body?: string; // 본문
creative?: string; // 크리에이티브 HTML
asset?: string; // 에셋
destinationURL?: string; // 클릭 시 이동 URL
callToAction?: string; // CTA 텍스트
profile?: {
displayName: string; // 프로필 이름
displayLogo: string; // 프로필 로고 URL
};
extra?: Record<string, string>; // 추가 데이터
isBackfilled?: boolean; // Backfill 광고 여부
};AdropNativeAdListener 인터페이스
interface AdropNativeAdListener {
onAdReceived?: (ad: AdropNativeAd) => void; // 광고 로드 성공
onAdClicked?: (ad: AdropNativeAd) => void; // 광고 클릭
onAdImpression?: (ad: AdropNativeAd) => void; // 광고 화면 노출
onAdFailedToReceive?: (ad: AdropNativeAd, errorCode?: string) => void; // 광고 로드 실패
}미디어 렌더링: 직광고 vs Backfill 광고
Type
isBackfilled
Render Method
3
커스텀 필드 데이터 사용
<AdropNativeAdView
nativeAd={nativeAd}
style={{
...styles.adContainer,
width: Dimensions.get('window').width,
}}
>
<View style={styles.rowContainer}>
<Text>{nativeAd.properties.extra['t1']}</Text>
<Text>{nativeAd.properties.extra['t2']}</Text>
<Text>{nativeAd.properties.extra['t3']}</Text>
</View>
</AdropNativeAdView>
useCustomClick 옵션
주의사항
Last updated