StageUp
Web SDKAdvertisements

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.

๐ŸŽฏ Basic Usage

Simple Banner Ad

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

Handling Click Events

AdStage.ads.banner('banner-container', {
  width: '100%',
  height: 250,
  onClick: (adData) => {
    console.log('๋ฐฐ๋„ˆ ๊ด‘๊ณ  ํด๋ฆญ๋จ:', adData);
    // ์‚ฌ์šฉ์ž ์ •์˜ ๋กœ์ง ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
  }
});

โš™๏ธ Configuration Options

Basic Options

OptionTypeDefaultDescription
widthstring | number'100%'Banner width (px or %)
heightnumber250Banner height (px)
onClickfunctionundefinedCallback function executed on click

Advanced Options

OptionTypeDefaultDescription
autoSlidebooleanfalseAuto-slide when multiple ads are present
slideIntervalnumber5000Slide interval (milliseconds)
adIdstringundefinedSpecify a particular ad ID

Filtering Options

OptionTypeDefaultDescription
language'ko' | 'en' | 'ja' | 'zh'undefinedFilter by language
deviceType'MOBILE' | 'DESKTOP'undefinedFilter by device
country'KR' | 'US' | 'JP' | 'CN' | 'DE'undefinedFilter by country

๐Ÿ’ก Real-World Implementation Examples

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>

๐Ÿš€ Advanced Features

Auto-Slide

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์ดˆ๋งˆ๋‹ค ์Šฌ๋ผ์ด๋“œ
});

Responsive Banner

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'
  });
});

Specifying a Particular Ad ID

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

๐Ÿ”ง Optimization Tips

1. Leverage Dynamic Resizing

The SDK automatically optimizes the container to fit the image size.

// ์ด๋ฏธ์ง€ ํฌ๊ธฐ์— ๋งž์ถฐ ์ž๋™ ์กฐ์ •
AdStage.ads.banner('banner-container', {
  width: '100%',
  height: 'auto'  // ์ด๋ฏธ์ง€ ๋น„์œจ์— ๋งž์ถฐ ์ž๋™ ์กฐ์ •
});

2. Background Loading

Ads load in the background, so you can receive the slot ID immediately.

// ์ฆ‰์‹œ ์Šฌ๋กฏ ID ๋ฐ˜ํ™˜
const slotId = AdStage.ads.banner('banner-container');
console.log('์Šฌ๋กฏ ์ƒ์„ฑ๋จ:', slotId);  // ์ฆ‰์‹œ ์‹คํ–‰
 
// ์‹ค์ œ ๊ด‘๊ณ ๋Š” ๋น„๋™๊ธฐ๋กœ ๋กœ๋“œ๋จ

3. Leverage Automatic Cleanup

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() ํ˜ธ์ถœํ•  ํ•„์š” ์—†์Œ

๐ŸŽจ Styling

Leveraging CSS Classes

You can apply styling using the CSS classes that the SDK adds automatically.

/* ๊ด‘๊ณ  ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ณธ ์Šคํƒ€์ผ */
.adstage-ad {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
}
 
/* ๋กœ๋”ฉ ์ƒํƒœ */
.adstage-loading {
  opacity: 0.7;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}
 
@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
 
/* ๋กœ๋”ฉ ์™„๋ฃŒ */
.adstage-loaded {
  opacity: 1;
  transition: opacity 0.3s ease;
}
 
/* ์˜ค๋ฅ˜ ์ƒํƒœ */
.adstage-error {
  border: 1px solid #ff6b6b;
  background-color: #ffe0e0;
}

Checking Slot Status

// ๋ชจ๋“  ์Šฌ๋กฏ ํ™•์ธ
const allSlots = AdStage.ads.getAllSlots();
console.log('์ „์ฒด ๊ด‘๊ณ  ์Šฌ๋กฏ:', allSlots);
 
// ํŠน์ • ์Šฌ๋กฏ ํ™•์ธ
const slot = AdStage.ads.getSlotById(slotId);
console.log('์Šฌ๋กฏ ์ •๋ณด:', slot);

Table of Contents