---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ads.yandex.com/helpcenter/en/easy/integration/unity/advanced-settings/targeting.md
  - https://ads.yandex.com/helpcenter/ru/easy/integration/unity/advanced-settings/targeting.md
  - https://ads.yandex.com/helpcenter/zh/easy/integration/unity/advanced-settings/targeting.md
  - href: zh/easy/integration/unity/advanced-settings/targeting.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://ads.yandex.com/helpcenter/zh/llms.txt

# 广告定位

定位功能用于设置精准的参数，以便用户看到与其更相关的广告。以下是使用定位功能的示例：

#|
||

**格式**

|

**类**

||
||

* 粘性横幅广告

* 内嵌横幅广告

* 固定横幅广告

|

`AdRequest`

||
||

* 插屏广告

* 激励广告

* 开屏广告

|

`AdRequestConfiguration`

||
|#


 {% list tabs %}

- 横幅广告

    BannerComponent.cs

    ```C#
        private void Start()
        {
        if (!string.IsNullOrEmpty(currentAdUnitId))
        {
            ConfigureBanner();

            double lat = 60.0, lon = 30.0;

            // 构建位置对象
            Location location = new Location.Builder()
                .SetLatitude(lat)
                .SetLongitude(lon)
                .Build();

            // 创建定位参数
            var adRequest = new AdRequest.Builder()
                .WithAge("25")
                .WithGender("male") // 或 "female"、"other"
                .WithContextTags(new List<string>() { "games", "unity", "test" })
                .WithContextQuery("user_search_query") // 搜索查询字符串
                .WithLocation(location)
                .WithParameters(new Dictionary<string, string> {
                        { "custom1", "value1" },
                        { "custom2", "value2" }
                })
                .Build();

            banner.LoadAd(adRequest);
        }
        else
        {
            Debug.LogError("Banner configuration failed. Ad Unit ID is missing.");
        }
        }
    ```

- 插屏广告

    InterstitialAdComponent.cs
    ```C#
    private void ConfigureAd()
    {
        double lat = 60.0, lon = 30.0;

        // 构建位置对象
        Location location = new Location.Builder()
            .SetLatitude(lat)
            .SetLongitude(lon)
            .Build();

        AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(CurrentAdUnitId)
                .WithAge("25")
                .WithGender("male") // 或 "female"、"other"
                .WithContextTags(new List<string>() { "games", "unity", "test" })
                .WithContextQuery("user_search_query") // 搜索查询字符串
                .WithLocation(location)
                .WithParameters(new Dictionary<string, string> {
                        { "custom1", "value1" },
                        { "custom2", "value2" }
                }).Build();
        try
        {
            interstitialAdLoader.LoadAd(adRequestConfiguration);
        }
        catch (Exception ex)
        {
            Debug.LogError($"Configuration failed: {ex.Message}");
        }
    }
    ```

- 激励广告

    RewardAdComponent.cs
    ```C#
    private void ConfigureAd()
    {
        double lat = 60.0, lon = 30.0;

        // 构建位置对象
        Location location = new Location.Builder()
            .SetLatitude(lat)
            .SetLongitude(lon)
            .Build();

        AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(CurrentAdUnitId)
                .WithAge("25")
                .WithGender("male") // 或 "female"、"other"
                .WithContextTags(new List<string>() { "games", "unity", "test" })
                .WithContextQuery("user_search_query") // 搜索查询字符串
                .WithLocation(location)
                .WithParameters(new Dictionary<string, string> {
                        { "custom1", "value1" },
                        { "custom2", "value2" }
                }).Build();
        try
        {
            rewardedAdLoader.LoadAd(adRequestConfiguration);
        }
        catch (Exception ex)
        {
            Debug.LogError($"{adName}: Configuration failed: {ex.Message}");
        }
    }
    ```

- 开屏广告

    AppOpenAdComponent.cs
    ```C#
    private void ConfigureAd()
    {
        double lat = 60.0, lon = 30.0;

        // 构建位置对象
        Location location = new Location.Builder()
            .SetLatitude(lat)
            .SetLongitude(lon)
            .Build();

        AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(CurrentAdUnitId)
                .WithAge("25")
                .WithGender("male") // 或 "female"、"other"
                .WithContextTags(new List<string>() { "games", "unity", "test" })
                .WithContextQuery("user_search_query") // 搜索查询字符串
                .WithLocation(location)
                .WithParameters(new Dictionary<string, string> {
                        { "custom1", "value1" },
                        { "custom2", "value2" }
                }).Build();
        try
        {
            appOpenAdLoader.LoadAd(adRequestConfiguration);
        }
        catch (Exception ex)
        {
            OnAdFailedToLoad?.Invoke($"Configuration failed: {ex.Message}");
        }
    }
    ```

{% endlist %}


#|
||

**参数**

|

**描述**

||
||

`age`

|

用户年龄：字符串格式的数字（例如，“14”、“18”等）。

||
||

`gender`

|

用户性别：“男”、“女”。

您可以使用 `Gender` 对象获取有效字符串。

||
||

`location`

|

您的应用检测到的用户位置。

要使用位置数据，您必须获得用户的同意，然后在 SDK 中设置 `MobileAds.setLocationConsent(true)`。

||
||

`contextQuery`

|

用户在应用中的搜索查询。

例如，如果用户搜索汽车，此参数可能如下所示：“在莫斯科购买二手车”。

||
||

`contextTags`

|

用户正在查看的页面中的关键字。可能是页面的标题、页面的部分内容、标记及其他元素。

对于包含汽车搜索的页面，此参数可能如下所示：“购买汽车”、“二手车”、“在莫斯科”。

||
|#
