Custom Mute This Ad for Native Ads

The "Mute This Ad" feature provides users with the ability to close or to stop seeing ads and signal which ads aren't interesting to them. With GADUnifiedNativeAd, you have the option to implement your own UI to enable a user to mute the native ad. Here's how it's done:

1. Request custom Mute This Ad

The first step is to request the custom Mute This Ad feature using the GADNativeMuteThisAdLoaderOptions class.

Swift

adLoader = GADAdLoader(adUnitID: adUnitID, rootViewController: self,
                        adTypes: [ .unifiedNative ],
                        options: [GADNativeMuteThisAdLoaderOptions()])
adLoader.delegate = self
adLoader.load(GADRequest())

Objective-C

GADNativeMuteThisAdLoaderOptions *muteOptions = [GADNativeMuteThisAdLoaderOptions new];
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:TestAdUnit
                                   rootViewController:self
                                              adTypes:@[ kGADAdLoaderAdTypeUnifiedNative ]
                                              options:@[ muteOptions ]];
self.adLoader.delegate = self;
[self.adLoader loadRequest:[GADRequest request]];

2. Check if custom Mute This Ad is available

Once the native ad is loaded, check the isCustomMuteThisAdAvailable property on the native ad. If it's available, show the custom button.

Swift

func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADUnifiedNativeAd){
  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 didReceiveUnifiedNativeAd:
  (GADUnifiedNativeAd *)nativeAd {
  self.nativeAdView.nativeAd = nativeAd;

  if (nativeAd.isCustomMuteThisAdAvailable) {
    [self enableCustomMuteWithReasons:nativeAd.muteThisAdReasons];
  } else {
    [self hideCustomMute];
  }
}

- (void)enableCustomMuteWithReasons:(NSArray *)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.
}

The implementation of the custom mute interface is entirely your decision. You can place a small close button on the ad, or you can provide some other interface for the user to opt to mute the ad.

3. Show the Mute This Ad reasons

If custom Mute This Ad is available, there is an array of GADMuteThisAdReason objects available in muteThisAdReason property on the native ad.

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 may also choose not to display these reasons when the user clicks the close button, and report the mute action directly with no reason.

4. Mute the ad

Muting the ad should involve two actions:

  1. Report the reason for the mute to the native ad
  2. On your user interface, mute/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.
}

5. Receive confirmation of ad mute (optional)

If you want to be notified that reporting the ad mute was successful, you can implement the GADUnifiedNativeAdDelegate method, nativeAdIsMuted:. This method will only be called if the ad was muted successfully.

Send feedback about...

Google Mobile Ads SDK for iOS
Google Mobile Ads SDK for iOS
Need help? Visit our support page.