Callback for User Interest Expression Timing
When you load an ad using GfpAdLoader, you can utilize callbacks to detect the moment when the user shows interest (when 50% or more of the ad area is exposed for 1 second) and the moment when the interest disappears (when the ad area is no longer exposed). By using this callback, you can, for example, change the Call-to-action button color of a native ad at the moment the user shows interest to increase the ad's visibility.
The usage is as follows:
- Kotlin
- Java
val adLoader = GfpAdLoader.Builder(context, adParam)
.withUserShowInterestListener { showInterest ->
if (showInterest) {
// Triggered when 50% of the ad area is exposed for 1 second
// Example: Change the CTA background color to a distinct color.
} else {
// Triggered when the ad area exposure drops below 0% after the user has shown interest
// Example: Revert the CTA background color to the default color.
}
}
.build()
GfpAdLoader adLoader = new GfpAdLoader.Builder(context, adParam)
.withUserShowInterestListener(showInterest -> {
if (showInterest) {
// Triggered when 50% of the ad area is exposed for 1 second
// Example: Change the CTA background color to a distinct color.
} else {
// Triggered when the ad area exposure drops below 0% after the user has shown interest
// Example: Revert the CTA background color to the default color.
}
})
.build();
Example Usage
Starting from NAM SDK version 6.5.0, an API has been added to retrieve the background color value that can be used for the callToAction asset, one of the assets used in native ads, at the moment the user expresses interest.
- Kotlin
- Java
val adLoader = GfpAdLoader.Builder(context, adParam)
.withUserShowInterestListener(showInterest -> {
if (showInterest) {
// Triggered when 50% of the ad area is exposed for 1 second
nativeAd.callToActionWithOption?.let { callToActionWithOption ->
// Retrieve and apply the background color value available at the moment the user expresses interest
val highlightedBgColor = callToActionWithOption.getHighlightedBgColor(this);
if (highlightedBgColor != null) {
// Apply if a highlighted background color is available
callToActionView.setBackgroundColor(highlightedBgColor)
}
}
} else {
// Triggered when the ad area exposure drops below 0% after the user has shown interest
// Example: Revert the CTA background color to the default color.
callToActionView.setBackgroundColor(defaultBackgroundColor)
}
})
.build();
GfpAdLoader adLoader = new GfpAdLoader.Builder(context, adParam)
.withUserShowInterestListener(showInterest -> {
if (showInterest) {
// Triggered when 50% of the ad area is exposed for 1 second
LabelOption callToActionWithOption = nativeAd.getCallToActionWithOption();
if (callToActionWithOption != null) {
// Retrieve and apply the background color value available at the moment the user expresses interest
Integer highlightedBgColor = callToActionWithOption.getHighlightedBgColor(this);
if (highlightedBgColor != null) {
// Apply if a highlighted background color is available
callToActionView.setBackgroundColor(highlightedBgColor);
}
}
} else {
// Triggered when the ad area exposure drops below 0% after the user has shown interest
// Example: Revert the CTA background color to the default color.
callToActionView.setBackgroundColor(defaultBackgroundColor);
}
})
.build();
GfpNativeAd.getCallToActionWithOption() method returns a nullable value. If the returned LabelOption is not null, the text value is always guaranteed and is the same as the return value of the GfpNativeAd.getCallToAction() method. However, the background color value obtained through the LabelOption.getHighlightedBgColor(context) method can be null.
The LabelOption.getHighlightedBgColor(context) value can be null in the following cases:
- When the response from a C2S ad provider such as DFP, FAN, or InMobi only delivers the string information corresponding to callToAction without providing a background color value.
- When the response is an S2S ad response (using the NDA module) but the callToAction response does not include a background color value.