Ad Metadata

  • This guide explains how to integrate Ad Metadata with the Google Mobile Ads SDK for Android in publisher apps, requiring minimum SDK version 17.0.0 and completed Rewarded Video integration.

  • Publishers can access ad metadata, such as ad ID, title, and duration, by implementing an AdMetadataListener and retrieving the metadata bundle via RewardedVideo.getAdMetadata().

  • onAdMetadataChanged() is triggered when an ad loads or its metadata changes, and it's recommended to wait for this callback before accessing ad metadata as it might not be immediately available.

  • VAST video ads provide specific metadata keys, including AdId, AdTitle, CreativeDurationMs, TraffickingParameters, DealId, AdSystem, CreativeId, MediaURL, and Wrappers, which offer details about the served ad.

  • The Wrappers key is exclusively present in VAST Wrapper ads and contains information about the ad's wrapper chain, while VAST Inline ads lack this key.

Select platform: Android iOS

This guide is intended for publishers integrating Ad Metadata with the Google Mobile Ads SDK for Android.

Prerequisites

  • Minimum version 17.0.0 of the Google Mobile Ads SDK.
  • Complete the steps in Rewarded Video.

Fetching ad metadata

To know more about served ads, listen for ad metadata changes on rewarded video ads.

onAdMetadataChanged() is called just after an ad loads or when its metadata changes asynchronously after it loads. It is not guaranteed that an ad's metadata will be available at the time the ad is loaded, so we recommend waiting for this callback before accessing an ad's metadata.

Here is a code example showing how to retrieve the ad metadata:

Java

RewardedAd.load(this, "/21775744923/example/rewarded", new AdManagerAdRequest.Builder().build(),
    new RewardedAdLoadCallback() {
      @Override
      public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
        mRewardedAd = rewardedAd;
        rewardedAd.setOnAdMetadataChangedListener(new OnAdMetadataChangedListener() {
          @Override
          public void onAdMetadataChanged() {
            Bundle metadata = rewardedAd.getAdMetadata();
            String adId = metadata.getString("AdId");
          }
        });
      }
    });

Kotlin

RewardedAd.load(this, "/21775744923/example/rewarded", AdManagerAdRequest.Builder().build(),
                    object : RewardedAdLoadCallback() {
      override fun onAdLoaded(rewardedAd: RewardedAd) {
        mRewardedAd = rewardedAd
        rewardedAd.onAdMetadataChangedListener = OnAdMetadataChangedListener {
          val metadata = rewardedAd.adMetadata
          val adId = metadata.getString("AdId")
        }
      }
    })

After retrieving the metadata, you can check the Bundle for the keys you care about. Different types of ads may have different ad metadata keys associated with them. VAST video ads have the following keys:

Key Type Description
AdId String The ID of the ad, empty if not available.
AdTitle String The title, empty if not specified.
CreativeDurationMs Integer The selected creative duration in milliseconds, -1 if non-linear.
TraffickingParameters String Trafficking parameters, empty if not available.
DealId String The first deal ID present in the wrapper chain for the current ad, starting from the top--empty if not available.
AdSystem String The source ad server of the ad, empty if not available.
CreativeId String The ID of the selected creative for the ad, empty if not available.
MediaURL String The URL of the selected media.
Wrappers Array The array is populated with elements beginning at the innermost wrapper ad (close to the inline ad) moving outwards to the outermost wrapper ad. Each element in the array is a dictionary that contains the following keys and values.
AdId
String. Ad ID used for wrapper ad, empty if not available.
AdSystem
String. Ad system used for wrapper ad, empty if not available.
CreativeId
String. Creative ID used for wrapper ad, empty if not available.