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 with AdRequest:

const StickyBannerScreen = () => {
// ... state and layout ...

let adRequest = new AdRequest({
    age: '20',
    contextQuery: 'context-query',
    contextTags: ['context-tag'],
    gender: Gender.Male,
    location: new Location(55.734202, 37.588063),
});

 return (
    <BannerView
        size={adSize!}
        adUnitId={selectedAdNetwork?.adUnitId!}
        adRequest={adRequest}
    />
 );
};

Example of targeting with loadAd:

const loadAd = async () => {
let loader = await InterstitialAdLoader.create()
    .catch((error) => {
        logger.addLog(`Did fail to create the loader with error: ${error}`, setLogs);
        setIsButtonDisabled(false);
        return;
    });

await loader.loadAd({
    adUnitId: adUnitId,
    targeting: {
        age: '20',
        contextQuery: 'context-query',
        contextTags: ['context-tag'],
        gender: Gender.Female,
        location: new Location(55.734202, 37.588063),
    },
})
    .then((ad) => {
        logger.addLog('Did load', setLogs);
        setAd(ad);
        setButtonLabel('Show ad');
        setIsButtonDisabled(false);
    })
    .catch((error) => {
        logger.addLog(`Did fail to load with error: ${error}`, setLogs);
        setAd(undefined);
        setButtonLabel('Load ad');
        setIsButtonDisabled(false);
    });
};

Parameter

Description

age

User's age in string format, for example: “14”, “18”.

gender

The user's gender: “male”, “female”.

You can use the Gender object to get a valid string.

location

User location determined by the app.

Before using this feature, make sure to obtain user consent and set MobileAds.setLocationConsent(true) in the SDK.

contextQuery

The user's search query in the app.

contextTags

The keywords from the page the user was viewing.