广告定位

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

格式

  • 粘性横幅广告

  • 内嵌横幅广告

  • 固定横幅广告

AdRequest

  • 插屏广告

  • 激励广告

  • 开屏广告

AdRequestConfiguration

BannerComponent.cs

    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

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

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

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}");
    }
}

参数

描述

age

用户年龄:字符串格式的数字(例如,“14”、“18”等)。

gender

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

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

location

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

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

contextQuery

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

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

contextTags

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

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

下一篇