# 전면 광고

## 1. 인스턴스 생성

AppKey와 placementId를 파라미터로 넘겨주고 전면 광고 인스턴스를 생성합니다.

{% code title="JavaScript" %}

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

{% endcode %}

## 2. 전면 광고 색상 변경

{% code title="JavaScript" %}

```javascript
RNAdPopcornInterstitialAdModule.setAdPopcornAdBackgroundColor('PLACEMENT_ID',
'#ffff0000')
```

{% endcode %}

{% hint style="info" %}
iOS의 경우 AdPopcornSSP `2.5.6` 이상의 버전을 사용해야 해당 옵션이 동작합니다.
{% endhint %}

{% hint style="info" %}
Color 코드의 경우 [#AARRGGBB](https://yuuj.tistory.com/15) 형식에 맞춰 입력해야 정상 동작 합니다.
{% endhint %}

## 3. 광고 요청

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

{% code title="JavaScript" %}

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

{% endcode %}

## 4. 광고 노출

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

{% code title="JavaScript" %}

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

{% endcode %}

## 5. 이벤트 연동

{% code title="JavaScript" %}

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

{% endcode %}

| 이벤트                                                           | 설명              |
| ------------------------------------------------------------- | --------------- |
| <mark style="color:red;">`OnInterstitialLoaded`</mark>        | 전면 로딩 성공        |
| ㄴevent.placementId                                            | 전면 로딩 성공한 지면 키  |
| <mark style="color:red;">`OnInterstitialReceiveFailed`</mark> | 전면 로딩 실패        |
| ㄴevent.placementId                                            | 전면 로딩 실패한 지면 키  |
| ㄴevent.errorCode                                              | 전면 로딩 실패 에러코드   |
| ㄴevent.errorMessage                                           | 전면 로딩 실패 에러 메시지 |
| <mark style="color:red;">`OnInterstitialOpened`</mark>        | 전면 노출           |
| ㄴevent.placementId                                            | 노출된 전면 광고 지면 키  |
| <mark style="color:red;">`OnInterstitialOpenFailed`</mark>    | 전면 노출 실패        |
| ㄴevent.placementId                                            | 전면 노출 실패        |
| <mark style="color:red;">`OnInterstitialClosed`</mark>        | 전면 닫기           |
| ㄴevent.placementId                                            | 전면 광고 닫은 지면 키   |
| <mark style="color:red;">`OnInterstitialClicked`</mark>       | 전면 클릭           |
| ㄴevent.placementId                                            | 전면 광고 클릭한 지면 키  |

## 6. 샘플 코드

{% code title="JavaScript" %}

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

const RNAdPopcornInterstitialAdModule = NativeModules.RNAdPopcornInterstitialAdModule;

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

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

	RNAdPopcornInterstitialAdModule.createInstance('YOUR_APP_KEY', 'PLACEMENT_ID');
  RNAdPopcornInterstitialAdModule.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('OnInterstitialLoaded', (event) => {
          console.log('OnInterstitialLoaded event : ' + event.placementId);
					RNAdPopcornInterstitialAdModule.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-2.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.
