Prebid SDK Utility functions

This page will store any utilities that can used in conjuntion with the Prebid SDK.

Find Prebid Creative Size

Prebid created findPrebidCreativeSize to address a bug in the Google Ad Manager ad server (described here) where under certain situations ads fail to render. It is recommended all Google Ad Manager integrations resize all ads served based on the winning Prebid creative size findPrebidCreativeSize.

Functionally speaking a Google Ad Manager listener is created to listen for the onAdLoaded event (when an ad is recieved) to determine the winning Prehbid ad size to determine how to resize the ad slot.

Util

Supported in Prebid SDK version 1.1.2.

void findPrebidCreativeSize(@Nullable View adView, final CreativeSizeCompletionHandler completionHandler)

Exmple:

dfpAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        super.onAdLoaded();

        Util.findPrebidCreativeSize(dfpAdView, new Util.CreativeSizeCompletionHandler() {
            @Override
            public void onSize(final Util.CreativeSize size) {
                if (size != null) {
                    dfpAdView.setAdSizes(new AdSize(size.getWidth(), size.getHeight()));
                }
            }
        });
    }
});

AdViewUtils

Improved findPrebidCreativeSize solution supported in Prebid SDK version 1.2+.

void findPrebidCreativeSize(@Nullable View adView, final PbFindSizeListener handler)

Example:

dfpAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        super.onAdLoaded();

        AdViewUtils.findPrebidCreativeSize(dfpAdView, new AdViewUtils.PbFindSizeListener() {
            @Override
            public void success(int width, int height) {
                dfpAdView.setAdSizes(new AdSize(width, height));
            }

            @Override
            public void failure(@NonNull PbFindSizeError error) {
                Log.d("MyTag", "error: " + error);
            }
        });

    }
});