Skip to content

Commit 1f72e76

Browse files
Nicholas Ventimigliacopybara-github
authored andcommitted
Updated age treatment snippets.
PiperOrigin-RevId: 940697284
1 parent 7a83543 commit 1f72e76

2 files changed

Lines changed: 115 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: 24 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;
@@ -64,5 +66,27 @@ private void SetUnspecifiedAgeTreatment()
6466
MobileAds.SetRequestConfiguration(requestConfiguration);
6567
// [END set_unspecified_age_treatment]
6668
}
69+
70+
private void SetUnderAgeOfConsent()
71+
{
72+
// [START set_under_age_of_consent]
73+
RequestConfiguration requestConfiguration = new RequestConfiguration
74+
{
75+
TagForUnderAgeOfConsent = TagForUnderAgeOfConsent.True
76+
};
77+
MobileAds.SetRequestConfiguration(requestConfiguration);
78+
// [END set_under_age_of_consent]
79+
}
80+
81+
private void SetAdContentFiltering()
82+
{
83+
// [START set_ad_content_filtering]
84+
RequestConfiguration requestConfiguration = new RequestConfiguration
85+
{
86+
MaxAdContentRating = MaxAdContentRating.G
87+
};
88+
MobileAds.SetRequestConfiguration(requestConfiguration);
89+
// [END set_ad_content_filtering]
90+
}
6791
}
6892
}

0 commit comments

Comments
 (0)