@suucha/ads-adsense
v0.1.0
Published
Google AdSense ad manager for Suucha Web SDK
Readme
@suucha/ads-adsense
Google AdSense ad manager implementation for Suucha Web SDK. Dynamically loads adsbygoogle.js and mounts ad slots into DOM containers.
Install
pnpm add @suucha/core @suucha/ads-adsenseUsage
Auto Ads (simplest)
import { suucha } from '@suucha/core';
import { AdSenseManager } from '@suucha/ads-adsense';
const ads = new AdSenseManager({
client: 'ca-pub-1234567890123456',
autoAds: true,
});
suucha.enableAds(ads);
// AdSense automatically picks ad placementsManual Slots
const ads = new AdSenseManager({
client: 'ca-pub-1234567890123456',
});
suucha.enableAds(ads);
const handle = await ads.mountSlot({
container: '#ad-banner', // CSS selector or HTMLElement
slot: '1234567890',
format: 'horizontal',
});
// Refresh slot
handle.refresh();
// Tear down
ads.unmountSlot(handle);Consent / GDPR
const ads = new AdSenseManager({
client: 'ca-pub-...',
deferUntilConsent: true,
});
// Script not loaded yet
suucha.enableAds(ads);
// After CMP grants consent:
suucha.setConsent(true);
ads.load();Options
| Option | Default | Description |
|---|---|---|
| client | (required) | Publisher ID (ca-pub-XXXX) |
| autoAds | false | Enable AdSense auto-ad placement |
| deferUntilConsent | false | Skip script load until load() called |
Slot Options
| Option | Default | Description |
|---|---|---|
| container | (required) | CSS selector or HTMLElement |
| slot | - | Ad unit ID |
| format | 'auto' | 'auto' / 'horizontal' / 'vertical' / 'rectangle' |
| responsive | true | Fill container width |
License
MIT © Suucha Studio
