Frontend SDK for Hybrid AI Interactive Ad Network - React + Universal
npm install @ai-ad-network/frontend-sdk> ๐ Zero-config SDK for AI-powered native ads with automatic client info collection
>
> ๐ฆ Dual SDK Support: React + Universal (Framework-Agnostic)
>
> Version: 1.0.7
---
``bash`
npm install @ai-ad-network/frontend-sdk
`tsx
// 1. Wrap your app
import { AdProvider } from '@ai-ad-network/frontend-sdk';
// 2. Display ads
import { useAiAds, ActionCardAdV2 } from '@ai-ad-network/frontend-sdk';
function ChatApp() {
const { ads, requestId } = useAiAds(query, response, isFinished);
return ads.map((ad, index) => (
ad={ad}
requestId={requestId}
slotId="slot-1"
position={index}
totalAds={ads.length}
/>
));
}
`
`bash`
npm install @ai-ad-network/frontend-sdk
`javascript
import { AdManager, DOMRenderer } from '@ai-ad-network/frontend-sdk/universal';
const manager = new AdManager({
apiBaseUrl: '/api/v1',
apiKey: 'ak_your_key',
slots: [{ slotId: 'banner', position: 'top', adTypes: ['action-card'] }]
});
const result = await manager.requestAds({ conversationContext: { query } });
DOMRenderer.renderActionCardWithAnalytics(result.slots[0].ads[0], container, {
analytics: { requestId: result.requestId, slotId: 'banner', position: 0, totalAds: 1 },
manager
});
`
---
๐ Complete Documentation โ
| ๆๆกฃ | ่ฏดๆ |
|------|------|
| ๅฟซ้ๅผๅงๆๅ | 3ๅ้ๅฟซ้้ๆ |
| ๅฎๆดไฝฟ็จๆๆกฃ | ่ฏฆ็ป API ่ฏดๆๅๆไฝณๅฎ่ทต |
| ้ฎ้ขๆๆฅๆๅ | ๅธธ่ง้ฎ้ขๅ่งฃๅณๆนๆก |
| Guide | Description |
|-------|-------------|
| Installation | Install and configure the SDK |
| React Integration | Step-by-step React setup (3 min) |
| Universal Integration | Vue, Angular, Vanilla JS setup (3 min) |
| Guide | Description |
|-------|-------------|
| Analytics Tracking | Impression & click tracking (V2 API) |
| ClientInfo API | Access device, user, app, geo data |
| Ad Formats | 7 native ad formats explained |
| Reference | Description |
|-----------|-------------|
| React SDK API | Hooks, components, types |
| Universal SDK API | AdManager, renderers, Web Components |
| Guide | Description |
|-------|-------------|
| Troubleshooting | Common issues & solutions |
| Migration Guide | V1 โ V2 Analytics API migration |
---
| Feature | Description |
|---------|-------------|
| ๐ฏ Intent-based Ads | Ads matched to user intent |
| ๐จ 7 Native Formats | Action Cards, Suffix, Sponsored Sources, Lead Gen, and more |
| ๐ V2 Analytics API | POST-based impression/click tracking (more reliable) |
| ๐ OpenRTB Compliant | Zero-config auto-collection of device/app/user/geo data |
| โก Optimized Performance | SWR caching, Intersection Observer, code splitting |
| ๐ญ Headless Design | Full customization with CSS variables |
| ๐ Framework-Agnostic | Works with React, Vue, Angular, Svelte, Vanilla JS, etc. |
---
`json`
{
"exports": {
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./universal": {
"import": "./dist/universal/universal.esm.js",
"require": "./dist/universal/universal.cjs.js",
"types": "./dist/universal/universal.d.ts"
}
}
}
---
| Format | React Component | Universal Method | Best For |
|--------|-----------------|------------------|----------|
| Action Card | ActionCardAdV2 | DOMRenderer.renderActionCard() | E-commerce, products |SuffixAdV2
| Suffix | | DOMRenderer.renderSuffixAd() | Conversational ads |SponsoredSourceAdV2
| Sponsored Source | | DOMRenderer.renderSponsoredSource() | Content citations |LeadGenAd
| Lead Generation | | DOMRenderer.renderLeadGenAd() | Lead capture, signups |
๐ Ad Formats Reference - Complete format guide
---
- โ
POST-based impression/click tracking (more reliable than pixel tracking)
- โ
Request-level analytics with requestId(requestId, slotId, position, totalAds)
- โ
Ad coordinates:
- โ
Session management for user journey tracking
- โ
Backward compatible with V1 pixel tracking
New Components: ActionCardAdV2, SuffixAdV2, SponsoredSourceAdV2
New Hooks: useAdTrackingV2
New Methods: AdManager.trackAdImpressionAPI(), AdManager.trackAdClick()
---
`tsx`
apiBaseUrl: string, // Required: API base URL
apiKey?: string, // Optional: API key (if not using backend proxy)
debug?: boolean, // Optional: Enable debug logging
enabled?: boolean, // Optional: Globally enable/disable ads
defaultFormats?: AdFormat[] // Optional: Default ad formats
}}
>
`javascript`
const manager = new AdManager({
apiBaseUrl: string, // Required: API base URL
apiKey?: string, // Optional: API key
slots?: AdSlotConfig[], // Optional: Predefined slots
enabled?: boolean // Optional: Enable/disable ads (default: true)
});
---
`typescript`
// Backend proxy (Node.js/Express)
app.post('/api/ads/request', async (req, res) => {
const AD_API_KEY = process.env.AD_API_KEY; // Server-side only
const response = await fetch('https://api.example.com/v1/ads/request', {
headers: { 'X-API-Key': AD_API_KEY },
body: JSON.stringify(req.body)
});
res.json(await response.json());
});
`tsx`
// Frontend - No API key exposed
๐ Security Guide - Complete security documentation
---
- [ ] SDK installed (npm install @ai-ad-network/frontend-sdk)
- [ ] Console shows SDK v1.0.7+
- [ ] React: App wrapped with AdManager
- [ ] Universal: initializedclientInfo` field
- [ ] API key configured (or backend proxy set up)
- [ ] Network requests include
- [ ] Ads are rendering
- [ ] Analytics events firing (check Network tab)
Done? ๐ Successfully integrated!
---
- ๐ง Email: support@ai-ad-network.com
- ๐ Docs: https://docs.ai-ad-network.com
- ๐ Issues: https://github.com/ai-ad-network/frontend-sdk/issues
---
MIT
---
SDK Version: 1.0.7
Last Updated: 2026-02-04