Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Updated native ad option snippets.
PiperOrigin-RevId: 925465584
  • Loading branch information
Nicholas Ventimiglia authored and copybara-github committed Jun 2, 2026
commit a82ae4feb026efc106376e6d4f107d815482f9c2
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// Copyright (C) 2026 Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <UIKit/UIKit.h>
#import <GoogleMobileAds/GoogleMobileAds.h>

NS_ASSUME_NONNULL_BEGIN

// Replace this ad unit ID with your own ad unit ID.
static NSString *const kNativeAdUnitID = @"/21775744923/example/native";

// Demonstrates how to use custom click gesture options for native ads in Google Ad Manager.
@interface AdManagerNativeAdOptionsSnippets : UIViewController <GADNativeAdDelegate>
// The ad loader.
@property(nonatomic, strong) GADAdLoader *adLoader;
@end

@implementation AdManagerNativeAdOptionsSnippets

// Sets up a GADAdLoader with custom swipe gesture options.
- (void)setCustomSwipeGesture {
// [START set_custom_swipe_gesture]
GADNativeAdCustomClickGestureOptions *swipeGestureOptions =
[[GADNativeAdCustomClickGestureOptions alloc]
initWithSwipeGestureDirection:UISwipeGestureRecognizerDirectionRight
tapsAllowed:YES];

self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:kNativeAdUnitID
rootViewController:self
adTypes:@[ GADAdLoaderAdTypeNative ]
options:@[ swipeGestureOptions ]];
// [END set_custom_swipe_gesture]
}

#pragma mark - GADNativeAdDelegate

// Called when a swipe gesture click is recorded, as configured in
// GADNativeAdCustomClickGestureOptions.
// [START custom_swipe_gesture_delegate]
- (void)nativeAdDidRecordSwipeGestureClick:(GADNativeAd *)nativeAd {
NSLog(@"A swipe gesture click has occurred.");
}

// Called when a swipe gesture click or a tap click is recorded.
- (void)nativeAdDidRecordClick:(GADNativeAd *)nativeAd {
NSLog(@"A swipe gesture click or tap click has occurred.");
}
// [END custom_swipe_gesture_delegate]

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Copyright (C) 2026 Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import GoogleMobileAds

private class AdManagerNativeAdOptionsSnippets: UIViewController, NativeAdDelegate {

// Replace this ad unit ID with your own ad unit ID.
private let nativeAdUnitID = "/21775744923/example/native"
private var adLoader: AdLoader?

private func setCustomSwipeGesture() {
// [START set_custom_swipe_gesture]
var options: [GADAdLoaderOptions]? = nil
adLoader = AdLoader(
adUnitID: nativeAdUnitID,
rootViewController: self,
adTypes: [.native],
options: options)
// [END set_custom_swipe_gesture]
}

// [START custom_swipe_gesture_delegate]
/// Notifies the delegate that a swipe gesture click was recorded, as configured in
/// NativeAdCustomClickGestureOptions.
func nativeAdDidRecordSwipeGestureClick(_ nativeAd: NativeAd) {
print("A swipe gesture click has occurred.")
}

/// Notifies the delegate that a swipe gesture click or a tap click was recorded.
func nativeAdDidRecordClick(_ nativeAd: NativeAd) {
print("A swipe gesture click or tap click has occurred.")
}
// [END custom_swipe_gesture_delegate]
}
Loading