Native Simple Advertisements
Native Simple advertisements only contain media view information without any asset information such as title, unlike native advertisements. It allows native ads to be displayed similarly to banner ads while omitting complicated settings and additional work.
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] Integrate NAM SDK
Please refer to common integration details..
The following steps will assume that the NAM SDK application has been completed.
Native Simple Ads only support the NDA module. Please add this module.
[Step 2] Layout configuration
To display a native ad, it is necessary to add the GfpNativeSimpleAdView in which the native simple ad will be inserted into the Activity or Fragment layout. This layout will be the ad location.
In the example below, a native ad declared a GfpNativeSimpleAdView in the ConstraintLayout ViewGroup with the ID native_simple_ad_view
.
<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=".SmartChannelFragment">
<com.naver.gfpsdk.GfpNativeSimpleAdView
android:id="@+id/native_simple_ad_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
[Step 3] Create AdParam and GfpAdLoader
Create GfpAdLoader to request native simple ads.
An AdParam object containing the ad request information is created and assigned to the GfpAdLoader creator.
Request information other than the Ad Unit ID is optional. Please refer to the ad request information.
3-1. Ad request timeout settings
A separate timeout for each ad request could be set by adding withTimeoutMillis() of the GfpAdLoader Builder settings as below.
If the setting is not selected, the default value will use the global settings (Default: 60 seconds) through SdkProperties
.
3-2. GfpNativeSimpleAdOptions
-
setAdChoicesPlacement
Set the location of the AD badge where the Native Simple advertisements will be displayed.
There are four values for the settings.
- ADCHOICES_TOP_LEFT
- ADCHOICES_TOP_RIGHT (default)
- ADCHOICES_BOTTOM_RIGHT
- ADCHOICES_BOTTOM_LEFT
-
setPlaceAdChoicesInAdViewCorner
If you set 'true' on api, the badge for Ad Choices will be rendered on AdView (based on GfpNativeSimpleAdView
).
3-3. Reception of ad loading events - GfpNativeAd.OnNativeSimpleAdLoadedListener
When an ad is successfully loaded through GfpAdLoader.Builder#withNativeSimpleAd(GfpNativeSimpleAdOptions, OnNativeSimpleAdLoadedListener)
, the GfpNativeSimpleAd object containing the loaded advertisement information is transmitted to the GfpNativeAd.OnNativeSimpleAdLoadedListener#onNativeSimpleAdLoaded()
parameter.
When loading is complete, set up GfpNativeSimpleAdView
in the corresponding listener.
- Kotlin
- Java
adLoader = GfpAdLoader.Builder(this, adParam)
.withNativeSimpleAd(adOptions, object: GfpNativeSimpleAd.OnNativeSimpleAdLoadedListener {
override onNativeSimpleAdLoaded(nativeSimpleAd: GfpNativeSimpleAd) {
nativeSimpleAdView.setNativeSimpleAd(nativeSimpleAd)
}
})
.build()
adLoader = new GfpAdLoader.Builder(this, adParam)
.withNativeSimpleAd(adOptions, new GfpNativeSimpleAd.OnNativeSimpleAdLoadedListener() {
@Override
public void onNativeSimpleAdLoaded(GfpNativeSimpleAd nativeSimpleAd) {
nativeSimpleAdView.setNativeSimpleAd(nativeSimpleAd);
}
})
.build();
3-4. AdEventListener
By setting up GfpAdLoader.Builder#withAdListener(AdEventListener)
, events for a click, impression, error, etc. except loading can be received.
- Kotlin
- Java
adLoader = GfpAdLoader.Builder(this, adParam)
// . . .
.withAdListener(object: AdEventListener() {
override fun onAdClicked() {
}
override fun onAdImpression() {
}
override fun onAdMuted() {
}
override fun onError(error: GfpError) {
}
})
// . . .
.build()
adLoader = new GfpAdLoader.Builder(this, adParam)
// . . .
.withAdListener(new AdEventListener() {
@Override
public void onAdClicked() {
}
@Override
public void onAdImpression() {
}
@Override
public void onAdMuted() {
}
@Override
public void onError(GfpError error) {
}
})
// . . .
.build();
[Step 4] Loading advertisement
Advertisements can be loaded once the settings for GfpAdLoader
have been completed.
When loading ads through a single GfpAdLoader, one request must be made at a time.
When reusing the GfpAdLoader, loadAd()
must be called again after each request is completed to start the next request.
If loadAd()
is called again before the request is complete, the previous load may be canceled or the previously loaded ad may be deleted.
- Kotlin
- Java
import ...
import com.naver.gfpsdk.AdEventListener
import com.naver.gfpsdk.AdParam
import com.naver.gfpsdk.GfpAdLoader
import com.naver.gfpsdk.GfpError
import com.naver.gfpsdk.GfpNativeSimpleAdOptions
import com.naver.gfpsdk.GfpNativeSimpleAdView
import com.naver.gfpsdk.GfpResponseInfo
class SmartChannelFragment : Fragment() {
private lateinit var adLoader: GfpAdLoader
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_smart_channel, container, false)
val nativeSimpleAdView: GfpNativeSimpleAdView = view.findViewById(R.id.native_simple_ad_view)
val adParam: AdParam = AdParam.Builder().setAdUnitId(AD_UNIT_ID).build()
val adOptions: GfpNativeSimpleAdOptions = GfpNativeSimpleAdOptions.Builder()
.setAdChoicesPlacement(GfpNativeSimpleAdOptions.ADCHOICES_TOP_RIGHT)
.build()
adLoader = GfpAdLoader.Builder(this, adParam)
.withAdListener(object: AdEventListener() {
override fun onAdClicked() {
Log.d("SmartchannelFragment", "click")
}
override fun onAdImpression() {
Log.d("SmartchannelFragment", "impression")
}
override fun onAdMuted() {
Log.d("SmartchannelFragment", "mute(block)")
}
override fun onError(error: GfpError, responseInfo: GfpResponseInfo) {
Log.e("SmartchannelFragment", responseInfo.toString())
}
})
.withNativeSimpleAd(
adOptions,
object: GfpNativeSimpleAd.OnNativeSimpleAdLoadedListener { nativeSimpleAd ->
nativeSimpleAdView.setNativeSimpleAd(nativeSimpleAd)
}
)
.build()
adLoader.loadAd()
return view
}
companion object {
private const val AD_UNIT_ID = "YOUR_AD_UNIT_ID"
}
}
import ...
import com.naver.gfpsdk.AdEventListener;
import com.naver.gfpsdk.AdParam;
import com.naver.gfpsdk.GfpAdLoader;
import com.naver.gfpsdk.GfpError;
import com.naver.gfpsdk.GfpNativeSimpleAdOptions;
import com.naver.gfpsdk.GfpNativeSimpleAdView;
import com.naver.gfpsdk.GfpResponseInfo;
public class SmartChannelFragment extends Fragment {
private static final String AD_UNIT_ID = "YOUR_AD_UNIT_ID";
private GfpAdLoader adLoader;
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_smart_channel, container, false);
GfpNativeSimpleAdView nativeSimpleAdView = view.findViewById(R.id.native_simple_ad_view);
AdParam adParam = new AdParam.Builder().setAdUnitId(AD_UNIT_ID).build();
GfpNativeSimpleAdOptions adOptions = new GfpNativeSimpleAdOptions.Builder()
.setAdChoicesPlacement(GfpNativeSimpleAdOptions.ADCHOICES_TOP_RIGHT)
.build();
adLoader = new GfpAdLoader.Builder(this, adParam)
.withAdListener(new AdEventListener() {
@Override
public void onAdClicked() {
Log.d("SmartchannelFragment", "click");
}
@Override
public void onAdImpression() {
Log.d("SmartchannelFragment", "impression");
}
@Override
public void onAdMuted() {
Log.d("SmartchannelFragment", "mute(block)");
}
@Override
public void onError(GfpError error, GfpResponseInfo responseInfo) {
Log.e("SmartchannelFragment", responseInfo.toString());
}
})
.withNativeSimpleAd(adOptions, new GfpNativeSimpleAd.OnNativeSimpleAdLoadedListener() {
@Override
public void onNativeSimpleAdLoaded(GfpNativeSimpleAd nativeSimpleAd) {
nativeSimpleAdView.setNativeSimpleAd(nativeSimpleAd);
}
})
.build();
adLoader.loadAd();
}
}
[Step 5] Advertisement removal
Once the display of the native ad is terminated, the ad must be removed for proper disposal.
To remove an ad, call cancel()
provided by GfpAdLoader
as shown below.
- Kotlin
- Java
override fun onDestroy() {
super.onDestroy()
adLoader?.let { it.cancel() }
}
@Override
public void onDestroy() {
super.onDestroy();
if (adLoader != null) {
adLoader.cancel();
}
}