Android

To manage a Thumbnail ad through Google Ad Manager mediation, Ogury provides a dedicated API that simplifies the integration process.

Initialize the Ogury SDK

To initialize the Ogury SDK, simply call the Ogury.start() method.

Ogury.start(this, "OGY-XXXXXXXXXXXX", object : OguryOnStartListener {
    override fun onStarted() {
        // Initialization successful
    }
    override fun onFailed(error: OguryError) {
        // Handle initialization failure
    }
})

The start() method requires two key parameters :

Though optional, the OguryOnStartListener is recommended. It provides callbacks for successful initialization or errors. If initialization fails, the listener returns an OguryError with an error code and message, helping you troubleshoot. The possible errors are defined in the OguryStartErrorCode class for easy reference.

OguryStartErrorCode

Enum value
Description

MODULE_MISSING

The SDK could not be started because a required SDK module is missing.

MODULE_FAILED_TO_START

The SDK could not be started because one of the required SDK modules failed to start.

Load a Thumbnail ad

To load a Thumbnail ad, instantiate an OguryThumbnailAdForGam object and call its load() method.

By default, the ad loads with a maximum size of 180x180 dp. If needed, you can customize the maximum size by following the guidelines provided in Customizing Thumbnail ad size section.

class MyActivity : Activity() {

    private lateinit var thumbnailAd: OguryThumbnailAdForGam

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        thumbnailAd = OguryThumbnailAdForGam(
            this, 
            "your Google Ad Manager ad unit ID"
        )
        thumbnailAd.load()
    }
}

OguryThumbnailAdForGam requires the following parameters:

  • context: a reference to any kind of Context.

  • adUnitID: the Google Ad Manager ad unit ID for the Thumbnail ad.

Register for callbacks

You can monitor the lifecycle of your Thumbnail ad by implementing the OguryThumbnailAdListener interface. This listener provides real-time updates on key events, such as successful ad loading, display, or errors.

To use it, set the listener on the instance of OguryThumbnailAdForGam by calling the setListener() method before invoking the load() method. Implement the necessary methods in your class to ensure timely notifications, allowing you to manage the ad experience effectively.

If the onAdErrorcallback is triggered, refer to the Error handling section below for detailed information on troubleshooting.

thumbnailAd.listener = object : OguryThumbnailAdListener {

    // Called when the ad is loaded and ready to be shown
    override fun onAdLoaded(thumbnailAd: OguryThumbnailAdForGam) {
        // Call show() to display the ad
    }

    // Called when an impression is recorded
    override fun onAdImpression(thumbnailAd: OguryThumbnailAdForGam) {
        // Track ad performance here
    }

    // Called when the user clicks on the ad
    override fun onAdClicked(thumbnailAd: OguryThumbnailAdForGam) {
        // Handle ad click tracking here
    }

    // Called when the ad is closed
    override fun onAdClosed(thumbnailAd: OguryThumbnailAdForGam) {
        // Resume app flow after ad is closed
    }

    // Called when the ad fails to load or display
    override fun onAdError(thumbnailAd: OguryThumbnailAdForGam, error: OguryAdError) {
        when (error.type) {
            OguryAdError.Type.LOAD_ERROR -> {
                // Handle loading error
            }
            OguryAdError.Type.SHOW_ERROR -> {
                // Handle display error
            }
        }
    }
})

Show a Thumbnail ad

To display an loaded Thumbnail ad, invoke the show() method on the instantiated OguryThumbnailAdForGam object.

By default, Thumbnail ad is aligned to the bottom-right corner, maintaining a margin of 20 dp from the right edge and 70 dp from the bottom. For more information on configuring the ad's position, please refer to the Customizing Thumbnail ad position section.

Additionally, a Thumbnail ad stays visible while the user navigates between the activities of your application. It is displayed in an activity only if the first two packages of its class name match the first two packages of the class name of the activity specified in the show() method. For details on how to customize these default settings using whitelists and blacklists, please see the Customizing Thumbnail ad display section.

if (thumbnailAd.isLoaded()) {
    // The ad is loaded and ready to be displayed.
    thumbnailAd.show(activity)
} else {
    // The ad is not loaded yet. Handle this situation appropriately.
}

The show method takes the following parameter:

  • activity: a reference to the Activity in which you want to display the Thumbnail ad.

Advanced Topics

Customizing Thumbnail ad size

In order to control the thumbnail size, set the size when initializing the OguryThumbnailAdForGam object with maxWidth and maxHeight parameters before calling load method

thumbnailAd = new OguryThumbnailAdForGam(this, "YOUR_GAM_UNIT_ID", maxWidth, maxHeight);

maxWidth and maxHeight parameters define the maximum size that the Thumbnail Ad will take on the screen. Both values are in dp.

We recommend to use maxWidth = 200 and maxHeight = 200 to improve the readability of the content of the Thumbnail Ad.

Example: when given maxWidth= 200 and maxHeight= 200, the Ogury SDK may decide to display a 16:9 video ad inside. In this case the Thumbnail Ad size will be 180x113dp to match the ratio of the 16:9 video.

The following constraints apply on the values you can pass to these parameters:

  • maxWidth and maxHeight must not be greater than the size of the screen.

  • maxWidthandmaxHeight must be greater than or equal to 101dp.

  • longest side, either maxWidth or maxHeight, must be greater than or equal to

    180dp.

Customizing Thumbnail ad position

To specify the position of a Thumbnail ad, invoke the setPosition() method with parameters: OguryThumbnailGravity, xMargin and yMargin.

thumbnailAd.setPosition(gravity, xMargin, yMargin)

The setPosition method takes the following parameters:

  • gravity : the corner from which the Thumbnail ad will be positioned. The OguryThumbnailGravityenum includes the following values:

    • TOP_LEFT

    • TOP_RIGHT

    • BOTTOM_LEFT

    • BOTTOM_RIGHT

  • xMargin: the horizontal distance from the x-axis to the Thumbnail ad, expressed in dp.

  • yMargin: the vertical distance from the y-axis to the Thumbnail ad, expressed in dp.

Customizing Thumbnail ad display

Customizing in which activities Thumbnail Ad is displayed

Thumbnail Ad remains on screen while the user navigates across the activities of your application.

By default, a Thumbnail Ad is displayed in an Activity only if the two first packages of its classname match the two first packages of the classname of the Activity passed as parameter to the show method.

Example: If you pass com.ogury.game.GameActivity as parameter of the show method, the Thumbnail Ad will stay on screen in all the activities in the com.ogury package and all packages at any level under it.

You can override these default settings using whitelists and blacklists.

Whitelist packages:

You can increase the number of whitelisted packages where Thumbnail Ads are displayed and stay on screen. This can be useful if you have Activity provided by a library like a game engine, in this case you need to whitelist the package associated to this library.

Call the setWhiteListPackages method to whitelist packages:

thumbnailAd.setWhiteListPackages("org.games.ui", "com.settings.activities");

Blacklist activities:

You can prevent Thumbnail Ads from being displayed on a given Activity by using the setBlackListActivities method:

thumbnailAd.setBlackListActivities(
    TermsAndConditionsActivity.class, 
    SettingsActivity.class);

The method logWhiteListedActivities can be used to display all whitelisted activities. It should be called only after setting the whitelist and blacklist.

thumbnailAd.logWhiteListedActivities(true)

After calling the method logWhiteListedActivities, connect your device to Android studio and filter the logs by OGURY tag. You will see logs that start with Whitelisted:, for example Whitelisted: com.ogury.HomeActivity

Customizing in which fragments Thumbnail Ad is displayed

In case the application is based mostly on fragments and there are fragments in which the thumbnail ad should not be displayed, a filtering on fragments instead of activities can be done. In order to change the filtering from activities to fragments, setBlackListFragments or setWhiteListFragmentPackages must be called.

By default, a Thumbnail Ad is displayed in a Fragment only if the two first packages of its classname matches the two first packages of the classname of the Activity passed as parameter to the show method.

Example: If you pass com.ogury.game.GameFragmentActivity as parameter of the show method, the Thumbnail Ad will stay on screen as long as a fragment is visible to the user and is part ofcom.ogury package and all packages at any level under it.

You can override these default settings using whitelists and blacklists.

Whitelist packages:

You can increase the number of whitelisted packages where Thumbnail Ads are displayed and stay on screen. This can be useful if you have a Fragment provided by a library like a game engine, in this case you need to whitelist the package associated to this library.

Call the setWhiteListFragmentPackages method to whitelist packages:

thumbnailAd.setWhiteListFragmentPackages("org.games.ui", "com.settings.fragments");

Blacklist fragments:

You can prevent Thumbnail Ads from being displayed on a given Fragment by using the setBlackListFragments method:

thumbnailAd.setBlackListFragments(
    BannerAdsFragment.class, 
    SettingsFragment.class);

Error handling

If you are unable to load or display any Thumbnail ads, we recommend logging callbacks from the OguryThumbnailAdListener to monitor the ad's lifecycle, especially the onAdError callback. This method provides an OguryAdError instance containing important error details:

  • type: indicates the error type through the OguryAdError.Type enum, which distinguishes between loading errors (Load) and showing errors (Show).

  • code: An integer that identifies the specific error. Errors that can occur during ad loading or displaying are defined in the OguryLoadErrorCode and OguryShowErrorCode classes. Detailed explanations of these error codes are provided in the tables below to assist you in troubleshooting effectively.

  • message: A descriptive message that provides additional context about the error.

You can utilize these details to diagnose the issue and take appropriate action to resolve it.

Last updated

Was this helpful?