Ad targeting
Targeting is used to set precise parameters so that users can see ads that are more relevant to them. Here's an example of using targeting:
|
Format |
Class |
|
|
|
|
Example of targeting with adRequest:
const StickyBannerScreen = () => { // Banner creation asset
//
... required state managers / other variables
//
// Targeting setup object
let adRequest = new AdRequest({
age: '20',
contextQuery: 'context-query',
contextTags: ['context-tag'],
gender: Gender.Male,
location: new Location(55.734202, 37.588063),
adTheme: AdTheme.Light,
parameters: new Map<string, string>([['param1', 'value1'], ['param2', 'value2']]),
});
// Targeting setup object
return (
<BannerView
size={adSize!}
adUnitId={selectedAdNetwork?.adUnitId!}
adRequest={adRequest} // Passing the object for targeting
//
... other methods and handlers
//
/>
);
};
Example of targeting with adRequestConfiguration:
// Modify the loader itself to use targeting
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;
});
// Targeting setup object
let adRequestConfiguration = new AdRequestConfiguration({
adUnitId: adUnitId,
age: '20',
contextQuery: 'context-query',
contextTags: ['context-tag'],
gender: Gender.Female,
location: new Location(55.734202, 37.588063),
adTheme: AdTheme.Light,
parameters: new Map<string, string>([['param1', 'value1'], ['param2', 'value2']]),
});
// Targeting setup object
await loader.loadAd(adRequestConfiguration)
.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”. |