Other Features

SDK Global Behaviour

When you start the SDK you get a Settings object that you can use to configure Fyber SDK global behaviour.

Settings settings = Fyber.With(appId)
            .Start();

You can use this object to add parameters to requests throughout Fyber products, change user messages and Offer Wall behaviour:

settings.NotifyUserOnCompletion(false)
	// add a list of custom params to all requests
	.AddParameter("paramKey","paramValue")
	// add a custom param to all requests
	.AddParameters(paramDictionary)
	// don't show notification when the user finishes watching a video
	.NotifyUserOnReward(false)
	// don't show notification when the user is rewarded
	.NotifyUserOnReward(false)
	// don't close the offer wall when the user is redirected to an offer
	.CloseOfferWallOnRedirect(false)
	// to change the userId after starting the sdk
	.UpdateUserId("userId")
	// to get userId as string. This method returns a string instead of Settings.
	string userId = settings.GetUserId();

All these configurations can be overriden on a request by request basis. See each product page to learn more about how to do this.

Pre-caching

Pre-caching is enabled by default. You can change this behaviour by chaining the WithManualPrecaching() method when starting the SDK:

Fyber.With(appId)
    .WithManualPrecaching()
    .Start();

To start, pause and resume pre-caching use the follwoing methods:

CacheManager.StartPrecaching();
CacheManager.PauseDownloads();
CacheManager.ResumeDownloads();

Learn more about pre-caching on the Rewarded Video page

Logs

You can enable logs on the SDK by calling the following method:

FyberLogger.EnableLogging(true);

Callbacks

RequestCallback

Throughout our documentation we use delegates as the default way to get the response value for each of Fyber products requests. However, starting on Unity Plugin 8.0.0 you can use RequestCallbacks that you chain to your request code:

Ad videoAd;
Ad interstitialAd;
Ad ofwAd;

GlobaRequestCallback requestCallback = new GlobaRequestCallback();
// [...]

private class GlobaRequestCallback : RequestCallback
{
    public void OnAdAvailable(Ad ad)
    {
	    switch(ad.AdFormat)
	    {
	        case AdFormat.REWARDED_VIDEO:
	            videoAd = ad;
	            break;
	        case AdFormat.INTERSTITIAL:
	            interstitialAd = ad;
	            break;
	        case AdFormat.OFFER_WALL:
	            ofwAd = ad;
	            break;
	        default:
	            break;
	        }
	    }

    public void OnAdNotAvailable(AdFormat adFormat)
    {
        switch(adFormat)
	    {
	        case AdFormat.REWARDED_VIDEO:
	            videoAd = null;
	            break;
	        case AdFormat.INTERSTITIAL:
	            interstitialAd = null;
	            break;
	        case AdFormat.OFFER_WALL:
	            ofwAd = null;
	            break;
	        default:
	            break;
	    }
    }

    public void OnRequestError(RequestError error)
    {
        UnityEngine.Debug.Log("OnRequestError: " + error.Description);
    }
}

If you implement a RequestCallback similar to the one above you can then use the same callback for all product requests without having to set delegates e.g.:

OfferWallRequester.Create()
    .WithCallback(requestCallback)
    .Request();
RewardedVideoRequester.Create()
    .WithCallback(requestCallback)
    .Request();
VirtualCurrencyRequester.Create()
    .WithCallback(requestCallback)
    .Request();

Of course you can also provide a custom RequestCallback for each product if that suits your application better.

AdCallback

You can also define callbacks for Ads:

private class GlobalAdCallback : AdCallback
{
    public void OnAdStarted(Ad ad)
    {
        // this is where you mute the sound and toggle buttons if necessary
        UnityEngine.Debug.Log("OnAdStarted. Ad " + ad.AdFormat +
                            " with placementId: " + ad.PlacementId + 
                            " has started");
    }  
    
    public void OnAdFinished(AdResult result)
    {
        // this is the place where you can resume the sound
        // reenable buttons, etc
        UnityEngine.Debug.Log("OnAdFinished. Ad " + result.AdFormat +
                            " finished with status: " + result.Status +
                            " and message: " + result.Message);
    }   
}

Using this callback would look like this:

Ad ofwAd;
Ad videoAd;
Ad interstitialAd;

GlobalAdCallback adCallback = new GlobalAdCallback();
// [...]
void ShowOfw()
{
	if (ofwAd != null)
	{
		ofwAd.WithCallback(adCallback)
			.Start();
		ofwAd = null;	
	}		
}

void ShowVideo()
{
	if (videoAd != null)
	{
		videoAd.WithCallback(adCallback)
			.Start();
		videoAd = null;	
	}		
}

void ShowInterstitial()
{
	if (interstitialAd != null)
	{
		interstitialAd.WithCallback(adCallback)
			.Start();
		interstitialAd = null;	
	}		
}	

VirtualCurrencyCallback

The same applies for virtual currency:

private class CustomVirtualCurrencyCallback : VirtualCurrencyCallback
{
    public void OnRequestError(RequestError error)
    {
        UnityEngine.Debug.Log("OnRequestError: " + error.Description);
    }

    public void OnError(VirtualCurrencyErrorResponse vcsError)
    {
        UnityEngine.Debug.Log(String.Format("Delta of coins request failed.\n" +
                        "Error Type: {0}\nError Code: {1}\nError Message: {2}",
                        vcsError.Type, vcsError.Code, vcsError.Message);
    }

    public void OnSuccess(VirtualCurrencyResponse response)
    {
        UnityEngine.Debug.Log("virtual currency response success. Delta of coins received: " + response.DeltaOfCoins);
    }
}

You would then chain this to a VirtualCurrencyRequester request:


CustomVirtualCurrencyCallback customCurrencyCallback = new CustomVirtualCurrencyCallback();
// [...]

void RequestCurrency()
{
	VirtualCurrencyRequester requestCallback  = VirtualCurrencyRequester.Create()
	    // optional method chaining 
	    //.AddParameter("key", "value")
	    //.AddParameters(dictionary)
	    // vcs specific methods
	    //.ForCurrencyId(currencyId)
	    //.NotifyUserOnReward(true)
	    // adding a custom vcs callback to the vcs request
	    .WithCallback(customCurrencyCallback)
	    .request();
}