Таргетирование рекламы

Таргетирование необходимо для использования точных настроек по подбору более точной рекламы. Пример использования таргетирования:

Формат

Класс

  • Sticky-баннер

  • Inline-баннер

  • Fixed-баннер

AdRequest

  • Межстраничная реклама

  • Реклама с вознаграждением

  • Реклама при открытии приложения

AdRequestConfiguration

BannerComponent.cs

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

        double lat = 60.0, lon = 30.0;

        // Собираем объект Location
        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 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 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 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

Пол пользователя: «male», «female».

Можно использовать объект Gender для получения корректной строки.

location

Локация пользователя, известная в вашем приложении.

Для использования нужно получить согласие пользователя на использование локации и выставить в SDK MobileAds.setLocationConsent(true).

contextQuery

Поисковый запрос пользователя в приложении.

Например, пользователь искал автомобиль. Параметр будет выглядеть так: «Купить легковой автомобиль с пробегом в Москве».

contextTags

Ключевые слова со страницы, которую смотрел пользователь. Это может быть заголовок, часть контента, теги и пр.

Для страницы с поиском автомобиля параметр может выглядеть так: «купить легковой автомобиль», «автомобиль с пробегом», «в Москве».