Banner Ads Banner ads are image-based ads and are the most commonly used ad format on websites. The AdStage SDK supports automatic resizing, slide functionality, and background loading for banner ads.
// HTML์ ์ปจํ
์ด๋ ์ค๋น
// <div id="banner-container"></div>
// SDK ์ด๊ธฐํ (ํ ๋ฒ๋ง)
AdStage. init ({
apiKey: process.env. NEXT_PUBLIC_ADSTAGE_API_KEY
});
// ๊ธฐ๋ณธ ๋ฐฐ๋ ๊ด๊ณ ์์ฑ
AdStage.ads. banner ( 'banner-container' , {
width: '100%' ,
height: 250
});
AdStage.ads. banner ( 'banner-container' , {
width: '100%' ,
height: 250 ,
onClick : ( adData ) => {
console. log ( '๋ฐฐ๋ ๊ด๊ณ ํด๋ฆญ๋จ:' , adData);
// ์ฌ์ฉ์ ์ ์ ๋ก์ง ์ถ๊ฐ ๊ฐ๋ฅ
}
});
Option Type Default Description widthstring | number'100%'Banner width (px or %) heightnumber250Banner height (px) onClickfunctionundefinedCallback function executed on click
Option Type Default Description autoSlidebooleanfalseAuto-slide when multiple ads are present slideIntervalnumber5000Slide interval (milliseconds) adIdstringundefinedSpecify a particular ad ID
Option Type Default Description language'ko' | 'en' | 'ja' | 'zh'undefinedFilter by language deviceType'MOBILE' | 'DESKTOP'undefinedFilter by device country'KR' | 'US' | 'JP' | 'CN' | 'DE'undefinedFilter by country
HTML (CDN) JavaScript (ES6) React Next.js App Next.js Provider
The simplest CDN approach lets you use it directly in HTML.
<! DOCTYPE html >
< html >
< head >
< meta charset = "UTF-8" >
< title >๋ฐฐ๋ ๊ด๊ณ ์์ </ title >
</ head >
< body >
< h1 >๋ด ์น์ฌ์ดํธ</ h1 >
<!-- ๋ฐฐ๋ ๊ด๊ณ ์ปจํ
์ด๋ -->
< div id = "banner-container" style = "width: 100%; height: 250px; border: 1px solid #ddd;" >
๋ก๋ฉ ์ค...
</ div >
<!-- AdStage SDK ๋ก๋ -->
< script src = "https://unpkg.com/@adstage/web-sdk/dist/index.umd.js" ></ script >
< script >
// SDK ์ด๊ธฐํ
AdStage. init ({
apiKey: 'your-api-key'
});
// ๋ฐฐ๋ ๊ด๊ณ ์์ฑ
AdStage.ads. banner ( 'banner-container' , {
width: '100%' ,
height: 250
});
</ script >
</ body >
</ html >
A feature that automatically slides through banner ads when multiple are present.
AdStage.ads. banner ( 'banner-container' , {
width: '100%' ,
height: 250 ,
autoSlide: true , // ์๋ ์ฌ๋ผ์ด๋ ํ์ฑํ
slideInterval: 3000 // 3์ด๋ง๋ค ์ฌ๋ผ์ด๋
});
How to adjust the banner size according to the screen size.
// ๋ฏธ๋์ด ์ฟผ๋ฆฌ๋ฅผ ํ์ฉํ ๋ฐ์ํ ๊ตฌํ
const getResponsiveHeight = () => {
if (window.innerWidth <= 768 ) {
return 100 ; // ๋ชจ๋ฐ์ผ: ๋์ด 100px
} else if (window.innerWidth <= 1024 ) {
return 200 ; // ํ๋ธ๋ฆฟ: ๋์ด 200px
} else {
return 250 ; // ๋ฐ์คํฌํฑ: ๋์ด 250px
}
};
AdStage.ads. banner ( 'banner-container' , {
width: '100%' ,
height: getResponsiveHeight (),
deviceType: window.innerWidth <= 768 ? 'MOBILE' : 'DESKTOP'
});
// ์๋์ฐ ๋ฆฌ์ฌ์ด์ฆ ์ ์ฌ์์ฑ
window. addEventListener ( 'resize' , () => {
// ๊ธฐ์กด ๊ด๊ณ ์ ๊ฑฐ ํ ์๋ก ์์ฑ
AdStage.ads. destroy (slotId);
slotId = AdStage.ads. banner ( 'banner-container' , {
width: '100%' ,
height: getResponsiveHeight (),
deviceType: window.innerWidth <= 768 ? 'MOBILE' : 'DESKTOP'
});
});
Use this when you want to display only a specific banner ad.
AdStage.ads. banner ( 'banner-container' , {
width: '100%' ,
height: 250 ,
adId: 'banner-ad-123' // ํน์ ๊ด๊ณ ID
});
The SDK automatically optimizes the container to fit the image size.
// ์ด๋ฏธ์ง ํฌ๊ธฐ์ ๋ง์ถฐ ์๋ ์กฐ์
AdStage.ads. banner ( 'banner-container' , {
width: '100%' ,
height: 'auto' // ์ด๋ฏธ์ง ๋น์จ์ ๋ง์ถฐ ์๋ ์กฐ์
});
Ads load in the background, so you can receive the slot ID immediately.
// ์ฆ์ ์ฌ๋กฏ ID ๋ฐํ
const slotId = AdStage.ads. banner ( 'banner-container' );
console. log ( '์ฌ๋กฏ ์์ฑ๋จ:' , slotId); // ์ฆ์ ์คํ
// ์ค์ ๊ด๊ณ ๋ ๋น๋๊ธฐ๋ก ๋ก๋๋จ
When the container is removed from the DOM, the ad is also cleaned up automatically.
const slotId = AdStage.ads. banner ( 'banner-container' );
// DOM์์ ์ปจํ
์ด๋ ์ ๊ฑฐ ์ ์๋ ์ ๋ฆฌ๋จ
document. getElementById ( 'banner-container' ). remove ();
// ์๋์ผ๋ก destroy() ํธ์ถํ ํ์ ์์
You can apply styling using the CSS classes that the SDK adds automatically.
/* ๊ด๊ณ ์ปจํ
์ด๋ ๊ธฐ๋ณธ ์คํ์ผ */
.adstage-ad {
position : relative ;
overflow : hidden ;
border-radius : 8 px ;
}
/* ๋ก๋ฉ ์ํ */
.adstage-loading {
opacity : 0.7 ;
background : linear-gradient ( 90 deg , #f0f0f0 25 % , #e0e0e0 50 % , #f0f0f0 75 % );
background-size : 200 % 100 % ;
animation : loading 1.5 s infinite ;
}
@keyframes loading {
0% { background-position : 200 % 0 ; }
100% { background-position : -200 % 0 ; }
}
/* ๋ก๋ฉ ์๋ฃ */
.adstage-loaded {
opacity : 1 ;
transition : opacity 0.3 s ease ;
}
/* ์ค๋ฅ ์ํ */
.adstage-error {
border : 1 px solid #ff6b6b ;
background-color : #ffe0e0 ;
}
// ๋ชจ๋ ์ฌ๋กฏ ํ์ธ
const allSlots = AdStage.ads. getAllSlots ();
console. log ( '์ ์ฒด ๊ด๊ณ ์ฌ๋กฏ:' , allSlots);
// ํน์ ์ฌ๋กฏ ํ์ธ
const slot = AdStage.ads. getSlotById (slotId);
console. log ( '์ฌ๋กฏ ์ ๋ณด:' , slot);