Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HB-5995] Update Documentation for Fullscreen API Usage #147

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions com.chartboost.mediation.demo/Assets/Demo/Demo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,17 @@ public async void OnLoadFullscreenClick()

var loadRequest = new ChartboostMediationFullscreenAdLoadRequest(fullscreenPlacementInputField.text, keywords);

loadRequest.DidClick += fullscreenAd => {
Log($"DidClick Name: {fullscreenAd.Request.PlacementName}");
};

loadRequest.DidClose += (fullscreenAd, error) =>
{
Log(!error.HasValue
? $"DidClose Name: {fullscreenAd.Request.PlacementName}"
: $"DidClose Name: {fullscreenAd.Request.PlacementName}, Code: {error?.code}, Message: {error?.message}");
};

loadRequest.DidReward += fullscreenAd =>
{
Log($"DidReward Name: {fullscreenAd.Request.PlacementName}");
};

loadRequest.DidRecordImpression += fullscreenAd =>
{
Log($"DidImpressionRecorded Name: {fullscreenAd.Request.PlacementName}");
};

loadRequest.DidExpire += fullscreenAd =>
{
Log($"DidExpire Name: {fullscreenAd.Request.PlacementName}");
};
loadRequest.DidClick += fullscreenAd => Log($"DidClick Name: {fullscreenAd.Request.PlacementName}");

loadRequest.DidClose += (fullscreenAd, error) => Log(!error.HasValue
? $"DidClose Name: {fullscreenAd.Request.PlacementName}"
: $"DidClose Name: {fullscreenAd.Request.PlacementName}, Code: {error?.code}, Message: {error?.message}");

loadRequest.DidReward += fullscreenAd => Log($"DidReward Name: {fullscreenAd.Request.PlacementName}");

loadRequest.DidRecordImpression += fullscreenAd => Log($"DidImpressionRecorded Name: {fullscreenAd.Request.PlacementName}");

loadRequest.DidExpire += fullscreenAd => Log($"DidExpire Name: {fullscreenAd.Request.PlacementName}");

var loadResult = await ChartboostMediation.LoadFullscreenAd(loadRequest);

Expand All @@ -161,7 +147,7 @@ public async void OnLoadFullscreenClick()
}

// Loaded but AD is null?
_fullscreenAd = loadResult.AD;
_fullscreenAd = loadResult.Ad;
if (_fullscreenAd == null)
{
Log("Fullscreen Ad is null but no error was found???");
Expand All @@ -171,12 +157,12 @@ public async void OnLoadFullscreenClick()
// DidLoad
_fullscreenAd.CustomData = DefaultFullscreenAdCustomData;
var customData = _fullscreenAd.CustomData;
var adRequestId = _fullscreenAd.LoadId;
var adLoadId = _fullscreenAd.LoadId;
var bidInfo = _fullscreenAd.WinningBidInfo;
var placementName = _fullscreenAd?.Request?.PlacementName;
var requestId = loadResult.RequestId;
var loadId = loadResult.LoadId;
var metrics = loadResult.Metrics;
Log($"Fullscreen: {placementName} Loaded with: \nAdRequestId {adRequestId} \nRequestID {requestId} \nBidInfo: {JsonConvert.SerializeObject(bidInfo, Formatting.Indented)} \n Metrics:{JsonConvert.SerializeObject(metrics, Formatting.Indented)} \n Custom Data: {customData}");
Log($"Fullscreen: {placementName} Loaded with: \nAdRequestId {adLoadId} \nRequestID {loadId} \nBidInfo: {JsonConvert.SerializeObject(bidInfo, Formatting.Indented)} \n Metrics:{JsonConvert.SerializeObject(metrics, Formatting.Indented)} \n Custom Data: {customData}");
}

public void OnInvalidateFullscreenClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Chartboost Mediation's delegate methods allow you to exercise a greater degree o

The Chartboost Mediation Unity SDK implements its delegate functionality using C# style delegates and events. Before using any of the delegate methods, you should first subscribe to the relevant SDK events in your MonoBehaviour as demonstrated:

### Subscribing Delegates
### Subscribing Static Delegates
```c#
private void OnEnable() {
// Start Delegate
Expand All @@ -28,21 +28,6 @@ private void OnEnable() {
// Error Handling Delegate
ChartboostMediation.UnexpectedSystemErrorDidOccur += UnexpectedSystemErrorDidOccur;

// Interstitial Ad Delegates
ChartboostMediation.DidLoadInterstitial += DidLoadInterstitial;
ChartboostMediation.DidShowInterstitial += DidShowInterstitial;
ChartboostMediation.DidCloseInterstitial += DidCloseInterstitial;
ChartboostMediation.DidClickInterstitial += DidClickInterstitial;
ChartboostMediation.DidRecordImpressionInterstitial += DidRecordImpressionInterstitial;

// Rewarded Ad Delegates
ChartboostMediation.DidLoadRewarded += DidLoadRewarded;
ChartboostMediation.DidShowRewarded += DidShowRewarded;
ChartboostMediation.DidCloseRewarded += DidCloseRewarded;
ChartboostMediation.DidReceiveReward += DidReceiveReward;
ChartboostMediation.DidClickRewarded += DidClickRewarded;
ChartboostMediation.DidRecordImpressionRewarded += DidRecordImpressionRewarded;

// Banner Ad Delegates
ChartboostMediation.DidLoadBanner += DidLoadBanner;
ChartboostMediation.DidClickBanner += DidClickBanner;
Expand Down Expand Up @@ -77,29 +62,14 @@ private void OnDisable() {
// Error Handling Delegate
ChartboostMediation.UnexpectedSystemErrorDidOccur -= UnexpectedSystemErrorDidOccur;

// Interstitial Ad Delegates
ChartboostMediation.DidLoadInterstitial -= DidLoadInterstitial;
ChartboostMediation.DidShowInterstitial -= DidShowInterstitial;
ChartboostMediation.DidCloseInterstitial -= DidCloseInterstitial;
ChartboostMediation.DidClickInterstitial -= DidClickInterstitial;
ChartboostMediation.DidRecordImpressionInterstitial -= DidRecordImpressionInterstitial;

// Rewarded Ad Delegates
ChartboostMediation.DidLoadRewarded -= DidLoadRewarded;
ChartboostMediation.DidShowRewarded -= DidShowRewarded;
ChartboostMediation.DidCloseRewarded -= DidCloseRewarded;
ChartboostMediation.DidReceiveReward -= DidReceiveReward;
ChartboostMediation.DidClickRewarded -= DidClickRewarded;
ChartboostMediation.DidRecordImpressionRewarded -= DidRecordImpressionRewarded;

// Banner Ad Delegates
ChartboostMediation.DidLoadBanner -= DidLoadBanner;
ChartboostMediation.DidClickBanner -= DidClickBanner;
ChartboostMediation.DidRecordImpressionBanner -= DidRecordImpressionBanner;
}
```

## Example Delegate Methods
### Subscribing Delegates

### Lifecycle Delegates
```c#
Expand Down Expand Up @@ -130,67 +100,6 @@ private static void UnexpectedSystemErrorDidOccur(string error)
}
```

### Interstitial Ad Delegates
```c#
private void DidLoadInterstitial(string placementName, string loadId, BidInfo info, string error)
{
Debug.Log($"DidLoadInterstitial {placementName}, Price: ${info.Price:F4}, Auction Id: {info.AuctionId}, Partner Id: {info.PartnerId}. {error}");
}

private void DidShowInterstitial(string placementName, string error)
{
Debug.Log($"DidShowInterstitial {placementName}: {error}");
}

private void DidCloseInterstitial(string placementName, string error)
{
Debug.Log($"DidCloseInterstitial {placementName}: {error}");
}

private void DidClickInterstitial(string placementName, string error)
{
Debug.Log($"DidClickInterstitial {placementName}: {error}");
}

private void DidRecordImpressionInterstitial(string placementName, string error)
{
Log($"DidRecordImpressionInterstitial {placementName}: {error}");
}
```

### Rewarded Ad Delegates
```c#
private void DidLoadRewarded(string placementName, string loadId, BidInfo info, string error)
{
Debug.Log($"DidLoadRewarded {placementName}, Price: ${info.Price:F4}, Auction Id: {info.AuctionId}, Partner Id: {info.PartnerId}. {error}");
}

private void DidShowRewarded(string placementName, string error)
{
Debug.Log($"DidShowRewarded {placementName}: {error}");
}

private void DidCloseRewarded(string placementName, string error)
{
Debug.Log($"DidCloseRewarded {placementName}: {error}");
}

private void DidClickRewarded(string placementName, string error)
{
Debug.Log($"DidClickRewarded {placementName}: {error}");
}

private void DidReceiveReward(string placementName, string error)
{
Debug.Log($"DidReceiveReward {placementName}: {error}");
}

private void DidRecordImpressionRewarded(string placementName, string error)
{
Log($"DidRecordImpressionRewarded {placementName}: {error}");
}
```

### Banner Ad delegates
```c#
private void DidLoadBanner(string placementName, string loadId, BidInfo info, string error)
Expand Down
73 changes: 56 additions & 17 deletions com.chartboost.mediation/Documentation/integration/loading-ads.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
# Loading Ads

## Creating Interstitial & Rewarded Ad Objects
## Loading Fullscreen Placements

To show an Interstitial or Rewarded Ads, first declare a variable to hold a reference to either the Interstitial or Rewarded Chartboost Mediation Ad. Supply the corresponding Placement Name you set up on your dashboard as the argument for each of these functions:
Since Chartboost Mediation Unity SDK 4.3.X we have deprecated the previous approach for loading fullscreen placements. A new Fullscreen API has been provided for `interstitials`, `rewarded videos` and `rewarded interstitials`, the new API makes use of C# asycn/await methods in order to await for load and show. A detailed example on the load logic for fullscreen placements can be found below:

```c#
// Interstitial Ad
private ChartboostMediationInterstitialAd _interstitialAd;

// Rewarded Ad
private ChartboostMediationRewardedAd _rewardedAd;
// Strong reference to cached ad.
private IChartboostMediationFullscreenAd _fullscreenPlacement;

...
_interstitialAd = ChartboostMediation.GetInterstitialAd(PLACEMENT_INTERSTITIAL);
_rewardedAd = ChartboostMediation.GetRewardedAd(PLACEMENT_REWARDED);
```
// keywords are optional
var keywords = new Dictionary<string, string> { { "i12_keyword1", "i12_value1" } };

## Loading Interstitial & Rewarded Ads
// Create a Fullscreen Ad Load Request
var loadRequest = new ChartboostMediationFullscreenAdLoadRequest(FULLSCREEN_PLACEMENT, keywords);

You will need to create an instance for each Placement Name you want to use. Finally, make the call to load the ad:
// Subscribing Instance Delegates
loadRequest.DidClick += fullscreenAd => Log($"DidClick Name: {fullscreenAd.Request.PlacementName}");

```c#
_interstitialAd.Load();
_rewardedAd.Load();
loadRequest.DidClose += (fullscreenAd, error) =>
Debug.Log(!error.HasValue ? $"DidClose Name: {fullscreenAd.Request.PlacementName}"
: $"DidClose with Error. Name: {fullscreenAd.Request.PlacementName}, Code: {error?.code}, Message: {error?.message}");

loadRequest.DidReward += fullscreenAd => Log($"DidReward Name: {fullscreenAd.Request.PlacementName}");

loadRequest.DidRecordImpression += fullscreenAd => Log($"DidImpressionRecorded Name: {fullscreenAd.Request.PlacementName}");

loadRequest.DidExpire += fullscreenAd => Log($"DidExpire Name: {fullscreenAd.Request.PlacementName}");

// Await on FullscreenAd Load
var loadResult = await ChartboostMediation.LoadFullscreenAd(loadRequest);


// Failed to Load
if (loadResult.Error.HasValue)
{
var error = loadResult.Error.Value;
Debug.Log($"Fullscreen Failed to Load: {error.code}, message: {error.message}");
return;
}

// Successful Load!

// Set strong reference to cached ad
_fullscreenPlacement = loadResult.AD;

// Set custom data before show
_fullscreenPlacement.CustomData = "CUSTOM DATA HERE!";

var placementName = _fullscreenAd?.Request?.PlacementName;
Debug.Log($"Fullscreen Placement Loaded with PlacementName: {placementName}")
```

You can implement delegates in your class to receive notifications about the success or failure of the ad loading process for both Interstitial and Rewarded formats. See section [Delegate Usage](delegate-usage.md) for more details.
> **Note** \
> The new fullscreen API supports multiple placement loads of the same placement. It is important to properly manage your ad instances if you are planning to create an Ad Queue system.

> **Warning** \
> The new fullscreen API utilizes instance based callbacks to notify information regarding the advertisement life-cycle. You must take this into account when migrating from the old API static callbacks.

## Creating Banner Ad Objects

Expand Down Expand Up @@ -100,9 +131,17 @@ You can implement delegates in your class to receive notifications about the suc
Sometimes, you may need to clear loaded ads on existing placements to request another ad (i.e. for an in-house programmatic auction). To do this:

```c#
// Old API
_interstitialAd.ClearLoaded();
_rewardedAd.ClearLoaded();

_bannerAd.ClearLoaded();
```

The clearLoaded API returns a boolean and indicates if the ad object has been cleared and is ready for another load call.
```c#
/// New fullscreen API
_fullscreenPlacement.Invalidate();
```

> **Warning** \
> `Invalidate` behaves similarly like `ClearLoaded` and `Destroy`. As such, once called, you must free your ad reference to avoid any possible issues.
45 changes: 21 additions & 24 deletions com.chartboost.mediation/Documentation/integration/showing-ads.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
# Showing Ads

## Showing Interstitial and Rewarded Ads
## Showing Fullscreen Placements

When you are ready to show a Rewarded or Interstitial ad, you can check that it is ready to show and then display it like so:
Fullscreen Placements must be first loaded, see section [Loading Ads](loading-ads.md) for more information.

### Interstitial Ad
Similar to the new load API. The new Fullscreen API utilizes C# async/await in order to request ad show. See below for details on implementation:

```c#
// Showing an Interstitial Ad
if (_interstitialAd.ReadyToShow())
_interstitialAd.Show();
```
if (_fullscreenPlacement == null)
return;

### Rewarded Ad
var adShowResult = await _fullscreenPlacement.Show();
var error = adShowResult.error;

```c#
//Showing a Rewarded Ad
if (_rewardedAd.ReadyToShow()){
_rewardedAd.show();
// Failed to Show
if (adShowResult.error.HasValue)
{
Debug.Log($"Fullscreen Failed to Show with Value: {error.Value.code}, {error.Value.message}");
return;
}

// Successful Show
var metrics = adShowResult.metrics;
Debug.Log($"Fullscreen Ad Did Show: {JsonConvert.SerializeObject(metrics, Formatting.Indented)}");
```

## Showing Banner Ads
Banners are now automatically shown after load, see section [Loading Ads](loading-ads.md) for more information.

## Releasing Chartboost Mediation Ads

To clear resources used by Chartboost Mediation Ads, you can use the destroy method associated with the respective Ad you have used.
To clear resources used by Chartboost Mediation Ads, you can use the methods associated with the respective Ad you have used.

```c#
private void OnDestroy()
{
if (_interstitialAd != null)
{
_interstitialAd.ClearLoaded();
_interstitialAd.Destroy();
Debug.Log("Destroyed an existing interstitial");
}
if (_rewardedAd != null)
if (_fullscreenPlacement != null)
{
_rewardedAd.ClearLoaded();
_rewardedAd.Destroy();
Debug.Log("Destroyed an existing rewarded");
_fullscreenPlacement.Invalidate();
Debug.Log("Invalidated an existing fullscreen");
}
if (_bannerAd != null)
{
Expand All @@ -49,5 +47,4 @@ private void OnDestroy()
Debug.Log("Destroyed an existing banner");
}
}

```
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ private void onAdLoaded(AndroidJavaObject result)

var nativeAd = result.Get<AndroidJavaObject>("ad");
var ad = new ChartboostMediationFullscreenAdAndroid(nativeAd, CacheManager.GetFullScreenAdLoadRequest(hashCode()));
var requestIdentifier = result.Get<string>("loadId");
var loadId = result.Get<string>("loadId");
var metrics = result.Get<AndroidJavaObject>("metrics").JsonObjectToMetrics();
_complete(new ChartboostMediationFullscreenAdLoadResult(ad, requestIdentifier, metrics));
_complete(new ChartboostMediationFullscreenAdLoadResult(ad, loadId, metrics));
});
}
}
Expand Down
Loading