Ad targeting

Targeting lets you pass user and context data so users see more relevant ads. Below is an example aligned with the current Yandex Mobile Ads SDK API.

For all ad formats, use AdRequest with optional AdTargeting.

Targeting example (Swift)

Pass user information using AdTargeting when you create an AdRequest:

let targeting = AdTargeting(
    age: 20,
    gender: .male,
    location: CLLocation(latitude: 55.7558, longitude: 37.6173),
    contextQuery: "gaming, rewarded, level_up",
    contextTags: ["games", "ios", "test"]
)
let request = AdRequest(adUnitID: "your_block_id", targeting: targeting)

Interstitial or rewarded load (completion handler)

interstitialAdLoader.loadAd(with: request) { result in
    switch result {
    case .success(let ad):
        self.interstitialAd = ad
    case .failure:
        break
    }
}

Native load

let options = NativeAdOptions()
adLoader.loadAd(with: request, options: options) { result in
    switch result {
    case .success(let ad):
        break
    case .failure:
        break
    }
}
bannerAdView.loadAd(with: request)

Parameter

Description

age

User age as a number.

gender

User gender: Gender.male, Gender.female.

location

The user location as detected by your app.

To use location data, obtain the user's consent and configure consent in the SDK according to your app's privacy flow.

contextQuery

The user's search query in the app.

For instance, if the user searched for a car, the parameter might look like "Buy a used car in Moscow".

contextTags

Keywords from the page the user was viewing. These could be the page's title, parts of its content, tags, and other elements.