# Rewarded Ad

## 1. 기본 요건

* [<mark style="color:blue;">ADX Flutter SDK</mark>](/adx/flutter/integrate.md)를 프로젝트에 추가합니다.
* Rewarded Ad용으로 발급받은 ADX Ad Unit ID를 사용합니다.
* 광고를 요청하기 전에 [<mark style="color:blue;">SDK 초기화</mark>](/adx/flutter/sdk-integration/initialize.md)를 먼저 진행합니다.
  * **SDK 초기화는 앱 실행 시 한 번만 호출**하여 주시고, **광고 요청은 초기화가 완료된 후**에 이뤄져야 합니다.

## 2. 구현

1. Android와 iOS 모두 배포된 경우 플랫폼 별로 발급받은 Ad Unit ID를 입력합니다.
2. 필요한 콜백을 등록합니다.
3. `AdxSdk.loadRewardedAd()` 를 호출하여 광고를 로드합니다.
4. 광고 객체 해지시 `AdxSdk.destroyRewardedAd()` 를 호출합니다.

```dart
String adUnitId = Platform.isAndroid ? "<ANDROID_ADX_REWARDED_AD_UNIT_ID>" : "<IOS_ADX_REWARDED_AD_UNIT_ID>";

AdxSdk.setRewardedAdListener(RewardedAdListener(
  onAdLoaded: (){
  },
  onAdError: (int errorCode){
  },
  onAdImpression: (){
  },
  onAdClicked: (){
  },
  onAdRewarded: (){
  },
  onAdClosed: (){
  },
  onAdFailedToShow: (){
  })
);

AdxSdk.loadRewardedAd(adUnitId);
```

* 광고가 로드가 되면 `showRewardedAd()` 를 호출하여 광고를 표출합니다.

```csharp
bool isLoaded = (await AdxSdk.isRewardedAdLoaded(adUnitId))!;
if (isLoaded) {
    AdxSdk.showRewardedAd(adUnitId);
}
```

{% hint style="info" %}
SSV (Server-side verification) 설정이 필요한 경우 '`showRewardedAd`' 메소드의 **Named Parameter로 정의된**`ssvUserId`와 `ssvCustomData`를 사용하십시오.
{% endhint %}

```dart
static void showRewardedAd(String adUnitId, {
    String? ssvUserId, 
    String? ssvCustomData
})
```

> * SSV 설정은 **선택사항**으로 필요한 경우에만 설정하여 사용할 수 있습니다.
> * SSV 설정은 보상 이벤트가 발생될 때 개발사에서 등록한 **Callback URL**을 **Server to Server** 방식으로 호출을 하기 위한 설정입니다.
> * SSV 설정에 대한 호출 조건은 아래와 같습니다.
>   * 대시보드를 통해 `Rewarded Video` 타입에서 **Callback URL** 등록이 되어 있어야 합니다.
>   * 비디오 시청 완료 후 보상 이벤트가 발생해야 합니다.
>   * 필요한 경우 광고 요청 전에 SDK를 통해 `User ID` 또는 `Custom Data` 정보를 설정합니다.
> * 클라이언트에서 설정한 `User ID` 와 `Custom Data` 정보가 있다면 **Callback URL**에 포함되어 호출하도록 적용되어 있습니다.
>   * (예시) <https://callback\\_url?param=value\\&userid=\\><valule>\&customdata=\<value>
>   * 해당 설정은 반드시 광고 요청 전에 호출해야 정상적으로 데이터가 **Callback URL**에 포함됩니다.
> * **Flutter ADX Plugin v1.0.6** 이상에서 지원됩니다.
> * [서버측 SSV 콜백 검증](https://docs.adxcorp.kr/appendix/ssv-callback-server-side-verification)을 참고하여 보상에 대한 검증을 합니다.

* 광고 객체 해지시 `destroyRewardedAd()` 를 호출합니다.

```dart
@override
void dispose() {
  super.dispose();
  AdxSdk.destroyRewardedAd(adUnitId);
}
```

## 3. Callback

특정 이벤트를 수신할 수 있습니다. 필요에 따라 구현해주세요.

```dart
class RewardedAdListener {
  void Function() onAdLoaded;
  void Function(int errorCode) onAdError;
  void Function() onAdImpression;
  void Function() onAdClicked;
  void Function() onAdRewarded;
  void Function() onAdClosed;
  void Function() onAdFailedToShow;

  RewardedAdListener({
    required this.onAdLoaded,
    required this.onAdError,
    required this.onAdImpression,
    required this.onAdClicked,
    required this.onAdRewarded,
    required this.onAdClosed,
    required this.onAdFailedToShow
  });
}
```


---

# 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://platform-business.gitbook.io/adx/flutter/sdk-integration/ad-formats/rewarded-ad.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.
