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:
The now.gg Rewarded Ads SDK Unity plugin is included as a Unity package file (NowGGRewardsSdk.unitypackage
).
Add the plugin to your Unity project:
NowGGRewardsSdk.unitypackage
that you previously downloaded.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.
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:
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.
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:
Initialize()
function of the NowGGRewardsSdkManager
class is called to initialize the Rewarded Ads SDK.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"); } }
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.
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(); }
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.
EnableDebugMode()
function should only be initialized for the testing environment.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:
SampleScene.unity
from the Assets\Scenes directory in your Project panel.Document Rev. 1.0