---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://ads.yandex.com/helpcenter/en/easy/integration/react-native/advanced-settings/targeting.md
  - https://ads.yandex.com/helpcenter/ru/easy/integration/react-native/advanced-settings/targeting.md
  - https://ads.yandex.com/helpcenter/zh/easy/integration/react-native/advanced-settings/targeting.md
  - href: zh/easy/integration/react-native/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 %}

- 横幅广告

    使用 `adRequest` 进行定向的示例：

    ```JavaScript
    const StickyBannerScreen = () => { // 横幅广告创建素材
    //
    ... 需要状态管理器/其他变量
    //

    // 定向设置对象
    let adRequest = new AdRequest({
        age: '20',
        contextQuery: 'context-query',
        contextTags: ['context-tag'],
        gender: Gender.Male,
        location: new Location(55.734202, 37.588063),
        adTheme: AdTheme.Light,
        parameters: new Map<string, string>([['param1', 'value1'], ['param2', 'value2']]),
    });
    // 定向设置对象

     return (
        <BannerView
            size={adSize!}
            adUnitId={selectedAdNetwork?.adUnitId!}
            adRequest={adRequest} // 传递用于定向的对象
            //
            ... 其他方法和处理程序
            //
        />
     );
    };
    ```

- 插屏和激励广告

    // 使用 `adRequestConfiguration` 进行定向的示例：

    ```JavaScript
    // 修改加载器本身以使用定向功能
    const loadAd = async () => {
    let loader = await InterstitialAdLoader.create()
        .catch((error) => {
            logger.addLog(`Did fail to create the loader with error: ${error}`, setLogs);
            setIsButtonDisabled(false);
            return;
        });

    // 定向设置对象
    let adRequestConfiguration = new AdRequestConfiguration({
        adUnitId: adUnitId,
        age: '20',
        contextQuery: 'context-query',
        contextTags: ['context-tag'],
        gender: Gender.Female,
        location: new Location(55.734202, 37.588063),
        adTheme: AdTheme.Light,
        parameters: new Map<string, string>([['param1', 'value1'], ['param2', 'value2']]),
    });
    // 定向设置对象

    await loader.loadAd(adRequestConfiguration)
        .then((ad) => {
            logger.addLog('Did load', setLogs);
            setAd(ad);
            setButtonLabel('Show ad');
            setIsButtonDisabled(false);
        })
        .catch((error) => {
            logger.addLog(`Did fail to load with error: ${error}`, setLogs);
            setAd(undefined);
            setButtonLabel('Load ad');
            setIsButtonDisabled(false);
        });
    };
    ```

{% endlist %}

#|
||

**参数**

|

**描述**

||
||

`age`

|

以字符串格式显示的用户年龄，例如：“14”、“18”。

||
||

`gender`

|

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

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

||
||

`location`

|

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

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

||
||

`contextQuery`

|

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

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

||
||

`contextTags`

|

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

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

||
|#
