Integrating the Offer Wall

Read through the process of requesting and displaying the Fyber Offer Wall to users in your app here. Before following this, you should have already completed Getting started with the Fyber Unity Plugin.

[Requesting the Offer Wall](#requesting-the-offer-wall)
[Handling Errors](#handling-errors)
[Displaying the Offer Wall](#displaying-the-offer-wall)
[Offer Wall Result](#offer-wall-result)
[Configuring the Offer Wall](#configuring-the-offer-wall)
## Requesting the Offer Wall Before displaying the `Offer Wall` you'll have to request it. To do so: 1. Make sure you've initialized the SDK previously as described in [Getting started with Fyber SDK](/content/current/unity/integration/getting-started/). 1. Set up a delegate to listen to `Offer Wall` requests using this snippet: ```csharp void OnEnable() { // Ad availability FyberCallback.AdAvailable += OnAdAvailable; } void OnDisable() { // Ad availability FyberCallback.AdAvailable -= OnAdAvailable; } // [...] Ad ofwAd; // [...] private void OnAdAvailable(Ad ad) { switch(ad.AdFormat) { case AdFormat.OFFER_WALL: ofwAd = ad; break; //handle other ad formats if needed } } ``` 1. Use the following code snippet to request the `Offer Wall`: ```csharp OfferWallRequester.Create() // optional method chaining //.AddParameter("key", "value") //.AddParameters(dictionary) //.WithPlacementId(placementId) // configure ofw behaviour: //.CloseOnRedirect(true) // you don't need to add a callback if you are using delegates //.WithCallback(requestCallback) //requesting the ad .Request(); ``` ## Handling Errors You won't always get a successful response. To handle these scenarios you'll have to set up these delegate methods: ```csharp void OnEnable() { FyberCallback.AdNotAvailable += OnAdNotAvailable; FyberCallback.RequestFail += OnRequestFail; } void Disable() { FyberCallback.AdNotAvailable -= OnAdNotAvailable; FyberCallback.RequestFail -= OnRequestFail; } private void OnAdNotAvailable(AdFormat adFormat) { switch(adFormat) { case AdFormat.OFFER_WALL: ofwAd = null; break; // handle other ad formats if needed } } private void OnRequestFail(RequestError error) { // process error UnityEngine.Debug.Log("OnRequestError: " + error.Description); } ``` `error` can have one of these values: | RequestError | Description | --- | ---- |DEVICE_NOT_SUPPORTED | Only devices running Android API level 10 and above are supported. |CONNECTION_ERROR | Internet connection error. |UNKNOWN_ERROR | An unknown error occurred. |SDK_NOT_STARTED | You need to start the SDK. |NULL_CONTEXT_REFERENCE | Context reference cannot be null. |SECURITY_TOKEN_NOT_PROVIDED | The security token was not provided when starting the SDK. |ERROR_REQUESTING_ADS | An error happened while trying to retrieve ads |UNABLE_TO_REQUEST_ADS | The SDK is unable to request right now because it is either already performing a request or showing an ad. ## Displaying the Offer Wall Once you've received an `Offer Wall` `Ad` you can display it like so: ```csharp Ad ofw; //[...] public void ShowOfferWall() { if (ofwAd != null) { ofwAd.Start(); ofwAd = null; } } ``` ## Offer Wall Result You may want to be notified when the `Offer Wall` is started and closed. To do so you'll have to add these extra delegates: ```csharp void OnEnable() { FyberCallback.AdStarted += OnAdStarted; FyberCallback.AdFinished += OnAdFinished; } void OnDisable() { FyberCallback.AdStarted -= OnAdStarted; FyberCallback.AdFinished -= OnAdFinished; } private void OnAdStarted(Ad ad) { // this is where you mute the sound and toggle buttons if necessary switch (ad.AdFormat) { case AdFormat.OFFER_WALL: ofwAd = null; break; //handle other ad formats if needed } } private void OnAdFinished(AdResult result) { switch (result.AdFormat) { case AdFormat.OFFER_WALL: UnityEngine.Debug.Log("Ofw closed with result: " + result.Status + "and message: " + result.Message); break; // handle other ad formats if needed } } ``` ## Configuring the Offer Wall ### Offer Wall Behavior If you want the `Offer Wall` to be automatically dismissed after the user is redirected to an offer you can chain the `CloseOnRedirect` method to your `Offer Wall` request: ```csharp OfferWallRequester.Create() .CloseOnRedirect(true) .Request(); ``` Otherwise, the Offer Wall will remain open when the user comes back to the application. ### Custom Parameters You can pass along custom parameters (e.g. pub0, pub1, …) with the request by chaining the `AddParameter` method to your request as follows: ```csharp OfferWallRequester.Create() .AddParameter("pub0", "pub1") .Request(); ```