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-5971]Update README.md with Instructions and Sample Code for Using the Adaptive Banner 3D GameObject #187

Merged
Show file tree
Hide file tree
Changes from 4 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ private void OnEnable() {

// Error Handling Delegate
ChartboostMediation.UnexpectedSystemErrorDidOccur += UnexpectedSystemErrorDidOccur;

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

Expand Down Expand Up @@ -61,11 +56,6 @@ private void OnDisable() {

// Error Handling Delegate
ChartboostMediation.UnexpectedSystemErrorDidOccur -= UnexpectedSystemErrorDidOccur;

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

Expand Down Expand Up @@ -100,20 +90,3 @@ private static void UnexpectedSystemErrorDidOccur(string error)
}
```

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

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

private void DidRecordImpressionBanner(string placementName, string error)
{
Log($"DidRecordImpressionBanner {placementName}: {error}");
}
```
112 changes: 71 additions & 41 deletions com.chartboost.mediation/Documentation/integration/loading-ads.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,35 @@ Debug.Log($"Fullscreen Placement Loaded with PlacementName: {placementName}")

## Creating Banner Ad Objects

To show a banner ad, first declare a variable to hold a reference to the Banner Ad. Supply the corresponding Placement Name and the Banner Size.
Since Chartboost Mediation Unity SDK 4.6.X we have deprecated the previous approach for loading banner placements. A new Banner API `ChartboostMedaitionBannerView` has been provided which makes use of C# asycn/await methods in order to await for load and show and also provides support to load adaptive size banners.

> **Note** \
> The following banner sizes can be passed down. Some partners may not fill for some banner sizes.
Another API `ChartboostMediationUnityBannerAd` is also provided which allows usage of unity gameobjects to load a banner ad within it.

A detailed example on the load logic for both of these APIs can be found below :

| Banner Enum | Dimensions (Width x Height) |
| :--- | :--- |
| `Standard` | 320 x 50 |
| `Medium` | 300 x 250 |
| `Leaderboard` | 728 x 90 |
### Using `ChartboostMediationBannerView` API

```c#
private ChartboostMediationBannerAd _bannerAd;

if (_bannerAd != null)
return;

/*
The following Banner enum Sizes can be passed down:
ChartboostMediationBannerAdSize.Standard
ChartboostMediationBannerAdSize.MediumRect
ChartboostMediationBannerAdSize.Leaderboard
*/
ChartboostMediationBannerAdSize BANNER_SIZE = ChartboostMediationBannerAdSize.Standard;
_bannerAd = ChartboostMediation.GetBannerAd(PLACEMENT_BANNER, BANNER_SIZE);
```
// Get a bannerView
ChartboostMediationBannerView bannerView = ChartboostMediation.GetBannerView();

// Determine the maximum size to load using width and height
var size = ChartboostMediationBannerSize.Adaptive(width, height);

Banners are now shown automatically after load, as such you will need to pass a `ChartboostMediationBannerAdScreenLocation` position when calling the load method:
// create a load request with size and your placementName
var loadRequest = new ChartboostMediationBannerAdLoadRequest(placementName, size)

// Determine where on the screen you want to place this bannerView
var screenLocation = ChartboostMediationAdScreenLocation.TopRight;

// Load the banner ad
var loadResult = await bannerView.Load(loadRequest, screenLocation);
if(!loadResult.Error.HasValue)
{
// loaded successfullly
}
```
Banners are now shown automatically after load, you may choose to use a different `ChartboostMediationBannerAdScreenLocation` position when calling the load method:

| Banner Ad Location Enum | Enum Value | Position |
|:---------------------------------------------------------| :--- | :--- |
Expand All @@ -99,28 +99,51 @@ Banners are now shown automatically after load, as such you will need to pass a
| `ChartboostMediationBannerAdScreenLocation.BottomCenter` | 5 | Positions the banner to the bottom-center screen of the device. |
| `ChartboostMediationBannerAdScreenLocation.BottomRight` | 6 | Positions the banner to the bottom-right screen of the device. |

If you enable auto-refresh for a banner placement in the dashboard, then the Chartboost Mediation Unity SDK will apply that setting when the placement is shown.

> **Note** \
> Any auto refresh changes made on the dashboard will take approximately one hour to take effect and the SDK must be rebooted in order to pick up the changes once they are available.
If you want to place the bannerView using a custom screen location then you can do so by providing a screen co-ordinate(x, y) which denotes where the top-left corner of this bannerView will be placed
kushG marked this conversation as resolved.
Show resolved Hide resolved
```C#
// 400 pixels from left
float x = ChartboostMediationConverters.PixelsToNative(400);
// 200 pixels from bottom
float y = ChartboostMediationConverters.PixelsToNative(200);

// Load the banner ad
await bannerView.Load(loadRequest, x, y);
```

You will need to create an instance for each Placement Name you want to use. Finally, make the call to load the ad:
### Using `ChartboostMediationUnityBannerAd` API

`ChartboostMediationUnityBannerAd` API enables loading of a bannerAd within a unity gameobject.
To create such gameobject you can simply right-click in hierarchy window and select `Chartboost Mediation/UnityBannerAd`
kushG marked this conversation as resolved.
Show resolved Hide resolved
![Creating UnityBannerAd](../images/create-unity-banner-ad.png)

```c#

/* All possible banner locations
* ChartboostMediationBannerAdScreenLocation.TopLeft,
* ChartboostMediationBannerAdScreenLocation.TopCenter,
* ChartboostMediationBannerAdScreenLocation.TopRight,
* ChartboostMediationBannerAdScreenLocation.Center,
* ChartboostMediationBannerAdScreenLocation.BottomLeft,
* ChartboostMediationBannerAdScreenLocation.BottomCenter,
* ChartboostMediationBannerAdScreenLocation.BottomRight,
* ChartboostMediationBannerAdScreenLocation.TopCenter
*/

// Load a banner on the top center location
_bannerAd.Load(ChartboostMediationBannerAdScreenLocation.TopCenter);
```C#
// Get reference to ChartboostMediationUnityBannerAd created in Editor
public ChartboostMediationUnityBannerAd unityBannerAd;

// Load the banner ad inside this gameobject
var loadResult = await unityBannerAd.Load();

if(!loadResult.Error.HasValue)
{
// loaded successfullly
}
```
If you want to create this gameobject at runtime you can make use of `ChartboostMediation.GetUnityBannerAd()`
```C#
// Get new unityBannerAd created as a child of provided canvas
var canvas = FindObjectOfType<Canvas>();
ChartboostMediationUnityBannerAd unityBannerAd = ChartboostMediation.GetUnityBannerAd(placementName, canvas.transform);

// Load the banner ad inside this gameobject
var loadResult = await unityBannerAd.Load();

if(!loadResult.Error.HasValue)
{
// loaded successfullly
}

```

You can implement delegates in your class to receive notifications about the success or failure of the ad loading process for Banner formats. See section [Delegate Usage](delegate-usage.md) for more details.
Expand All @@ -140,6 +163,13 @@ _bannerAd.ClearLoaded();
```c#
/// New fullscreen API
_fullscreenPlacement.Invalidate();

/// New bannerView API
_bannerView.Reset();

/// New unityBannerAd API
_unityBannerAd.Reset()

```

> **Warning** \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ private void OnDestroy()
_fullscreenPlacement.Invalidate();
Debug.Log("Invalidated an existing fullscreen");
}
if (_bannerAd != null)
if (_bannerView != null)
{
_bannerAd.ClearLoaded();
_bannerAd.Destroy();
_bannerView.Reset();
_bannerView.Destroy();
Debug.Log("Destroyed an existing banner");
}
if(_unityBannerAd != null)
{
_unityBannerAd.Reset();
Destroy(_unityBannerAd.gameobject);
Debug.Log("Destroyed an existing banner");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Chartboost.AdFormats.Banner
{
/// <summary>
/// The resizeAis enum for banner ads.
/// </summary>
public enum ChartboostMediationBannerResizeAxis
{
Horizontal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

namespace Chartboost.AdFormats.Banner
{
/// <summary>
/// The banner type enum
/// </summary>
public enum ChartboostMediationBannerType
{
Fixed,
Adaptive
}

/// <summary>
/// The banner size type enum
/// </summary>
public enum ChartboostMediationBannerSizeType
{
Unknown = -1,
Expand Down Expand Up @@ -44,48 +50,142 @@ private ChartboostMediationBannerSize(ChartboostMediationBannerSizeType sizeType
BannerType = bannerType;
}

/// <summary>
/// Returns a size for an adaptive banner with the specified width.
/// This will generally be used when requesting an inline ad that can be of any height. To request an adaptive size banner with
/// a maximum height, use <see cref="Adaptive(float, float)"/> instead.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, 0);

/// <summary>
/// Returns a size for an adaptive banner with the specified width and maxHeight.
/// This will generally be used when requesting an anchored adaptive size banner, or when requesting an inline ad where the maximum height can
/// be constrained. To request an adaptive size banner without a maximum height, use <see cref="Adaptive(float)"/> instead.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <param name="height">The maximum height for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive(float width, float height)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, height);

#region static conveniences
public static readonly ChartboostMediationBannerSize Standard =
GetFixedTypeAd(ChartboostMediationBannerSizeType.Standard);

public static readonly ChartboostMediationBannerSize MediumRect =
GetFixedTypeAd(ChartboostMediationBannerSizeType.Medium);

public static readonly ChartboostMediationBannerSize Leaderboard =
GetFixedTypeAd(ChartboostMediationBannerSizeType.Leaderboard);

/// <summary>
/// A <see cref="ChartboostMediationBannerSize"/> size object for a fixed size 320x50 standard banner.
/// </summary>
public static readonly ChartboostMediationBannerSize Standard = GetFixedTypeAd(ChartboostMediationBannerSizeType.Standard);

/// <summary>
/// A <see cref="ChartboostMediationBannerSize"/> size object for a fixed size 300x250 medium banner.
/// </summary>
public static readonly ChartboostMediationBannerSize MediumRect = GetFixedTypeAd(ChartboostMediationBannerSizeType.Medium);

/// <summary>
/// A <see cref="ChartboostMediationBannerSize"/> size object for a fixed size 728x90 leaderboard banner.
/// </summary>
public static readonly ChartboostMediationBannerSize Leaderboard = GetFixedTypeAd(ChartboostMediationBannerSizeType.Leaderboard);

//Horizontal

/// <summary>
/// Convenience that returns a 2:1 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive2X1(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, width / 2.0f);


/// <summary>
/// Convenience that returns a 4:1 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive4X1(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, width / 4.0f);


/// <summary>
/// Convenience that returns a 6:1 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive6X1(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, width / 6.0f);

/// <summary>
/// Convenience that returns a 8:1 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive8X1(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, width / 8.0f);


/// <summary>
/// Convenience that returns a 10:1 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive10X1(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, width / 10.0f);

//vertical

/// <summary>
/// Convenience that returns a 1:2 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive1X2(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, width * 2.0f);


/// <summary>
/// Convenience that returns a 1:3 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive1X3(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, width * 3.0f);


/// <summary>
/// Convenience that returns a 1:4 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive1X4(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, width * 4.0f);


/// <summary>
/// Convenience that returns a 9:16 <see cref="ChartboostMediationBannerSize"/> size for the specified width.
/// Note: This is only a maximum banner size. Depending on how your waterfall is configured, smaller or different aspect ratio
/// ads may be served.
/// </summary>
/// <param name="width">The maximum width for the banner.</param>
/// <returns>A <see cref="ChartboostMediationBannerSize"/> that can be used to load a banner.</returns>
public static ChartboostMediationBannerSize Adaptive9X16(float width)
=> new ChartboostMediationBannerSize(ChartboostMediationBannerSizeType.Adaptive, width, (width * 16.0f) / 9.0f);
#endregion
Expand Down
Loading
Loading