Skip to content

APS Updates #89

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
18 changes: 6 additions & 12 deletions com.adsbynimbus.nimbus/Editor/NimbusManagerCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,9 @@ private void HandleApsSlots(SerializedProperty slotData, out ApsSlotData[] platf
SlotId = slotId?.stringValue
};

var adUnitType = item.FindPropertyRelative("AdUnitType");
var adUnitType = item.FindPropertyRelative("APSAdUnitType");
if (adUnitType != null) {
apsData.AdUnitType = (AdUnitType)adUnitType.enumValueIndex;
apsData.APSAdUnitType = (APSAdUnitType)adUnitType.enumValueIndex;
}

apsSlotData.Add(apsData);
Expand All @@ -657,26 +657,20 @@ private bool ValidateApsData(string platform, SerializedProperty appId, ApsSlotD
return false;
}

var seenAdTypes = new Dictionary<AdUnitType, bool>();
var seenAdTypes = new Dictionary<APSAdUnitType, bool>();
foreach (var apsSlot in slotData) {
if (apsSlot.SlotId.IsNullOrEmpty()) {
Debug.unityLogger.LogError("Nimbus",
$"APS SDK has been included, the APS slot id for {platform} cannot be empty, object NimbusAdsManager not created");
return false;
}

if (apsSlot.AdUnitType == AdUnitType.Undefined) {
Debug.unityLogger.LogError("Nimbus",
$"APS SDK has been included, Ad Unit type for {platform} cannot be Undefined, object NimbusAdsManager not created");
return false;
}

if (!seenAdTypes.ContainsKey(apsSlot.AdUnitType)) {
seenAdTypes.Add(apsSlot.AdUnitType, true);
if (!seenAdTypes.ContainsKey(apsSlot.APSAdUnitType)) {
seenAdTypes.Add(apsSlot.APSAdUnitType, true);
}
else {
Debug.unityLogger.LogError("Nimbus",
$"APS SDK has been included, APS cannot contain duplicate ad type {apsSlot.AdUnitType} for {platform}, object NimbusAdsManager not created");
$"APS SDK has been included, APS cannot contain duplicate ad type {apsSlot.APSAdUnitType} for {platform}, object NimbusAdsManager not created");
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,4 @@ extension DispatchGroup {
return pairIds
}
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Nimbus.Internal.Interceptor {
public interface IInterceptor {
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen);
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0);
public BidRequest ModifyRequest(BidRequest bidRequest, string data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SkAdNetworkIOS(string rawPlistJson) {
}


public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) {
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0) {
return "";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public void InitializeNativeSDK() {
_aps = new AndroidJavaClass(AndroidApsPackage);
_aps.CallStatic("initialize", _currentActivity, _appID);
foreach (var slot in _slotData) {
var (w, h) = AdTypeToDim(slot.AdUnitType);
if (slot.AdUnitType == AdUnitType.Rewarded) {
var (w, h) = AdTypeToDim(slot.APSAdUnitType);
if (slot.APSAdUnitType == APSAdUnitType.InterstitialVideo ||
slot.APSAdUnitType == APSAdUnitType.RewardedVideo) {
_aps.CallStatic<bool>("addApsSlot", slot.SlotId, w, h, true);
continue;
}
Expand All @@ -46,39 +47,77 @@ public void InitializeNativeSDK() {
adRegistration.CallStatic("enableTesting", true);
}

private static Tuple<int, int> AdTypeToDim(AdUnitType type) {
private static Tuple<int, int> AdTypeToDim(APSAdUnitType type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you were to store the width and height of the ad on the ApsAdSlot you could remove this function and reference those values directly.

switch (type) {
case AdUnitType.Undefined:
return new Tuple<int, int>(0, 0);
case AdUnitType.Banner:
case APSAdUnitType.Display320X50:
return new Tuple<int, int>(320, 50);
case AdUnitType.Interstitial:
case APSAdUnitType.Display300X250:
return new Tuple<int, int>(300, 250);
case APSAdUnitType.Display728X90:
return new Tuple<int, int>(728, 90);
case APSAdUnitType.InterstitialDisplay:
return new Tuple<int, int>(320, 480);
case APSAdUnitType.InterstitialVideo:
return new Tuple<int, int>(320, 480);
case AdUnitType.Rewarded:
case APSAdUnitType.RewardedVideo:
return new Tuple<int, int>(Screen.width, Screen.height);
default:
return new Tuple<int, int>(0, 0);
}
}


public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) {
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0) {
var found = false;
// ReSharper disable once ForCanBeConvertedToForeach
// ReSharper disable once LoopCanBeConvertedToQuery
for (var i = 0; i < _slotData.Length; i++) {
if (_slotData[i].AdUnitType != type) continue;
found = true;
break;
var interstitialVideo = false;
foreach (ApsSlotData slot in _slotData){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous for loop implementation for matching slots was fine since it was only checking a single condition but as the complexity has grown, this pattern becomes much harder to maintain as it is currently lacking adequate testing and will be prone to future error.

Is it possible to replace this with the .Net Find function?

if (type == AdUnitType.Banner)
{
if (width == 320 && height == 50 && slot.APSAdUnitType == APSAdUnitType.Display320X50)
{
found = true;
break;
}
if (width == 300 && height == 250 && slot.APSAdUnitType == APSAdUnitType.Display300X250)
{
found = true;
break;
}
if (width == 728 && height == 90 && slot.APSAdUnitType == APSAdUnitType.Display728X90)
{
found = true;
break;
}
}
if (type == AdUnitType.Interstitial)
{
if (slot.APSAdUnitType == APSAdUnitType.InterstitialDisplay ||
slot.APSAdUnitType == APSAdUnitType.InterstitialVideo)
{
found = true;
interstitialVideo = (slot.APSAdUnitType == APSAdUnitType.InterstitialVideo);
break;
}
}
if (type == AdUnitType.Rewarded)
{
if (slot.APSAdUnitType == APSAdUnitType.RewardedVideo)
{
found = true;
break;
}
}
}

if (!found) {
Debug.unityLogger.LogError("Nimbus",
"APS NOT FOUND");
return null;
}

var (w, h) = AdTypeToDim(type);
if (type == AdUnitType.Rewarded) {

var w = width;
var h = height;
if (interstitialVideo || type == AdUnitType.Rewarded) {
w = 0;
h = 0;
isFullScreen = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public void InitializeNativeSDK() {
_initializeAPSRequestHelper(_appID, TimeoutInSeconds, _enableTestMode);

foreach (var slot in _slotData) {
var (w, h) = AdTypeToDim(slot.AdUnitType);
if (slot.AdUnitType == AdUnitType.Rewarded) {
var (w, h) = AdTypeToDim(slot.APSAdUnitType);
if (slot.APSAdUnitType == APSAdUnitType.InterstitialVideo ||
slot.APSAdUnitType == APSAdUnitType.RewardedVideo) {
_addAPSSlot(slot.SlotId, w, h, true);
continue;
}
Expand All @@ -50,39 +51,74 @@ public void InitializeNativeSDK() {
}
}

private static Tuple<int, int> AdTypeToDim(AdUnitType type) {
private static Tuple<int, int> AdTypeToDim(APSAdUnitType type) {
switch (type) {
case AdUnitType.Undefined:
return new Tuple<int, int>(0, 0);
case AdUnitType.Banner:
case APSAdUnitType.Display320X50:
return new Tuple<int, int>(320, 50);
case AdUnitType.Interstitial:
case APSAdUnitType.Display300X250:
return new Tuple<int, int>(300, 250);
case APSAdUnitType.Display728X90:
return new Tuple<int, int>(728, 90);
case APSAdUnitType.InterstitialDisplay:
return new Tuple<int, int>(320, 480);
case AdUnitType.Rewarded:
case APSAdUnitType.InterstitialVideo:
return new Tuple<int, int>(Screen.width, Screen.height);
case APSAdUnitType.RewardedVideo:
return new Tuple<int, int>(Screen.width, Screen.height);
default:
return new Tuple<int, int>(0, 0);
}
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) {
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0) {
var found = false;
// ReSharper disable once ForCanBeConvertedToForeach
// ReSharper disable once LoopCanBeConvertedToQuery
for (var i = 0; i < _slotData.Length; i++) {
if (_slotData[i].AdUnitType != type) continue;
found = true;
break;
var interstitialVideo = false;
foreach (ApsSlotData slot in _slotData){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be duplicated from the Android code, is it possible to use a single method for retrieving the slot that can be used by both platforms?

if (type == AdUnitType.Banner)
{
if (width == 320 && height == 50 && slot.APSAdUnitType == APSAdUnitType.Display320X50)
{
found = true;
break;
}
if (width == 300 && height == 250 && slot.APSAdUnitType == APSAdUnitType.Display300X250)
{
found = true;
break;
}
if (width == 728 && height == 90 && slot.APSAdUnitType == APSAdUnitType.Display728X90)
{
found = true;
break;
}
}
if (type == AdUnitType.Interstitial)
{
if (slot.APSAdUnitType == APSAdUnitType.InterstitialDisplay ||
slot.APSAdUnitType == APSAdUnitType.InterstitialVideo)
{
found = true;
interstitialVideo = (slot.APSAdUnitType == APSAdUnitType.InterstitialVideo);
break;
}
}
if (type == AdUnitType.Rewarded)
{
if (slot.APSAdUnitType == APSAdUnitType.RewardedVideo)
{
found = true;
break;
}
}
}

if (!found) {
return null;
}


var (w, h) = AdTypeToDim(type);
// ReSharper disable once InvertIf
if (type == AdUnitType.Rewarded) {
var w = width;
var h = height;
if (interstitialVideo || type == AdUnitType.Rewarded) {
w = 0;
h = 0;
isFullScreen = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
using System;
using UnityEngine;

namespace Nimbus.Internal.Interceptor.ThirdPartyDemand {
[Serializable]
public class ApsSlotData {
public string SlotId;
public AdUnitType AdUnitType;
public APSAdUnitType APSAdUnitType;
}
public enum APSAdUnitType : byte {
Display320X50 = 0,
Display300X250 = 1,
Display728X90 = 2,
InterstitialDisplay = 3,
InterstitialVideo = 4,
RewardedVideo = 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void InitializeNativeSDK() {
//do nothing
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) {
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0) {
foreach (ThirdPartyAdUnit adUnit in _adUnitIds)
{
if (adUnit.AdUnitType == type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public BidRequest ModifyRequest(BidRequest bidRequest, string data)
return bidRequest;
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen)
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0)
{
foreach (ThirdPartyAdUnit adUnit in _adUnitIds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public BidRequest ModifyRequest(BidRequest bidRequest, string data) {
return bidRequest;
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen)
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0)
{
var meta = new AndroidJavaClass(NimbusMetaPackage);
var buyerId = meta.GetStatic<string>("bidderToken");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BidRequest ModifyRequest(BidRequest bidRequest, string data) {
return bidRequest;
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen)
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0)
{
var biddingToken = _fetchMetaBiddingToken();
Debug.unityLogger.Log("METABIDDINGTOKEN", biddingToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void InitializeNativeSDK() {

}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen) {
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0) {
foreach (ThirdPartyAdUnit adUnit in _adUnitIds)
{
if (adUnit.AdUnitType == type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public BidRequest ModifyRequest(BidRequest bidRequest, string data)
return bidRequest;
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen)
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0)
{
foreach (ThirdPartyAdUnit adUnit in _adUnitIds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public BidRequest ModifyRequest(BidRequest bidRequest, string data) {
return bidRequest;
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen)
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0)
{
var token = "";
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public BidRequest ModifyRequest(BidRequest bidRequest, string data) {
return bidRequest;
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen)
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0)
{
var biddingToken = _fetchMobileFuseToken();
Debug.unityLogger.Log("MobileFuse Token", biddingToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public BidRequest ModifyRequest(BidRequest bidRequest, string data) {
return bidRequest;
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen)
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0)
{
var unityAds = new AndroidJavaClass(UnityAdsPackage);
var token = unityAds.CallStatic<string>("getToken");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public BidRequest ModifyRequest(BidRequest bidRequest, string data) {
return bidRequest;
}

public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen)
public string GetProviderRtbDataFromNativeSDK(AdUnitType type, bool isFullScreen, int width=0, int height=0)
{
var biddingToken = _fetchUnityAdsToken();
Debug.unityLogger.Log("Unity Token", biddingToken);
Expand Down
Loading