Rewarded Ads SDK for Unity

With the now.gg Rewarded Ads SDK plugin for Unity, you can implement in-app rewarded ads within your game on Unity.

To implement rewarded ads:

  1. Download and Import the now.gg Rewarded Ads SDK Unity plugin.
  2. Add required dependencies.
  3. Implement now.gg Rewarded Ads SDK to your project.

Download and Import the Plugin

The now.gg Rewarded Ads SDK Unity plugin is included as a Unity package file (NowGGRewardsSdk.unitypackage).

Add the plugin to your Unity project:

  1. Download the package containing the latest version of now.gg Rewarded Ads SDK Plugin for Unity.
  2. After you have downloaded the plugin, import it to your project.
    To do this:

    • Click on Assets > Import Package > Custom Package, as shown below:
    • Select NowGGRewardsSdk.unitypackage that you previously downloaded.
    • Select all the listed files and click on Import.

Once all the plugin files have been imported, a folder named ‘NowGGRewardsSdk‘ will be added to your project. You can find this folder at the root of the Assets folder.

Note: Please do not modify the NowGGRewardsSdk folder, as that contains all the assets related to now.gg Rewarded Ads SDK.

Add Required Dependencies

This operation will download and add all the required dependencies to the Assets/Plugins/Android directory of your project using the Unity External Dependency Manager.

To add the required dependencies:

  • Click on Assets > External Dependency Manager > Android Resolver > Resolve.

Implement now.gg Rewarded Ads SDK

The following sections illustrate the implementation of the now.gg Rewarded Ads SDK functions which you can call from your app/game in Unity.

Once the now.gg Rewarded Ads SDK Plugin has been imported, and the dependencies have been added; you can now integrate your app/game with now.gg Rewarded Ads SDK.

1. Initialize the SDK

Before your app can show the ads, you must initialize the SDK.

Start by creating a class that contains the now.gg Rewarded Ads implementation and attach it to a game object that you can use to initialize the SDK, as illustrated below:

void Start()
   {
       NowGGRewardsSdkManager.Instance.OnInitSuccess += OnInitSuccess;
       NowGGRewardsSdkManager.Instance.OnInitFailed += OnInitFailed;
       NowGGRewardsSdkManager.Instance.OnAdDismissed += OnAdDismissed;
       NowGGRewardsSdkManager.Instance.OnAdFailedToLoad += OnAdFailedToLoad;
       NowGGRewardsSdkManager.Instance.OnAdShownToUser += OnAdShownToUser;
       NowGGRewardsSdkManager.Instance.OnUserEarnedReward += OnUserEarnedReward;
      
       NowGGRewardsSdkManager.Instance.Initialize();
   }

Note:

  • You should initialize the SDK only once, ideally at app launch.
  • Initialize() function of the NowGGRewardsSdkManager class is called to initialize the Rewarded Ads SDK.
  • The SDK responses are recorded using the callback functions, as illustrated above.

2. Show Rewarded Ads

Once the SDK has been successfully initialized, you can now show the in-app rewarded ads.

Based on your requirement, you can display rewarded ads in your app by calling the NowGGRewardsSdkManager.Instance.ShowAd() function.

now.gg Rewarded Ads SDK utilizes the following callback functions to inform your app about the status of the rewarded ad request:

  • void OnAdShownToUser(); – Ad is displayed on the user’s screen.
  • void OnAdFailedToLoad(String error); – Ad failed to load.
  • void OnAdDismissed(bool rewardEarned); – Ad was dismissed by the user. Continue with app operations.
  • void OnUserEarnedReward(); – User earned a reward.

The following code segment illustrates the above-listed callback functions and their implementation:

public class RewardsSDKDemo : MonoBehaviour
{
   
// Show Ad    
   public void ShowAd()
   {
       NowGGRewardsSdkManager.Instance.ShowAd();
   }

// Initialize Success
   private void OnInitSuccess()
   {
       Debug.Log("OnInitSuccess");
   }

// Initialize Failed 
   private void OnInitFailed(string error)
   {
       Debug.Log("OnInitFailed.. " + error);
   }

// Ad is displayed on the User's screen
   private void OnAdShownToUser()
   {
       Debug.Log("OnAdShownToUser");
   }

// Ad failed to load
   private void OnAdFailedToLoad(string error)
   {
       Debug.Log("OnAdFailedToLoad.." + error);
   }

//Ad was dismissed by the user; continue with app operations.
   private void OnAdDismissed(bool rewardEarned)
   {
       Debug.Log("OnAdDismissed.." + rewardEarned);
   }

//User earned a reward  
   private void OnUserEarnedReward()
      {
          Debug.Log("OnUserEarnedReward");
      }
}

Testing Integration

Now that you have integrated with now.gg Rewarded Ads SDK, you must test this integration.

To test your integration with now.gg, you must enable debug mode, which enables you to test this integration locally on the BlueStacks 5 App Player.

1. Enable Debug Mode

Call the EnableDebugMode() function of the NowGGRewardsSdkManager class before initializing the SDK, as illustrated below:

void Start()
   {
       NowGGRewardsSdkManager.Instance.OnInitSuccess += OnInitSuccess;
       NowGGRewardsSdkManager.Instance.OnInitFailed += OnInitFailed;
       NowGGRewardsSdkManager.Instance.OnAdDismissed += OnAdDismissed;
       NowGGRewardsSdkManager.Instance.OnAdFailedToLoad += OnAdFailedToLoad;
       NowGGRewardsSdkManager.Instance.OnAdShownToUser += OnAdShownToUser;
       NowGGRewardsSdkManager.Instance.OnUserEarnedReward += OnUserEarnedReward;

/* IMPORTANT: Use this line to test integration on Bluestacks 5 and remove it from prod/release apk */
       NowGGRewardsSdkManager.Instance.EnableDebugMode();
      
       NowGGRewardsSdkManager.Instance.Initialize();
   }

2. Test the SDK Integration

  • Install BlueStacks 5 App Player on your test machine.
  • Install your app with ‘now.gg Rewarded Ads SDK’ integration by simply dragging and dropping the APK over the BlueStacks 5 App Player.
  • Launch your app.
  • Depending on how you have configured the rewarded Ads with your app, test the scenarios where:
    • Ad is displayed on the user’s screen
    • The user has earned a reward
    • The ad was dismissed by the user, which resulted in either:
      • No reward being earned
      • Reward earned since it was dismissed after a specific time configured by the Ad network.

Note: The ads displayed within the testing environment on BlueStacks 5 are dummy ads. Actual Ads will only be displayed to the user after you publish your app to now.gg.

Important Information

  • The EnableDebugMode() function should only be initialized for the testing environment.
  • You must remove this function before submitting the release version of your APK to now.gg Cloud.

SDK Demo Project

We have also included an SDK Demo project in the download package. You can refer to this project to understand now.gg Rewarded Ads flow.

To understand the flow:

  • Open this project in Unity.
  • Open the scene SampleScene.unity from the Assets\Scenes directory in your Project panel.
×

Document Rev. 1.0

Text copied to clipboard
Questions? Please reach out to us at dev-support@now.gg