-
Notifications
You must be signed in to change notification settings - Fork 7
UnityAdsHelper Rewarded Ads
Since rewarded ads are typically non-skippable, some form of button or prompt should always be used to show a rewarded ad. Doing so presents your users with the choice to opt-in, which can lead to a better user experience while making ad impressions more effective.
However, when offering rewarded ads, you may also want to limit how often users are able to redeem rewards for watching ads. In this case, you could implement a cooldown between ads.
Let's update the the ButtonExample script with a method to reward users and set the cooldown for the next ad. We will assign this method to UnityAdsHelper.onFinished
, which is only called when an ad is watched but not skipped.
C# Example – ButtonExample.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ButtonExample : MonoBehaviour
{
public Text textReady;
public Text textWaiting;
public string zoneId;
public float cooldownTime = 300f;
public int rewardAmount = 250;
private float _cooldownTime;
private Button _button;
void Start ()
{
_button = GetComponent<Button>();
}
void Update ()
{
if (_button)
{
_button.interactable = IsReady();
if (textReady) textReady.enabled = _button.interactable;
if (textWaiting) textWaiting.enabled = !_button.interactable;
}
}
private bool IsReady ()
{
if (Time.time > _cooldownTime)
{
return UnityAdsHelper.IsReady(zoneId);
}
else return false;
}
public void ShowAd ()
{
UnityAdsHelper.onFinished = OnFinished;
UnityAdsHelper.ShowAd(zoneId);
}
private void OnFinished ()
{
if (rewardAmount > 0)
{
Debug.Log("The player has earned a reward!");
}
if (cooldownTime > 0)
{
_cooldownTime = Time.time + cooldownTime;
Debug.Log(string.Format("Next ad is available in {0} seconds.",cooldownTime));
}
}
}
JavaScript Example – ButtonExample.js
#pragma strict
import UnityEngine.UI;
public class ButtonExample extends MonoBehaviour
{
public var textReady : Text;
public var textWaiting : Text;
public var zoneId : String;
public var cooldownTime : float = 300f;
public var rewardAmount : int = 250;
private var _cooldownTime : float;
private var _button : Button;
function Start () : void
{
_button = GetComponent.<Button>();
}
function Update () : void
{
if (_button)
{
_button.interactable = IsReady();
if (textReady) textReady.enabled = _button.interactable;
if (textWaiting) textWaiting.enabled = !_button.interactable;
}
}
private function IsReady () : boolean
{
if (Time.time > _cooldownTime)
{
return UnityAdsHelper.IsReady(zoneId);
}
else return false;
}
public function ShowAd () : void
{
UnityAdsHelper.onFinished = OnFinished;
UnityAdsHelper.ShowAd(zoneId);
}
private function OnFinished () : void
{
if (rewardAmount > 0)
{
Debug.Log("The player has earned a reward!");
}
if (cooldownTime > 0)
{
_cooldownTime = Time.time + cooldownTime;
Debug.Log(String.Format("Next ad is available in {0} seconds.",cooldownTime));
}
}
}
With the ButtonExample script updated, you can now set the Cooldown Time (in seconds) and Reward Amount from the Inspector. Be sure to also specify the zone ID of your rewarded zone in the Zone ID field.
Note: To continue using this script with non-rewarded ads, simply set Cooldown Time and Reward Amount to 0. Leave the Zone ID field empty to use the default zone.
The eCPM is defined as the Effective Cost Per 1000 impressions.
eCPM = revenue / starts * 1000
The eCPM is essentially a performance value used to indicate the effectiveness of ads shown in your game. The more impressions you have, the more reliable this value is.
Statistically speaking, the first few ads shown tend to be the most effective in generating revenue. While the most successful ad implementations knowingly take advantage of this by only showing a few ads per user per day, they also make those impressions count.
Video ads are most effective when players are willing to watch. An obvious statement, but it's safe to say the average user doesn't play your game just so they can watch ads. So where's the incentive?
Using rewarded ads is a way to provide users with the motivation to watch non-skippable ads, in exchange for an in-game reward. For example, some games use rewarded ads to give an extra life or a second chance, allowing the user to continue gameplay from a fail state without having to restart from the very beginning. Another example might be to offer the user some amount of in-game currency or consumable item that could be applied toward upgrading their character or purchasing new equipment.
Ultimately, using rewarded ads is a great way to effectively show ads, while also making them relevant to your game and less disruptive to the flow of the in-game experience.