[この広告を非表示] 機能では、ユーザーが広告を閉じたり表示を停止したりして、興味がない広告がどれかを示唆できます。この広告非表示機能のデフォルトの(カスタマイズされていない)バージョンは次のような形式になります。
GADUnifiedNativeAd
を使用すると、ネイティブ広告を非表示にする機能を独自のユーザー インターフェースで提供できます。手順は次のとおりです。
カスタムの広告非表示機能をリクエストする
まず、GADNativeMuteThisAdLoaderOptions
クラスを使用して、カスタムの [この広告を非表示] 機能をリクエストします。
Swift
adLoader = GADAdLoader(adUnitID: "[AD_UNIT_ID]", rootViewController: self, adTypes: [ .unifiedNative ], 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:@[ kGADAdLoaderAdTypeUnifiedNative ] options:@[ muteOptions ]]; self.adLoader.delegate = self; [self.adLoader loadRequest:[GADRequest request]];
カスタムの広告非表示機能が利用可能かどうかを確認する
ネイティブ広告が読み込まれたら、そのネイティブ広告の isCustomMuteThisAdAvailable
プロパティを確認し、広告非表示機能が利用可能な場合は、カスタムボタンを表示します。
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<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. }
カスタムの広告非表示機能のインターフェースは、ご自身で自由に決められます。広告に小さな閉じるボタンを配置しても、広告を非表示にするための別のインターフェースをユーザーに提供してもかまいません。
広告を非表示にする理由を表示する
カスタムの広告非表示機能が利用可能な場合には、ネイティブ広告の muteThisAdReason
プロパティに GADMuteThisAdReason
オブジェクトの配列が存在し、そのオブジェクトの reasonDescription プロパティに非表示にする理由の文字列を含めることができます。
ベスト プラクティスとして、これらの文字列を表示して、ユーザーが広告を非表示にする理由を選べるようにすることをおすすめします。ユーザーが理由のひとつをクリックすると、広告を非表示にしたことを、選択した理由とともにレポートできます。
また、ユーザーが閉じるボタンをクリックした際にこれらの理由を表示しないようにして、理由なしで広告非表示のアクションをレポートすることもできます。
広告を非表示にする
広告の非表示では、次の 2 つのアクションを組み込みます。
- そのネイティブ広告に非表示の理由を通知する
- 独自のユーザー インターフェースで、任意の方法で広告をミュートまたは非表示にする
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. }
広告非表示の確認を受け取る(省略可)
広告の非表示が完了したときに通知を受け取りたい場合は、GADUnifiedNativeAdDelegate
メソッドの nativeAdIsMuted:
を実装できます。このメソッドは、広告の非表示が正常に行われた場合にのみ呼び出されます。