Ad targeting

The SDK API lets you add extra information about the user. Contextual data in the request can significantly improve ad quality and increase your revenue.

Set up targeting

To pass targeting parameters, use the AdTargeting class. The AdTargeting object is passed to the AdRequest constructor for all ad formats.

You can provide the following information about the user:

Parameter

Description

age

User's age: a number in string format ("14", "18", and so on).

gender

User's gender: set as one of the Gender enumeration values.

Use the Gender.MALE and Gender.FEMALE constants to get a valid string.

location

The user's location as known in your app, passed using the Location class.

Before setting this parameter, obtain the user's consent and pass permission to use location to the SDK using the YandexAds.SetLocationTracking method.

contextQuery

The user's search query in the app.

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

contextTags

Keywords from the page the user was viewing. These can be a title, part of the content, tags, and so on.

For a car search page, the parameter might look like "Buy a car", "used car", "in Moscow".

Targeting examples

AdTargeting targeting = new AdTargeting(
    age: "20",
    gender: Gender.FEMALE,
    location: new Location.Builder()
        .SetLatitude(55.734202)
        .SetLongitude(37.588063)
        .SetHorizontalAccuracy(100)
        .Build(),
    contextQuery: "context-query",
    contextTags: new List<string> { "context-tag" });

AdRequest adRequest = new AdRequest(
    "your_block_id",
    targeting: targeting
);