StageUp
모바일 SDK프로모션

React Native

React Native 애플리케이션에서 NBase AdStage SDK를 사용한 프로모션 관리 가이드입니다.

1. 개요

  • 프로모션(Promotion)은 앱 내에서 마케팅 캠페인, 배너, 팝업 등을 표시하고 추적하는 기능입니다.
  • AdStage SDK는 프로모션 조회, 표시(열기), 추적 기능을 제공합니다.

2. 빠른 시작

npm install nbase-ad-react-native-sdk
# 또는
yarn add nbase-ad-react-native-sdk
 
# iOS의 경우 추가로
cd ios && pod install

3. 프로모션 기능

3.1 프로모션 열기

특정 조건에 맞는 프로모션을 열어 사용자에게 표시합니다.

import { AdStageSDK } from 'nbase-ad-react-native-sdk';
import { Linking } from 'react-native';
 
const showPromotion = async () => {
	try {
		const result = await AdStageSDK.openPromotion({
			bannerType: 'NATIVE',           // 배너 타입: NATIVE, POPUP, BANNER
			targetAudience: 'new_user',     // 타겟 오디언스
			showTodayButton: true,          // "오늘 하루 보지 않기" 버튼 표시
		});
    
		if (result.success && result.url) {
			console.log('프로모션 URL:', result.url);
			// 외부 브라우저로 프로모션 페이지 열기
			await Linking.openURL(result.url);
      
			// 프로모션 오픈 이벤트 추적(선택)
			AdStageSDK.trackEvent('promotion_opened', {
				url: result.url,
				promotionId: result.promotionId,
				timestamp: new Date().toISOString(),
			});
		} else {
			console.log('표시할 프로모션이 없습니다.');
		}
    
	} catch (error) {
		console.error('프로모션 열기 실패:', error);
	}
};
 
// 다양한 배너 타입으로 프로모션 열기
const showPopupPromotion = async () => {
	const result = await AdStageSDK.openPromotion({
		bannerType: 'POPUP',
		targetAudience: 'all',
		showTodayButton: true,
	});
	if (result.success && result.url) {
		await Linking.openURL(result.url);
	}
};
 
const showBannerPromotion = async () => {
	const result = await AdStageSDK.openPromotion({
		bannerType: 'BANNER',
		targetAudience: 'returning_user',
		showTodayButton: false,
	});
	if (result.success && result.url) {
		await Linking.openURL(result.url);
	}
};

3.2 프로모션 목록 조회

사용 가능한 프로모션 목록을 조회하여 앱 내에서 표시합니다.

import { AdStageSDK } from 'nbase-ad-react-native-sdk';
 
const loadPromotionList = async () => {
	try {
		const result = await AdStageSDK.getPromotionList({
			bannerType: 'BANNER',    // 배너 타입 필터
			limit: 10,               // 최대 조회 개수
		});
    
		console.log(`총 ${result.promotions.length}개의 프로모션 발견`);
    
		result.promotions.forEach((promotion, index) => {
			console.log(`프로모션 ${index + 1}:`);
			console.log(`   ID: ${promotion.id}`);
			console.log(`   제목: ${promotion.title}`);
			console.log(`   설명: ${promotion.description}`);
			console.log(`   이미지 URL: ${promotion.imageUrl}`);
			console.log(`   링크 URL: ${promotion.linkUrl}`);
			console.log(`   시작일: ${promotion.startDate}`);
			console.log(`   종료일: ${promotion.endDate}`);
			console.log('---');
		});
    
		return result.promotions;
    
	} catch (error) {
		console.error('프로모션 목록 로드 실패:', error);
		return [];
	}
};
 
// 배너 타입별 조회 예시
const loadBannerPromotions = async () => {
	return await AdStageSDK.getPromotionList({
		bannerType: 'BANNER',
		limit: 5,
	});
};
 
const loadPopupPromotions = async () => {
	return await AdStageSDK.getPromotionList({
		bannerType: 'POPUP',
		limit: 3,
	});
};
 
const loadNativePromotions = async () => {
	return await AdStageSDK.getPromotionList({
		bannerType: 'NATIVE',
		limit: 10,
	});
};

4. 문제 해결

프로모션이 표시되지 않음

  • 네이티브 초기화(예: AdStageInitializer.load())가 완료되었는지 확인
  • 네트워크 연결 상태 확인
  • 서버에 해당 조건의 프로모션이 등록되어 있는지 확인

프로모션 목록이 빈 배열로 반환됨

  • bannerType/targetAudience 설정 확인
  • 서버 등록 상태 및 API 응답 로그 확인

이미지가 로드되지 않음

  • 이미지 URL이 HTTPS인지 확인
  • Android: 네트워크 보안 설정 확인
  • iOS: ATS(App Transport Security) 설정 확인

WebView/브라우저가 열리지 않음

  • Linking.canOpenURL() 결과 확인
  • URL 형식 확인, 디바이스에 브라우저 앱 존재 여부 확인

빌드 오류

  • npm install && cd ios && pod install 재실행
  • React Native 캐시 클리어: npx react-native start --reset-cache
  • Android 클린 빌드: cd android && ./gradlew clean

목차