googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.34k stars 1.09k forks source link

Lack of Method to Determine Anchored Adaptive Banner Height #3150

Closed sjvc closed 4 months ago

sjvc commented 4 months ago

Environment:

Issue description:

There appears to be a significant discrepancy in the Google Mobile Ads Unity plugin compared to its Android counterpart, particularly in determining the height of anchored adaptive banners. In Unity, the AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width) method returns an AdSize object with a height of 0, unlike the expected behavior observed in the Android SDK.

Steps to reproduce:

  1. Invoke AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width) in a Unity project.
  2. Observe that the returned AdSize object contains a height value of 0, indicating an inability to pre-determine the banner height.

Expected vs. Actual Behavior

In the AdMob Android native SDK, the method AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(activity, screenWidth) provides the exact ad size, including its height, before creation. This is crucial for optimizing layout and user experience. The expected behavior is for the Unity plugin to provide a similar capability, ensuring consistency across platforms.

Relevant Code Snippet from Android SDK:

Upon examining the functionality of the Android native method AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(activity, screenWidth), it internally invokes a method designed to calculate the adaptive ad size as follows:

public static AdSize obfuscatedMethodName(Context context, int screenWidthDp, int orientation) {
    int heightDp = anotherObfuscatedMethodNameThatGetsScreenHeightInDp(context, orientation);
    if (heightDp == -1) {
        return AdSize.INVALID;
    } else {
        int anotherHeightDp = Math.min(90, Math.round((float)heightDp * 0.15F));
        if (screenWidthDp > 655) {
            heightDp = Math.round((float)screenWidthDp / 728.0F * 90.0F);
        } else if (screenWidthDp > 632) {
            heightDp = 81;
        } else if (screenWidthDp > 526) {
            heightDp = Math.round((float)screenWidthDp / 468.0F * 60.0F);
        } else if (screenWidthDp > 432) {
            heightDp = 68;
        } else {
            heightDp = Math.round((float)screenWidthDp / 320.0F * 50.0F);
        }

        heightDp = Math.max(Math.min(heightDp, anotherHeightDp), 50);
        return new AdSize(screenWidthDp, heightDp);
    }
}

I understand the documentation and previous discussions have highlighted that the anchored banner height is capped at the lesser of 15% of the device's height or 90 density-independent pixels (with a minimum of 50 density-independent pixels), but the internal method used by AdMob Android native SDK suggests a more precise approach that also takes screen width into account.

Request for Enhancement

Given the importance of cross-platform consistency and the need for precise ad layout planning, could the Unity plugin be enhanced to align with the Android SDK's functionality? Implementing a method that provides the actual size of an anchored adaptive banner, including its height, before its creation would be a significant improvement. This feature would not only ensure consistency but also greatly enhance the flexibility and usability of the SDK for Unity developers.

NVentimiglia commented 4 months ago

@sjvc

Thank you for the well formatted feature request. I think this is a reasonable request, and have filed for this internally (b/326123984).

I will close this issue for now, feel free to reopen if you have something more to add.