Common Features
This document centralizes the shared concepts previously duplicated in each ad type guide so that individual type docs can focus on their unique capabilities.
🧱 Core Structure & Shared Invocation Pattern
React / Next.js Provider Pattern (Shared)
⚙️ Shared Option Summary
| Option | Type | Description | Applies To |
|---|---|---|---|
onClick | function(adData) | Callback on ad click | All |
adId | string | Force a specific ad | All |
language | `'ko' | 'en' | 'ja' |
deviceType | `'MOBILE' | 'DESKTOP'` | Device filter |
country | ISO2 country code | Country filter | All |
Type‑specific options are documented in each (banner / text / video) guide.
🔄 Lifecycle & Internal Flow
Key Characteristics
- Immediate return:
slotIdreturned before server response ⇒ non‑blocking UI - Deferred container: retries if container not yet in DOM; renders later when available
- MutationObserver auto cleanup: DOM removal triggers automatic
destroy() - Multi‑ad safety: repeated calls on same container keep only the latest (implementation policy)
🧪 Slot Management API
Example slot shape:
🚀 Performance & Optimization Strategies
| Strategy | Explanation | Notes |
|---|---|---|
| Background loading | Async load avoids blocking initial paint | slotId is immediate |
| Delayed container support | Handles late DOM insertion automatically | Simplifies init code |
| Auto cleanup | Prevents memory/event leaks | Helpful in SPA navigations |
| Minimal DOM mutation | Only inner container updated | Reduces layout shifts |
| Type‑aware sizing | Banner/Video sized; Text auto height | Lowers CLS |
Responsive Pattern Template
📦 React / Next.js Recommended Summary
| Pattern | Description | When |
|---|---|---|
| Global Provider | Single SDK init | App / RootLayout |
| Hook (useAdStageInstance) | Safe SDK access | CSR components |
| Cleanup in useEffect | Guarantees destroy | Clarifies slot lifetime |
| Skeleton styling | Customize .adstage-loading | UX polish |
🎨 Shared CSS Classes
See type docs for additional styling specifics.
🛠 Debugging & Monitoring
Enable Debug Mode
Listen to Custom Events
Diagnostic Helper
🔐 Safety & Best Practices
| Topic | Recommendation |
|---|---|
| API Key | Public exposure acceptable but use least‑privileged key |
| Event tracking | For extra analytics in onClick, send async before navigation |
| Error handling | Log / alert on adstage:ad:error |
| Retry policy | Container delay handled internally → avoid redundant setTimeout loops |
❓ FAQ (Shared)
Q. Do I need to always call destroy()?
A. Usually no. DOM removal is auto‑detected. Call manually only if you immediately reuse the same container for a different purpose.
Q. slotId is returned but nothing displays. Why?
A. It may still be loading, or filters (adId / language / deviceType / country) excluded available ads. Enable debug mode and inspect emitted events.
Q. Does this render server‑side in Next.js?
A. No. Rendering is client‑only. Invoke inside use client components.
Q. What happens on repeated calls for the same container?
A. Prior slot is removed; the latest invocation takes precedence (implementation policy).

