广告定位

定位功能支持传递用户和上下文数据,以展示更相关的广告。 以下是使用当前 Yandex Mobile Ads SDK API 的示例:

对于所有广告格式,使用 AdRequest 与可选 AdTargeting。

使用 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}
    />
 );
};

使用 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);
    });
};

参数

描述

age

用户年龄:字符串格式的数字(例如“14”、“18”等)。

gender

用户性别:“男性”、“女性”。

您可以使用 Gender 对象获取有效字符串。

location

用户位置由应用确定。

在使用此功能之前,请确保获得用户同意,并在 SDK 中设置 MobileAds.setLocationConsent(true)。

contextQuery

用户在应用中的搜索查询。

contextTags

用户正在查看的页面中的关键字。

下一篇