Skip to content

Commit 0e62f29

Browse files
Nicholas Ventimigliacopybara-github
authored andcommitted
Updated native ad option snippets.
PiperOrigin-RevId: 925465584
1 parent f2f6a37 commit 0e62f29

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.android.gms.snippets;
16+
17+
import android.content.Context;
18+
import android.util.Log;
19+
import com.google.android.gms.ads.AdListener;
20+
import com.google.android.gms.ads.AdLoader;
21+
import com.google.android.gms.ads.nativead.NativeAdOptions;
22+
23+
/** Java code snippets for the developer guide. */
24+
final class AdManagerNativeAdOptionsSnippets {
25+
26+
private static final String AD_UNIT_ID = "/21775744923/example/native";
27+
private static final String TAG = "AdManagerNativeAdOptionsSnippets";
28+
29+
private void setCustomClickGesture(Context context) {
30+
// [START set_custom_click_gesture]
31+
NativeAdOptions adOptions =
32+
new NativeAdOptions.Builder()
33+
.enableCustomClickGestureDirection(
34+
NativeAdOptions.SWIPE_GESTURE_DIRECTION_RIGHT, /* tapsAllowed= */ true)
35+
.build();
36+
37+
// /21775744923/example/native is a sample ad unit ID that has custom click
38+
// gestures enabled.
39+
AdLoader.Builder builder =
40+
new AdLoader.Builder(context, AD_UNIT_ID).withNativeAdOptions(adOptions);
41+
// [END set_custom_click_gesture]
42+
}
43+
44+
private void setSwipeGesture(Context context) {
45+
// [START set_swipe_gesture]
46+
AdLoader adLoader =
47+
new AdLoader.Builder(context, AD_UNIT_ID)
48+
.withAdListener(
49+
new AdListener() {
50+
// Called when a swipe gesture click is recorded.
51+
@Override
52+
public void onAdSwipeGestureClicked() {
53+
// Called when a swipe gesture click is recorded.
54+
Log.d(TAG, "A swipe gesture click has occurred.");
55+
}
56+
57+
@Override
58+
public void onAdClicked() {
59+
// Called when a swipe gesture click or a tap click is recorded, as
60+
// configured in NativeAdOptions.
61+
Log.d(TAG, "A swipe gesture click or a tap click has occurred.");
62+
}
63+
})
64+
.build();
65+
// [END set_swipe_gesture]
66+
}
67+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.android.gms.snippets
16+
17+
import android.content.Context
18+
import android.util.Log
19+
import com.google.android.gms.ads.AdListener
20+
import com.google.android.gms.ads.AdLoader
21+
import com.google.android.gms.ads.nativead.NativeAdOptions
22+
23+
/** Kotlin code snippets for the developer guide. */
24+
class AdManagerNativeAdOptionsSnippets {
25+
26+
private fun setCustomClickGesture(context: Context) {
27+
// [START set_custom_click_gesture]
28+
val adOptions =
29+
NativeAdOptions.Builder()
30+
.enableCustomClickGestureDirection(NativeAdOptions.SWIPE_GESTURE_DIRECTION_RIGHT, true)
31+
.build()
32+
33+
// /21775744923/example/native is a sample ad unit ID that has custom click
34+
// gestures enabled.
35+
val builder = AdLoader.Builder(context, AD_UNIT_ID).withNativeAdOptions(adOptions)
36+
// [END set_custom_click_gesture]
37+
}
38+
39+
private fun setSwipeGesture(context: Context) {
40+
// [START set_swipe_gesture]
41+
val adLoader =
42+
AdLoader.Builder(context, AD_UNIT_ID)
43+
.withAdListener(
44+
object : AdListener() {
45+
override fun onAdSwipeGestureClicked() {
46+
// Called when a swipe gesture click is recorded.
47+
Log.d(TAG, "A swipe gesture click has occurred.")
48+
}
49+
50+
override fun onAdClicked() {
51+
// Called when a swipe gesture click or a tap click is recorded, as
52+
// configured in NativeAdOptions.
53+
Log.d(TAG, "A swipe gesture click or a tap click has occurred.")
54+
}
55+
}
56+
)
57+
.build()
58+
// [END set_swipe_gesture]
59+
}
60+
61+
private companion object {
62+
const val AD_UNIT_ID = "/21775744923/example/native"
63+
const val TAG = "AdManagerNativeAdOptionsSnippets"
64+
}
65+
}

0 commit comments

Comments
 (0)