Skip to content

Commit 34fefdc

Browse files
Nicholas Ventimigliacopybara-github
authored andcommitted
Updated age treatment snippets.
PiperOrigin-RevId: 940697284
1 parent 1c59495 commit 34fefdc

2 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2026 Google LLC
2+
3+
using System.Collections.Generic;
4+
using GoogleMobileAds.Api;
5+
using GoogleMobileAds.Api.AdManager;
6+
using UnityEngine;
7+
8+
namespace GoogleMobileAds.Snippets
9+
{
10+
/// <summary>
11+
/// Code snippets used for the developer guides.
12+
/// </summary>
13+
internal class AdRequestSnippets
14+
{
15+
private void AddNetworkExtras()
16+
{
17+
// [START add_network_extras]
18+
var adRequest = new AdRequest();
19+
adRequest.Extras.Add("collapsible", "bottom");
20+
// [END add_network_extras]
21+
}
22+
23+
private void AddCustomTargeting()
24+
{
25+
// [START add_custom_targeting]
26+
// Example: Pass custom targeting "age=25".
27+
AdManagerAdRequest newRequest = new AdManagerAdRequest
28+
{
29+
CustomTargeting = new Dictionary<string, string>
30+
{
31+
{ "age", "25" }
32+
}
33+
};
34+
// [END add_custom_targeting]
35+
}
36+
37+
private void AddCustomTargetingAsList()
38+
{
39+
// [START add_custom_targeting_as_list]
40+
AdManagerAdRequest newRequest = new AdManagerAdRequest
41+
{
42+
CustomTargeting = new Dictionary<string, string>
43+
{
44+
{ "age", "24, 25, 26" }
45+
}
46+
};
47+
// [END add_custom_targeting_as_list]
48+
}
49+
50+
private void AddCategoryExclusions()
51+
{
52+
// [START add_category_exclusions]
53+
AdManagerAdRequest newRequest = new AdManagerAdRequest
54+
{
55+
CategoryExclusions = new HashSet<string>
56+
{
57+
"automobile",
58+
"boat"
59+
}
60+
};
61+
// [END add_category_exclusions]
62+
}
63+
64+
private void SetPublisherProvidedId()
65+
{
66+
// [START set_publisher_provided_id]
67+
AdManagerAdRequest newRequest = new AdManagerAdRequest
68+
{
69+
PublisherProvidedId = "AB123456789"
70+
};
71+
// [END set_publisher_provided_id]
72+
}
73+
74+
private void SetPublisherProvidedSignals()
75+
{
76+
// [START set_publisher_provided_signals]
77+
AdManagerAdRequest newRequest = new AdManagerAdRequest
78+
{
79+
Extras = new Dictionary<string, string>
80+
{
81+
// Set the demographic to an audience with an "Age Range" of 30-34
82+
// and an interest in mergers and acquisitions.
83+
{ "IAB_AUDIENCE_1_1", "1, 2, 3, 4, 5" },
84+
// Set the content to sedan, station wagon and SUV automotive values.
85+
{ "IAB_AUDIENCE_2_2", "6, 7, 8, 9, 10" }
86+
}
87+
};
88+
// [END set_publisher_provided_signals]
89+
}
90+
}
91+
}

samples/HelloWorld/Assets/Snippets/RequestConfigurationSnippets.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright 2026 Google LLC
2+
13
using UnityEngine;
24
using GoogleMobileAds.Api;
35
using System.Collections.Generic;
@@ -28,5 +30,38 @@ private void SetTestDeviceIds()
2830
MobileAds.SetRequestConfiguration(requestConfiguration);
2931
// [END set_request_configuration]
3032
}
33+
34+
private void SetChildAgeTreatment()
35+
{
36+
// [START set_child_age_treatment]
37+
RequestConfiguration requestConfiguration = new RequestConfiguration
38+
{
39+
AgeRestrictedTreatment = AgeRestrictedTreatment.Child
40+
};
41+
MobileAds.SetRequestConfiguration(requestConfiguration);
42+
// [END set_child_age_treatment]
43+
}
44+
45+
private void SetUnderAgeOfConsent()
46+
{
47+
// [START set_under_age_of_consent]
48+
RequestConfiguration requestConfiguration = new RequestConfiguration
49+
{
50+
TagForUnderAgeOfConsent = TagForUnderAgeOfConsent.True
51+
};
52+
MobileAds.SetRequestConfiguration(requestConfiguration);
53+
// [END set_under_age_of_consent]
54+
}
55+
56+
private void SetAdContentFiltering()
57+
{
58+
// [START set_ad_content_filtering]
59+
RequestConfiguration requestConfiguration = new RequestConfiguration
60+
{
61+
MaxAdContentRating = MaxAdContentRating.G
62+
};
63+
MobileAds.SetRequestConfiguration(requestConfiguration);
64+
// [END set_ad_content_filtering]
65+
}
3166
}
3267
}

0 commit comments

Comments
 (0)