The "Mute This Ad" feature lets users close or stop seeing a particular ad, and signal which ads they aren't interested in. Here's how the feature appears on a typical ad:
With GADNativeAd
, you can implement a custom UI to mute
native ads. This guide shows you how.
Request custom Mute This Ad
The first step is to enable the custom Mute This Ad feature using
the GADNativeMuteThisAdLoaderOptions
class when making an ad request.
Swift
adLoader = GADAdLoader(adUnitID: "[AD_UNIT_ID]", rootViewController: self, adTypes: [ .native ], options: [GADNativeMuteThisAdLoaderOptions()]) adLoader.delegate = self adLoader.load(GADRequest())
Objective-C
GADNativeMuteThisAdLoaderOptions *muteOptions = [GADNativeMuteThisAdLoaderOptions new]; self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:"[AD_UNIT_ID]" rootViewController:self adTypes:@[ GADAdLoaderAdTypeNative ] options:@[ muteOptions ]]; self.adLoader.delegate = self; [self.adLoader loadRequest:[GADRequest request]];
Show the Mute This Ad reasons
Once the native ad is loaded, check the isCustomMuteThisAdAvailable
property of the native ad.
If Mute This Ad is available, you can proceed to implement a custom mute
interface, such as a button or gesture for the user to mute or close the ad.
You also have access to an array of GADMuteThisAdReason
objects in the muteThisAdReasons
property of the native ad. GADMuteThisAdReason
has a reasonDescription
property that provides a displayable string.
As a best practice, we recommend displaying these reasons to the user and allowing them to select their reason for muting the ad. When the user clicks on one of the reasons, you should report the ad mute with the selected reason.
You can also choose to not display these reasons when the user clicks the close button, and report the mute action directly with no reason.
Swift
func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd){ nativeAdView.nativeAd = nativeAd if (nativeAd.isCustomMuteThisAdAvailable) { enableCustomMute(nativeAd.muteThisAdReasons) } else { hideCustomMute() } ... } func enableCustomMute(_ reasons:[GADMMuteThisAdReason]) { // TODO: This method should show your custom mute button and provide the list // of reasons to the interface that are to be displayed when the user mutes // the ad. } func hideCustomMute() { //TODO: Remove / hide the custom mute button from your user interface. }
Objective-C
- (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd: (GADNativeAd *)nativeAd { self.nativeAdView.nativeAd = nativeAd; if (nativeAd.isCustomMuteThisAdAvailable) { [self enableCustomMuteWithReasons:nativeAd.muteThisAdReasons]; } else { [self hideCustomMute]; } } - (void)enableCustomMuteWithReasons:(NSArray<GADMuteThisAdReason *> *)reasons { // TODO: This method should show your custom mute button and provide the list // of reasons to the interface that are to be displayed when the user mutes the // ad. } - (void)hideCustomMute { // TODO: Remove / hide the custom mute button from your user interface. }
Mute the ad
Muting the ad should involve two actions:
- Report the reason for the mute to the native ad.
- On your UI, mute or hide the ad yourself in your preferred manner.
Swift
func muteAdDialogDidSelect(reason: GADMuteThisAdReason) { // Report the mute action and reason to the ad. nativeAdView.nativeAd?.muteThisAd(with: reason) muteAd() } func muteAd() { // TODO: Mute / hide the ad in your preferred manner. }
Objective-C
- (void)muteAdDialogDidSelectReason:(GADMuteThisAdReason *)reason { // Report the mute action and reason to the ad. [self.nativeAdView.nativeAd muteThisAdWithReason:reason]; [self muteAd]; } - (void)muteAd { // TODO: Mute / hide the ad in your preferred manner. }
Receive confirmation of ad mute (optional)
If you want to be notified that reporting the ad mute was successful, you can
implement the nativeAdIsMuted:
delegate method on GADNativeAdDelegate
. This method is called only after
an ad is successfully muted.