Ad targeting
Targeting is used to set precise parameters so that users can see ads that are more relevant to them. Below is an example aligned with 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 |
|
|
The user's age in string format, for example: “14”, “18”. |
|
|
The user's gender: “male”, “female”. You can use the |
|
|
The user's location as detected by your app. To use location data, you must obtain the user's consent and then set |
|
|
The user's search query in the app. For instance, if the user searched for a car, this parameter might look like this: “Buy a used car in Moscow”. |
|
|
The keywords from the page the user was viewing. These could be the page's title, parts of its content, tags, and other elements. For a page with a car search, this parameter might look like this: “buy a car”, “used car”, “in Moscow”. |