# 리워드 비디오 광고

## 1. 인스턴스 생성

placementId를 파라미터로 넘겨주고 리워드비디오 광고 관련 인스턴스를 생성한다.

{% code title="JavaScript" %}

```javascript
RNAdPopcornRewardVideoAdModule.createInstance('YOUR_APP_KEY', 'PLACEMENT_ID');
```

{% endcode %}

## 2. 광고 요청

리워드 비디오  광고 노출을 원하는 시점에 <mark style="color:red;">`loadAd()`</mark> API를 호출하여 서버에 광고를 요청합니다.

{% code title="JavaScript" %}

```javascript
RNAdPopcornRewardVideoAdModule.loadAd('PLACEMENT_ID');
```

{% endcode %}

## 3. 광고 노출

리워드비디오 광고 노출 시점에 <mark style="color:red;">`showAd()`</mark> API를 추가하여 광고를 노출합니다.

{% code title="JavaScript" %}

```javascript
RNAdPopcornRewardVideoAdModule.showAd('PLACEMENT_ID');
```

{% endcode %}

## 4. 이벤트 연동

{% code title="JavaScript" %}

```javascript
componentDidMount() {
    ...
    const eventEmitter = new NativeEventEmitter();
    eventEmitter.addListener('OnRewardVideoAdLoaded', (event) => {
            console.log('OnRewardVideoAdLoaded event : ' + event.placementId);
            }
        );
    ...
  }
```

{% endcode %}

| 이벤트                                                          | 설명                        |
| ------------------------------------------------------------ | ------------------------- |
| <mark style="color:red;">`OnRewardVideoAdLoaded`</mark>      | 리워드 비디오 로딩 성공             |
| ㄴevent.placementId                                           | 리워드 비디오 로딩 성공한 지면 키       |
| <mark style="color:red;">`OnRewardVideoAdLoadFailed`</mark>  | 리워드 비디오 로딩 실패             |
| ㄴevent.placementId                                           | 리워드 비디오 로딩 실패한 지면 키       |
| ㄴevent.errorCode                                             | 리워드 비디오 로딩 실패 에러코드        |
| ㄴevent.errorMessage                                          | 리워드 비디오 로딩 실패 에러 메시지      |
| <mark style="color:red;">`OnRewardVideoAdOpened`</mark>      | 리워드 비디오 노출                |
| ㄴevent.placementId                                           | 노출된 리워드 비디오 광고 지면 키       |
| <mark style="color:red;">`OnRewardVideoAdOpenFalied`</mark>  | 리워드 비디오 노출 실패             |
| ㄴevent.placementId                                           | 노출 실패한 리워드 비디오 광고 지면 키    |
| <mark style="color:red;">`OnRewardVideoAdClosed`</mark>      | 리워드 비디오 닫기                |
| ㄴevent.placementId                                           | 리워드 비디오 광고 닫은 지면 키        |
| <mark style="color:red;">`OnRewardVideoAdClicked`</mark>     | 리워드 비디오 클릭                |
| ㄴevent.placementId                                           | 리워드 비디오 광고 클릭한 지면 키       |
| <mark style="color:red;">`OnRewardVideoPlayCompleted`</mark> | 리워드 비디오 재생 완료             |
| ㄴ event.placementId                                          | 리워드 비디오 재생 완료한 지면 키       |
| <mark style="color:red;">`OnRewardPlusCompleted`</mark>      | 리워드 플러스 활성화된 지면의 적립 요청 완료 |
| ㄴ event.resultCode                                           | 적립 요청 결과 코드               |
| ㄴ event.reward                                               | 적립 요청된 포인트                |

* <mark style="color:red;">`OnRewardVideoAdClicked`</mark> **:** 클릭 이벤트의 경우 Android에서만 제공됩니다.

## 5. 샘플 코드

{% code title="JavaScript" %}

```javascript
import React, { useEffect } from 'react';
import {
  NativeModules,
  NativeEventEmitter
} from 'react-native';

const RNAdPopcornRewardVideoAdModule = NativeModules.RNAdPopcornRewardVideoAdModule;

function App(): JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };
  RNAdPopcornSSPModule.init();

  RNAdPopcornRewardVideoAdModule.createInstance('YOUR_APP_KEY', 'PLACEMENT_ID');
  RNAdPopcornRewardVideoAdModule.loadAd('PLACEMENT_ID');

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />

      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}>
        <Header />        
      </ScrollView>
    </SafeAreaView>
  );
}


componentDidMount() {
  ...
  const eventEmitter = new NativeEventEmitter();
  eventEmitter.addListener('OnRewardVideoAdLoaded', (event) => {
          console.log('OnRewardVideoAdLoaded event : ' + event.placementId);
          RNAdPopcornRewardVideoAdModule.showAd(event.placementId);
          }
      );
  ...
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://adpopcornssp.gitbook.io/ssp-sdk/sdk/react-native-beta/undefined-4.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
