헤더 비딩 적용
Prebid.js, Amazon UAM을 통한 HeaderBidding을 지원합니다.
1. Prebid.js 연동
adSlot.setPbjsBidTargeting(pbjsTargeting)
을 사용하여 Prebid.js 비딩 응답 결과를 설정합니다.
<script async src="https://ssl.pstatic.net/tveta/libs/glad/prod/gfp-core.js"></script>
<script async src="//acdn.adnxs.com/prebid/not-for-prod/prebid.js"></script>
<script>
// NAM SDK 초기화 & adSlot 설정
window.gladsdk = window.gladsdk || { cmd: [] };
window.gladsdk.cmd.push(function () {
window.gladsdk.defineAdSlot({
adUnitId: 'GFP ad slot adUnitId',
adSlotElementId: 'GFP ad slot adSlotElementId',
});
window.gladsdk.defineAdSlot({
adUnitId: 'GFP ad slot adUnitId',
adSlotElementId: 'GFP ad slot adSlotElementId',
});
});
// Prebid의 비딩 요청 타임아웃
var PREBID_TIMEOUT = 1000;
// Prebid를 이용한 광고 렌더링 전체의 타임아웃
var FAILSAFE_TIMEOUT = 3000;
// pbjs 라이브러리 초기화
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
// Prebid 비딩 유닛 설정
var pbAdUnits = [
{
code: 'GFP ad slot adSlotElementId', // example: div-1
mediaTypes: {
banner: {
sizes: [
[width, height],
[width, height],
], //example: [[300,250], [300,600]]
},
},
bids: [
{
bidder: 'appnexus',
params: {
placementId: 13144370,
},
},
],
},
{
code: 'GFP ad slot adSlotElementId', // example: div-2
mediaTypes: {
banner: {
sizes: [[width, height]], //example: [[728,90]]
},
},
bids: [
{
bidder: 'appnexus',
params: {
placementId: 13144370,
},
},
],
},
];
// Prebid.js를 이용한 렌더링 전체에 대한 타이머
var timer = setTimeout(function () {
window.gladsdk.cmd.push(function () {
window.gladsdk.refreshAdSlots();
});
}, FAILSAFE_TIMEOUT);
// Prebid 비딩 요청
pbjs.que.push(function () {
pbjs.addAdUnits(pbAdUnits);
pbjs.requestBids({
bidsBackHandler: function () {
window.gladsdk.cmd.push(function () {
clearTimer(timer);
var bidAllUnits = pbjs.getBidResponses();
// Prebid의 비딩 결과를 각 광고 유닛별로 NAM SDK adSlot에 설정
Object.keys(bidAllUnits).forEach(function (adSlotElementId) {
var pbjsBids = pbjs.getBidResponsesForAdUnitCode(adSlotElementId).bids;
var adSlot = window.gladsdk.findAdSlot(adSlotElementId);
adSlot.setPbjsBidTargeting(pbjsBids);
});
// NAM SDK의 모든 광고 refresh
window.gladsdk.refreshAdSlots();
});
},
timeout: PREBID_TIMEOUT,
});
});
</script>
2. Amazon UAM 연동
adSlot.setApsBidTargeting(apsTargeting)
을 사용하여 Amazon UAM 비딩 응답 결과를 설정합니다.
<script async src="https://ssl.pstatic.net/tveta/libs/glad/prod/gfp-core.js"></script>
<script>
//apstag.js 로드
!(function (a9, a, p, s, t, A, g) {
if (a[a9]) return;
function q(c, r) {
a[a9]._Q.push([c, r]);
}
a[a9] = {
init: function () {
q('i', arguments);
},
fetchBids: function () {
q('f', arguments);
},
setDisplayBids: function () {},
targetingKeys: function () {
return [];
},
_Q: [],
};
A = p.createElement(s);
A.async = !0;
A.src = t;
g = p.getElementsByTagName(s)[0];
g.parentNode.insertBefore(A, g);
})('apstag', window, document, 'script', '//c.amazon-adsystem.com/aax2/apstag.js');
// NAM SDK 초기화 & adSlot 설정
window.gladsdk = window.gladsdk || { cmd: [] };
window.gladsdk.cmd.push(function () {
window.gladsdk.defineAdSlot({
adUnitId: 'GFP ad slot adUnitId',
adSlotElementId: 'GFP ad slot adSlotElementId',
});
window.gladsdk.defineAdSlot({
adUnitId: 'GFP ad slot adUnitId',
adSlotElementId: 'GFP ad slot adSlotElementId',
});
});
// apstag.js 라이브러리 초기화
apstag.init({
pubID: 'xxxx', // APS Tag pub ID
});
// apstag.js 비딩 요청
apstag.fetchBids(
{
slots: [
{
slotID: 'GFP ad slot adSlotElementId',
slotName: 'GFP ad slot adUnitId',
sizes: [
[width, height],
[width, height],
], //example: [[300,250], [300,600]]
},
{
slotID: 'GFP ad slot adSlotElementId',
slotName: 'GFP ad slot adUnitId',
sizes: [[width, height]], //example: [[728,90]]
},
],
timeout: 2e3,
},
function (apsBids) {
window.gladsdk.cmd.push(function () {
// apsbid.js의 비딩 결과를 각 광고 유닛별로 NAM SDK adSlot에 설정
apsBids.forEach(function (apsBid) {
var adSlot = window.gladsdk.findAdSlot(apsBid.slotID);
adSlot.setApsBidTargeting(apsBid);
});
// NAM SDK의 모든 광고 refresh
window.gladsdk.refreshAdSlots();
});
}
);
</script>