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.+.
In the new API, the Ogury.start() must be called before you use any Ogury's functionalities including the Ogury Choice Manager.
Collect the consent
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
publicclassMyActivityextendsActivity { @OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);OguryChoiceManager.initialize(context,"OGY-XXXXXXXXXXXX",newOguryCmConfig());OguryChoiceManager.ask(this, oguryConsentListener); }privatefinalOguryConsentListener oguryConsentListener =newOguryConsentListener() { @OverridepublicvoidonComplete(OguryChoiceManager.Answer answer) {Presage.getInstance().start("OGY-XXXXXXXXXXXX",this);// ... and load Ogury ad formats } @OverridepublicvoidonError(OguryError error) {Presage.getInstance().start("OGY-XXXXXXXXXXXX",this);// ... and load Ogury ad formats } };}
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:
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.
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.
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.
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.