Skip to main content

Rewarded Advertisements

Rewarded ads provide incentives and rewards to users when they complete watching a video in full screen.


Before Starting

  • Ad Unit ID is required for ad calling.

    Please complete the settings for advertising provider, inventory, and registering of ad units through the NAM Admin.

    Please contact the NAM manager for related inquiries.

  • If there are other Views at the top of the ad, the exposure measurement may not be performed properly, resulting in a disadvantage in measuring performance indicators.

[Step 1] NAM SDK integration complete

Please refer to common integration details..

The following steps will assume that the NAM SDK application has been completed.


[Step 2] (Sample options) Add layout

(Unlike banner or native ads) it is not necessary to create an Ad Container for reward-type advertising.

While banner ads or native ads are displayed once the loading is complete, reward-type ads have a separate method to display the ads after loading.

Therefore, to distinguish between the load and show steps of the advertisement, a show button is made and used in the sample.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/show_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="SHOW" />

</androidx.constraintlayout.widget.ConstraintLayout>

[Step 3] Create and load advertising parameters

After creating a GfpRewardedAdManager instance, reward-type advertisements can be loaded by calling the loadAd() method.

danger

At this point, an activity context will be required. Some DSPs may malfunction if the activity context is not transmitted.

In banner or native ads, loading is connected to ad display (show). However, in reward-type/interstitial ads, load and show are separated.

load is the step for preparing to show an advertisement.


[Step 4] Receiving advertising events

Receive various advertising events by setting RewardedAdListener in GfpRewardedAdManager instance as shown below.

Information on reward-type advertising can be received via the onAdCompleted method.

rewardedAdManager.setAdListener(object: RewardedAdListener() {
override fun onAdLoaded(ad: GfpRewardedAd) {
// when the ad is loaded
}

override fun onAdStarted(ad: GfpRewardedAd) {
// when the ad is on
}

override fun onAdClicked(ad: GfpRewardedAd) {
// when the ad is clicked
}

override fun onAdClosed(ad: GfpRewardedAd) {
// when the ad is closed
}

override fun onAdCompleted(ad: GfpRewardedAd) {
// when the ad is completed
}

override fun onError(ad: GfpRewardedAd, error: GfpError) {
// when failed to load the ad or error occurs during rendering
}
})

[Step 5] Load and display ads (Show)

  • Once GfpRewardedAdManager settings have been completed, advertisements can be loaded through loadAd().
  • If the ad has been loaded successfully, the ad can be displayed.
    • Before displaying an ad, the validity of the ad can be checked optionally by calling isAdInvalidated().

      If the method result is true, the advertisement is invalid. Therefore, the advertisement could be displayed depending on the advertisement provider but the charging may not occur.

      Note that each DSP may have a valid ad time. Although it may differ from each DSP, it may become invalid if it has been a while since loading.

    • Advertisements that have been shown once will not be shown again.

class RewardedFragment : Fragment() {
private lateinit var rewardedAdManager: GfpRewardedAdManager
private lateinit var showButton: Button

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_rewarded, container, false)
showButton = view.findViewById(R.id.show_button)
showButton.isEnabled = false

showButton.setOnClickListener {
// check validation
if (rewardedAdManager.isAdInvalidated()) {
Log.d("MainActivity", "the ad is invalid")
return@setOnClickListener
}

rewardedAdManager.showAd(requireActivity())
}

val adParam: AdParam = AdParam.Builder()
.setAdUnitId("YOUR_AD_UNIT_ID")
.addUserParam("testKey", "testValue")
.build()

rewardedAdManager = GfpRewardedAdManager(requireActivity(), adParam)

// set timeout (optional)
// rewardedAdManager.setTimeoutMillis(60_000L);

rewardedAdManager.setAdListener(object: RewardedAdListener() {
override fun onAdLoaded(ad: GfpRewardedAd) {
Log.d("RewardedFragment", "succeed to load. responseInfo[${ad.responseInfo}]")
showButton.isEnabled = true
}

override fun onAdStarted(ad: GfpRewardedAd) {
Log.d("RewardedFragment", "start the ad")
}

override fun onAdClicked(ad: GfpRewardedAd) {
Log.d("RewardedFragment", "click occurs")
}

override fun onAdClosed(ad: GfpRewardedAd) {
Log.d("RewardedFragment", "close the ad")
showButton.isEnabled = false
}

override fun onAdCompleted(ad: GfpRewardedAd) {
// you can get reward here.
Log.d(
"RewardedFragment",
"complete - responseInfo[${ad.responseInfo}]"
)
}

override fun onError(ad: GfpRewardedAd, error: GfpError) {
Log.e("RewardedFragment", ad.responseInfo.toString())
}
})

rewardedAdManager.loadAd()

return view
}
}

[Step 6] Destroy

Once the display of the banner ad is terminated, the ad must be removed for proper disposal.

To remove an ad, call destroy() provided by GfpRewardedAdManager as shown below.

rewardedAdManager.destroy()