Skip to main content

Interstitial Advertisements

Interstitial ads appear during natural app transitions and are 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

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

To distinguish between the load and show steps, a show button is made and used in the sample.

Also, interstitial advertisements receive activity context and display advertisements without a separate Ad Container.

<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 advertisement objects (GfpInterstitialAdManager) and request parameters (AdParam)

For ad request parameters, an Ad Unit ID is required.

Other values are optional. Please refer to the ad request information.

Interstitial ads are managed by creating a separate Manager object.

danger

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

val adParam = AdParam.Builder().setAdUnitId(AD_UNIT_ID).build()
val interstitialAdManager = GfpInterstitialAdManager(requireActivity(), adParam)

[Step 4] Receiving advertising events

Receive various advertising events such as exposure and click by setting InterstitialAdListener in GfpInterstitialAdManager instance as shown below.

interstitialAdManager.setAdListener(object: InterstitialAdListener() {
override fun onAdLoaded(ad: GfpInterstitialAd) {
// when the ad is loaded
}
override fun onAdStarted(ad: GfpInterstitialAd) {
// when the ad is on
}
override fun onAdClicked(ad: GfpInterstitialAd) {
// when the ad is clicked
}
override fun onAdClosed(ad: GfpInterstitialAd) {
// when the ad is closed
}
override fun onError(ad: GfpInterstitialAd, error: GfpError) {
// when failed to load the ad or error occurs during rendering
}
})

[Step 5] Load and display ads (Show)

  • Once GfpInterstitialAdManager 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.

    • Also, advertisements that have been shown once will not be shown again.

class InterstitialFragment : Fragment() {
private lateinit var interstitialAdManager: GfpInterstitialAdManager
private lateinit var showButton: Button

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_interstitial, container, false)
showButton = view.findViewById(R.id.show_button)
showButton.isEnabled = false
showButton.setOnClickListener {
// Check if ad is already expired or invalidated, and do not show ad if that is the case.
// You will not get paid to show an invalidated ad.
if (interstitialAdManager.isAdInvalidated) {
return@setOnClickListener
}
interstitialAdManager.showAd(requireActivity())
}

val adParam = AdParam.Builder().setAdUnitId(AD_UNIT_ID).build()

interstitialAdManager = GfpInterstitialAdManager(requireActivity(), adParam)

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

interstitialAdManager.setAdListener(object: InterstitialAdListener() {
override fun onAdLoaded(ad: GfpInterstitialAd) {
// ready to show
Log.d("InterstitialFragment", "Succeed to load. responseInfo[${ad.responseInfo}]")
showButton.isEnabled = true
}

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

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

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

override fun onError(ad: GfpInterstitialAd, error: GfpError) {
Log.e("InterstitialFragment", ad.responseInfo.toString())
showButton.isEnabled = false
}
})

interstitialAdManager.loadAd()

return view
}

companion object {
private const val AD_UNIT_ID = "YOUR_AD_UNIT_ID"
}
}

[Step 6] Advertisement Removal

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

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

override fun onDestroy() {
if (::interstitialAdManager.isInitialized) {
interstitialAdManager.destroy()
}
super.onDestroy()
}