This guide is intended for publishers integrating ad metadata with the Google Mobile Ads iOS SDK.
Prerequisites
- Google Mobile Ads SDK minimum version 7.41.0.
- Complete the steps in either of the guides below:
Fetching ad metadata
To have an app know more about ads that are served, set the ad to be its own
GADAdMetadataDelegate
. Then you can listen for ad metadata changes by
implementing the adMetadataDidChange:
method on GADAdMetadataDelegate
. Once
this delegate is called, check the adMetadata
property on the ad.
adMetadataDidChange:
is called just after an ad loads or when an ad's
metadata changes asynchronously after it loads. It is not guaranteed that ad
metadata is available at load time, 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 for a rewarded ad:
@interface ViewController () <GADFullScreenContentDelegate, GADAdMetadataDelegate>
@end
@implementation ViewController
- (void)loadRewardedAd {
*request = [ request];
[GADRewardedAd
loadWithAdUnitID:@"ca-app-pub-3940256099942544/4806952744"
request:request
completionHandler:^(GADRewardedAd *ad, NSError *error) {
if (error) {
NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
return;
}
self.rewardedAd = ad;
self.rewardedAd.fullScreenContentDelegate = self;
/// Set the ad to be the delegate of its ad metadata.
self.rewardedAd.adMetadataDelegate = self;
NSLog(@"Rewarded ad loaded.");
}];
}
/#pragma mark GADAdMetadataDelegate implementation
- (void)adMetadataDidChange:(id<GADAdMetadataProvider>)ad {
NSDictionary<NSString*, id> *adMetadata = _rewardedAd.adMetadata;
NSString *adId = adMetadata[@"AdId"];
}
After retrieving the metadata, you can check the Bundle for the keys you care about. Different types of ads might 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, or the empty string 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, or the empty string if not available. |
DealId |
String | The first deal ID present in the wrapper chain for the current ad, starting from the top, or the empty string if this information is 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.
|