Sample project with example integration can be downloaded from: https://github.com/Nefta-io/suite-for-unity:

Requirements

Unity 2019.f.40 or higher

Supported platforms

  • Android minimal version 4.1 (API level 16) or higher
  • iOS 11 or higher
  • Standalone Windows/Mac for development in Editor

Include the SDK

First download the latest package from: https://github.com/Nefta-io/suite-for-unity/releases and import it into your project through Menu > Assets > Import Package > Custom Package... and select the

Confirm the import of all the files in the package:

Configuration

By default, the SDK runs in demo mode serving you testing placements. In order to serve the right ad units you've configured on the platform enter your application id in the NeftaConfiguration scriptable object:

Note that if you provide null or empty string as the application id, the SDK will run in demo mode; it will show testing ads, in case you want to test the technical client part, without configuring the backend.

Code integration

// Init the SDK
NAds = NAds.Init();

With this, you can start bidding, showing, and earning with Nefta ads.

Troubleshooting

On iOS frameworks should be already configured okay out of the box, but in case you have any issues with them, make sure that you are including the correct SDK based on your target, so either the arm one or the simulator x64 one:

So that you have only one NeftaSDK in xcode project that is Embeded & Sign:

Single Ad SDK

In case Nefta Ad SDK is the only advertising SDK you will probably want to have simple integration, similar to the one in the Demo sample. Where you call to load an ad placement and when it's ready you display it when you want:

Simple integration

Multiple Ad SDKs with logic control

In case you have multiple Ad SDKs you will probably want to have some logic to control which SDK offers the ad with the highest bid price. Two of the most common implementations are waterfall (sequential Ad Requests) and header bidding (Simultaneous Ad Requests).

Given the following abstract Ad provider SDK:

public interface IAdProvider
{
	public interface IAdUnit
	{
		float GetPrice();
	}

	void AddOnLoadCompleteListener(Action<IAdUnit> listener);

	void Load();

	void Show();
}

Waterfall

public void LoadAndShowTheBestAdThroughWaterfall()
{
  foreach (var adProvider in _integratedAdProviders)
  {
    _providerWaterfall.Enqueue(adProvider);
  }
  RequestAdFromNextProvider();
}

private void RequestAdFromNextProvider()
{
  if (_providerWaterfall.TryDequeue(out var nextProvider))
  {
    nextProvider.Load(); // we still have more providers to check
    return;
  }

  // all providers have been checked, let's show the ad with highest bid
  ShowBestLoadedAd();
}

private void OnLoadComplete(IAdProvider adProvider, IAdProvider.IAdUnit adUnit)
{
  _loadedAdPerSdk[adProvider] = adUnit;

  RequestAdFromNextProvider();
}

private void ShowBestLoadedAd()
{
  // all providers have been checked, let's show the ad with highest bid
  KeyValuePair<IAdProvider, IAdProvider.IAdUnit> bestProviderAd = new KeyValuePair<IAdProvider, IAdProvider.IAdUnit>(null, null);
  foreach (var providerAd in _loadedAdPerSdk)
  {
    if (bestProviderAd.Value == null || bestProviderAd.Value.GetPrice() < providerAd.Value.GetPrice())
    {
      bestProviderAd = providerAd;
    }
  }
  _loadedAdPerSdk.Clear();
  bestProviderAd.Key.Show();
}

Header bidding

public void LoadAndShowTheBestAdThroughHeaderBidding()
{
  _providersToHeadBid.AddRange(_integratedAdProviders);
  foreach (var adProvider in _providersToHeadBid)
  {
    adProvider.Load();
  }
}

private void RequestAdFromNextProvider()
{
  if (_providerWaterfall.TryDequeue(out var nextProvider))
  {
    nextProvider.Load(); // we still have more providers to check
    return;
  }
}

private void OnLoadComplete(IAdProvider adProvider, IAdProvider.IAdUnit adUnit)
{
  _loadedAdPerSdk[adProvider] = adUnit;
  _providersToHeadBid.Remove(adProvider);

  // if we already received response from all ad providers
  if (_providersToHeadBid.Count == 0)
  {
    ShowBestLoadedAd();
  }
}

private void ShowBestLoadedAd()
{
  // all providers have been checked, let's show the ad with highest bid
  KeyValuePair<IAdProvider, IAdProvider.IAdUnit> bestProviderAd = new KeyValuePair<IAdProvider, IAdProvider.IAdUnit>(null, null);
  foreach (var providerAd in _loadedAdPerSdk)
  {
    if (bestProviderAd.Value == null || bestProviderAd.Value.GetPrice() < providerAd.Value.GetPrice())
    {
      bestProviderAd = providerAd;
    }
  }
  _loadedAdPerSdk.Clear();
  bestProviderAd.Key.Show();
}

We recommend going with the header bidding approach as the bid price can fluctuate whilst we are waiting for the providers in the waterfall to respond one by one. This delay leads to making less optimal decisions.


Features of the Nefta Ad SDK:

  • Small footprint,
  • Quite performant (CPU & memory wise), and customizable,
  • If for whatever reason our SDK or our service were to fail, there would be no impact to the app.
  • Compatible both with Header Bidding and Waterfall.

After integration:

  • Ensure the app has integrated the "Game Events": Nefta Game Events
  • Setup your Ad Units in the Nefta platform.