> ## Documentation Index
> Fetch the complete documentation index at: https://guide.daro.so/llms.txt
> Use this file to discover all available pages before exploring further.

# 리워드 비디오 광고

## 리워드 비디오 형태 소개

* 광고 시청을 대가로 인앱 가치를 지닌 보상(재화, 기능, 컨텐츠 등)을 제공하는 형태의 광고입니다.
* 보상을 대가로 시청하므로 동영상 광고의 스킵이 불가능하며 일반적인 길이는 30초입니다.

<img src="https://mintcdn.com/delightroom-5a71a6a8/dxU0bpsPoPvkYh_g/sdk-integration/common-img/ad-formats/rv-example-image.png?fit=max&auto=format&n=dxU0bpsPoPvkYh_g&q=85&s=42c4b8429cf25ce598c679e6eee00f70" alt="Rv Example Image Pn" title="Rv Example Image Pn" style={{ width:"38%" }} width="1080" height="2336" data-path="sdk-integration/common-img/ad-formats/rv-example-image.png" />

### 동작 예시

<img src="https://mintcdn.com/delightroom-5a71a6a8/dxU0bpsPoPvkYh_g/sdk-integration/common-img/ad-formats/rv-example-gif.gif?s=e6a8679d28bbe4600a449121ba4bbe53" alt="Rv Example Gif Gi" title="Rv Example Gif Gi" style={{ width:"38%" }} width="180" height="389" data-path="sdk-integration/common-img/ad-formats/rv-example-gif.gif" />

***

## 구현하기

리워드 비디오 광고는 Hook API로 사용합니다. 컴포넌트 내부에서 `useRewardedAd`를 사용하면 로딩 상태와 리워드 콜백을 함께 관리할 수 있습니다.

<Warning>
  기존의 정적 API(`RewardedAd.loadAd` 등)는 deprecated입니다. 정적 리스너(`RewardedAd.addAdLoadedEventListener` 등)는 Hook이나 인스턴스 API로 로드한 광고의 이벤트를 받지 못하니, 광고 로드를 새 API로 옮길 때 이벤트 리스너도 함께 옮겨주세요.
</Warning>

```javascript theme={null}
import { Button } from "react-native";
import { useRewardedAd } from "react-native-daro";

function RewardedAdButton({ adUnitId }) {
  const { isLoaded, isLoading, load, show, isAdReady } = useRewardedAd(
    adUnitId,
    {
      onLoaded: (adInfo) => {
        // 광고 로드 성공
      },
      onLoadFailed: (errorInfo) => {
        // 광고 로드 실패
      },
      onReceivedReward: (rewardInfo) => {
        // 리워드 지급
      },
      onHidden: (adInfo) => {
        // 광고 닫힘
      },
      onImpressionRecorded: (adInfo) => {
        // 광고 impression 기록
      },
    }
  );

  const handlePress = async () => {
    if (await isAdReady()) {
      show("CUSTOM_DATA");
      return;
    }

    load();
  };

  return (
    <Button
      disabled={isLoading}
      title={isLoaded ? "Show Rewarded" : "Load Rewarded"}
      onPress={handlePress}
    />
  );
}
```

## 리워드 비디오 광고 콜백 메서드

* 다음 코드는 사용자의 내부 User ID를 태그하고, 콜백에 CustomData를 추가하는 방법을 보여줍니다.
  * User ID 문자열의 최대 크기는 8192자입니다.

```javascript theme={null}
setUserId("${USER_ID}");

// useRewardedAd 가 돌려주는 show 에 CustomData 를 넘깁니다.
const { isLoaded, show } = useRewardedAd(REWARDED_AD_UNIT_ID);

if (isLoaded) {
  show("CUSTOM_DATA");
}
```
