Migration guide

From October 2020, Ogury released a new API specially refactored to improve the onboarding experience. In this guide, you will learn how to switch from the old API to the new one.

Import the Ogury SDK

In order to import the last version of the new Ogury SDK, you must update the Ogury's dependency in the build.gradle of your application. Now, you have to request the 5.+ version instead of the 4.+.

dependencies {
    implementation 'co.ogury:ogury-sdk:5.+'
}

Initialize the Ogury SDK

The way to initialize the Ogury SDK is a bit different. Replace the old API by the new one:

Old API

Presage.getInstance().start("OGY-XXXXXXXXXXXX", context);

New API

OguryConfiguration.Builder oguryConfigurationBuilder = new OguryConfiguration.Builder(context, "OGY-XXXXXXXXXXXX");
Ogury.start(oguryConfigurationBuilder.build());

In the new API, the Ogury.start() must be called before you use any Ogury's functionalities including the Ogury Choice Manager.

If you use the Ogury Choice Manager, you no longer have to initialize the Ogury's SDK in the OguryConsentListener callbacks. It must be initialized before calling the ask and edit method:

Old API

public class MyActivity extends Activity {

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        OguryChoiceManager.initialize(context, "OGY-XXXXXXXXXXXX", new OguryCmConfig());
        OguryChoiceManager.ask(this, oguryConsentListener);
    }
    
    private final OguryConsentListener oguryConsentListener = new OguryConsentListener() {
        @Override public void onComplete(OguryChoiceManager.Answer answer) {
            Presage.getInstance().start("OGY-XXXXXXXXXXXX", this);
            // ... and load Ogury ad formats
        }
        @Override public void onError(OguryError error) {
            Presage.getInstance().start("OGY-XXXXXXXXXXXX", this);
            // ... and load Ogury ad formats
        }
    };
}

New API

public class MyActivity extends Activity {

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        OguryConfiguration.Builder oguryConfigurationBuilder = new OguryConfiguration.Builder(this, "OGY-XXXXXXXXXXXX");
        Ogury.start(oguryConfigurationBuilder.build());
        
        OguryChoiceManager.ask(this, oguryConsentListener);
        
        // ... and load Ogury ad formats
    }
    
    private final OguryConsentListener oguryConsentListener = new OguryConsentListener() {
        @Override public void onComplete(OguryChoiceManager.Answer answer) {
            // ...
        }
        @Override public void onError(OguryError error) {
            // ...
        }
    };
    
}

Note the OguryChoiceManager.initialize() method is not required anymore. It is replaced by the Ogury.start().

The Ogury Choice Manager and the Ogury ad formats are synchronized. So you can start loading the ads while requesting user consent. You do not need to wait for the user response. Indeed, the ad will be loaded once the user's consent response is obtained. Just pay attention to call ask method before loading ads.

If you were still using the deprecated API of the Ogury Choice Manager, note the API has changed a bit:

Deprecated API

ConsentListener consentListener = new ConsentListener() {
    @Override public void onComplete(ConsentManager.Answer answer) {
        // ...
    }
    @Override public void onError(ConsentException e) {
        // ...
    }
};
ConsentManager.ask(this, "OGY-XXXXXXXXXXXX" consentListener);

New API

OguryConsentListener oguryConsentListener = new OguryConsentListener() {
    @Override public void onComplete(OguryChoiceManager.Answer answer) {
        // ...
    }
    @Override public void onError(OguryError error) {
        // ...
    }
};
OguryChoiceManager.ask(this, oguryConsentListener);

Integrate Ogury ad formats

The way Ogury ads are loaded and displayed has not really changed. Ogury has just refactored a little bit the API in order to have a more consistent and smother API. Let's take a look at the changes, format by format.

Interstitial Ad

API changes

The PresageInsterstitial object becomes OguryInterstitialAd. Now, the constructor takes a Context and an ad unit string as parameters instead of an Activity and an AdConfig object.

The method used to register a listener on the lifecycle of the Interstitial ad is now setListener instead of setInterstitialCallback and takes a OguryInterstitialAdListener object as parameters instead of a PresageInterstitialCallback.

ThePresageInsterstitialCallback object becomes OguryInsterstitialAdListener and the methods to implement is now:

Methods

Definition

onAdLoaded

The SDK is ready to display the ad provided by the ad server.

onAdDisplayed

The ad has been displayed on the screen.

onAdClicked

The as has been clicked by the user.

onAdClosed

The ad has been closed by the user.

onAdError

The ad failed to load or display.

The onAdAvailable, onAdNotAvailable, onAdNotLoaded methods have been removed. The onAdNotAvailable, onAdNotLoaded callbacks are now replaced by the onAdError callback.

Now, the onAdError callback provides an OguryError object instead of an error code integer. The OguryError parameter contains the reason of the failure.

In practice

Old API

AdConfig config = new AdConfig("YOUR_AD_UNIT_ID");
final PresageInterstitial interstitial = new PresageInterstitial(activity, config);
interstitial.setInterstitialCallback(new PresageInterstitialCallback() {

    @Override public void onAdNotLoaded () { 
        // ... 
    }

    @Override public void onAdLoaded () {
        interstitial.show();
    }

    @Override public void onAdNotAvailable () {
        // ... 
    }

    @Override public void onAdAvailable () {
        // ... 
    }

    @Override public void onAdError (int errorCode) {
        Log.w("Ogury", "An error occured (code: " + errorCode + ")");
        // ... 
    }

    @Override public void onAdClosed () {
        // ... 
    }

    @Override public void onAdDisplayed () { 
        // ...
    }
});
interstitial.load();

New API

final OguryInterstitialAd interstitial = new OguryInterstitialAd(context, "YOUR_AD_UNIT_ID");
interstitial.setListener(new OguryInterstitialAdListener() {

    @Override public void onAdLoaded () {
        interstitial.show();
    }

    @Override public void onAdDisplayed () { 
        // ...
    }
    
    @Override public void onAdClicked () {
        // ... 
    }
    
    @Override public void onAdClosed () {
        // ... 
    }

    @Override public void onAdError (OguryError oguryError) {
        Log.w("Ogury", "An error occured (code: " + oguryError.getErrorCode()
            + " ; message: " + oguryError.getMessage() + ")");
    }
});
interstitial.load();

Opt-in Video Ad

API changes

The PresageOptinVideo object becomes OguryOptinVideoAd. Now, the constructor takes a Context and an ad unit string as parameters instead of an Activity and an AdConfig object.

The method used to register a listener on the lifecycle of the opt-in video ad is now setListener instead of setOptinVideoCallback and takes a OguryOptinVideoAdListener object as parameters instead of a PresageOptinVideoCallback.

ThePresageOptinVideoCallback object becomes OguryOptinVideoAdListener and the methods to implement is now:

Methods

Definition

onAdLoaded

The SDK is ready to display the ad provided by the ad server.

onAdDisplayed

The ad has been displayed on the screen.

onAdClicked

The as has been clicked by the user.

onAdRewarded

The user must be rewarded, as they has watched the Opt-in Video Ad.

onAdClosed

The ad has been closed by the user.

onAdError

The ad failed to load or display.

The onAdAvailable, onAdNotAvailable, onAdNotLoaded methods have been removed. The onAdNotAvailable, onAdNotLoaded callbacks are now replaced by the onAdError callback.

Now, the onAdError callback provides an OguryError object instead of an error code integer. The OguryError parameter contains the reason of the failure.

The RewardItem object provided in the onAdRewarded callback is now replaced by an OguryReward object.

In practice

Old API

AdConfig config = new AdConfig("YOUR_AD_UNIT_ID");
final PresageOptinVideo optinVideo = new PresageInterstitial(activity, config);
optinVideo.setOptinVideoCallback(new PresageOptinVideoCallback() {

    @Override public void onAdRewarded(RewardItem rewardItem) {
        Log.d("Ogury", "User has received reward '" + rewardItem.getName()
            + "' with value: " + rewardItem.getValue());
    }

    @Override public void onAdNotLoaded () { 
        // ... 
    }

    @Override public void onAdLoaded () {
        optinVideo.show();
    }

    @Override public void onAdNotAvailable () {
        // ... 
    }

    @Override public void onAdAvailable () {
        // ... 
    }

    @Override public void onAdError (int errorCode) {
        Log.w("Ogury", "An error occured (code: " + errorCode + ")");
    }

    @Override public void onAdClosed () {
        // ... 
    }

    @Override public void onAdDisplayed () { 
        // ...
    }
});
optinVideo.load();

New API

final OguryOptinVideoAd optinVideo = new OguryOptinVideoAd(context, "YOUR_AD_UNIT_ID");
optinVideo.setListener(new OguryOptinVideoAdListener() {

    @Override public void onAdLoaded () {
        optinVideo.show();
    }

    @Override public void onAdDisplayed () { 
        // ...
    }
    
    @Override public void onAdClicked () {
        // ... 
    }
    
    @Override public void onAdRewarded(OguryReward oguryReward) {
        Log.d("Ogury", "User has received reward '" + oguryReward.getName() 
            + "' with value: " + oguryReward.getValue());
    }
    
    @Override public void onAdClosed () {
        // ... 
    }

    @Override public void onAdError (OguryError oguryError) {
        Log.w("Ogury", "An error occured (code: " + oguryError.getErrorCode()
            + " ; message: " + oguryError.getMessage() + ")");
    }
});
optinVideo.load();

The method used to register a listener on the lifecycle of the banner ad is now setListener instead of setCallback and takes a OguryBannerAdListener object as parameters instead of a OguryBannerCallback.

The OguryBannerCallback object becomes OguryBannerAdListener and the methods to implement is now:

Methods

Definition

onAdLoaded

The SDK is ready to display the ad provided by the ad server.

onAdDisplayed

The ad has been displayed on the screen.

onAdClicked

The as has been clicked by the user.

onAdClosed

The ad has been closed by the user.

onAdError

The ad failed to load or display.

The onAdAvailable, onAdNotAvailable, onAdNotLoaded methods have been removed. The onAdNotAvailable, onAdNotLoaded callbacks are now replaced by the onAdError callback.

Now, the onAdError callback provides an OguryError object instead of an error code integer. The OguryError parameter contains the reason of the failure.

In practice

inal OguryBannerAdView banner = new OguryBannerAdView(context);
banner.setAdUnit("YOUR_AD_UNIT_ID");
banner.setAdSize(OguryBannerAdSize.SMALL_BANNER);
banner.setCallback(new OguryBannerCallback() {

    @Override public void onAdAvailable() {
        // ...
    }

    @Override
    public void onAdNotAvailable() {
        // ...
    }

    @Override
    public void onAdLoaded() {
        bannerContainer.add(banner);
    }

    @Override
    public void onAdNotLoaded() {
        // ...
    }

    @Override
    public void onAdDisplayed() {
        // ...
    }

    @Override
    public void onAdClicked() {
        // ...
    }

    @Override
    public void onAdClosed() {
        // ...
    }

    @Override
    public void onAdError(int errorCode) {
        Log.w("Ogury", "An error occured (code: " + errorCode+ ")");
    }

});
banner.loadAd();

New API

final OguryBannerAdView banner = new OguryBannerAdView(context);
banner.setAdUnit("YOUR_AD_UNIT_ID");
banner.setAdSize(OguryBannerAdSize.SMALL_BANNER);
banner.setListener(new OguryInterstitialAdListener() {

    @Override public void onAdLoaded () {
        bannerContainer.add(banner);
    }

    @Override public void onAdDisplayed () { 
        // ...
    }
    
    @Override public void onAdClicked () {
        // ... 
    }
    
    @Override public void onAdClosed () {
        // ... 
    }

    @Override public void onAdError (OguryError oguryError) {
        Log.w("Ogury", "An error occured (code: " + oguryError.getErrorCode()
            + " ; message: " + oguryError.getMessage() + ")");
    }
});
banner.loadAd();

Thumbnail Ad

The constructor takes no longer take an Activity and an AdConfig object as parameters. Now, it takes aContext and an ad unit string.

The method used to register a listener on the lifecycle of the thumbnail ad is now setListener instead of setCallback and takes a OguryThumbnailAdListener object as parameters instead of a OguryThumbnailAdCallback.

the OguryThumbnailAdCallback object becomes OguryThumbnailAdListener and the methods to implement is now:

Methods

Definition

onAdLoaded

The SDK is ready to display the ad provided by the ad server.

onAdDisplayed

The ad has been displayed on the screen.

onAdClicked

The as has been clicked by the user.

onAdClosed

The ad has been closed by the user.

onAdError

The ad failed to load or display.

The onAdAvailable, onAdNotAvailable, onAdNotLoaded methods have been removed. The onAdNotAvailable, onAdNotLoaded callbacks are now replaced by the onAdError callback.

Now, the onAdError callback provides an OguryError object instead of an error code integer. The OguryError parameter contains the reason of the failure.

In practice

Old API

AdConfig config = new AdConfig("YOUR_AD_UNIT_ID");
final OguryThumbnailAd thumbnail = new OguryThumbnailAd(activity, config);
thumbnail.setCallback(new OguryThumbnailAdCallback() {

    @Override public void onAdAvailable() {
        // ...
    }

    @Override public void onAdNotAvailable() {
        // ...
    }

    @Override public void onAdLoaded() {
        thumbnail.show(activity);
    }

    @Override public void onAdNotLoaded() {
        // ...
    }

    @Override public void onAdDisplayed() {
        // ...
    }

    @Override public void onAdClosed() {
        // ...
    }

    @Override public void onAdError(int errorCode) {
        Log.w("Ogury", "An error occured (code: " + errorCode + ")");
    }
});
thumbnail.load();

New API

final OguryThumbnailAd thumbnail = new OguryThumbnailAd(context, "YOUR_AD_UNIT_ID");
thumbnail.setListener(new OguryThumbnailAdListener() {

    @Override public void onAdLoaded () {
        thumbnail.show(activity);
    }

    @Override public void onAdDisplayed () { 
        // ...
    }
    
    @Override public void onAdClicked () {
        // ... 
    }
    
    @Override public void onAdClosed () {
        // ... 
    }

    @Override public void onAdError (OguryError oguryError) {
        Log.w("Ogury", "An error occured (code: " + oguryError.getErrorCode()
            + " ; message: " + oguryError.getMessage() + ")");
    }
});
thumbnail.load();

Last updated