Ad targeting

Targeting enables passing user and context data to display more relevant ads. Below is an example using the current Yandex Mobile Ads SDK API.

For all ad formats, use AdRequest with optional AdTargeting.

Example of targeting (Swift)

Pass the data via AdTargeting when creating 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)

Loading interstitial or rewarded ads (completion handler)

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

Loading native ads

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's age as a number.

gender

Gender: Gender.male, Gender.female.

location

User location determined by the app.

Before using this feature, make sure to get user consent first, then set up consent passing to the SDK according to your app's privacy policy.

contextQuery

The user's search query in the app.

For example, if a user searched for a car, the parameter might look like this: “Buy a used car in Moscow”.

contextTags

Keywords from the page viewed by the user: title, content snippets, tags, and so on.