PlayaYield SDK Documentation
Production-ready Chrome Extension Ad Monetization SDK for Manifest V3. Lightweight, secure, and fully compliant.
MV3 Compliant
No remote code execution, all bundled locally
Lightweight
< 35 KB minified and tree-shakeable
Type-Safe
Full TypeScript support with autocomplete
Auto-Tracking
Automatic impression and click tracking
1Quick Start
Get up and running with PlayaYield in under 5 minutes. This guide will walk you through the essential steps to integrate ad monetization into your Chrome extension.
Before You Begin
Make sure you have a PlayaYield API key. If you don't have one yet, sign up to get your key instantly.
ℹ️Chrome Web Store Description Checklist
Google requires plain-language disclosure when you monetize an extension. Use this guidance in your Chrome Web Store description to show reviewers and users that PlayaYield ads stay compliant and do not rely on additional user permissions.
Suggested blurb
This extension uses PlayaYield to show ads only inside internal extension pages (popup, side panel, and settings UI). Ads never inject into websites, never modify search, and never require new user permissions or data access.
- •Clearly list every surface where ads appear (popup, side panel, internal pages) and emphasize that they never touch user-facing webpages.
- •State that PlayaYield does not grant or request additional user permissions and operates entirely within your existing extension scopes.
- •Reiterate that no personal data is collected or sold through these ad units and that users can disable monetization anytime via your extension settings.
2Installation
Install the SDK using your preferred package manager:
npm install @playanext/playa-yield-sdk
Package Details
- Bundle size: < 35 KB minified
- Zero dependencies
- Tree-shakeable ESM and CJS builds
- Full TypeScript definitions included
3Configuration
Configure your manifest.json to work with PlayaYield:
{
"manifest_version": 3,
"name": "Your Extension",
"version": "1.0.0",
"background": {
"service_worker": "background.js"
},
"permissions": ["storage"]
}No Extra Permissions Required
PlayaYield works within your existing extension permissions. Users won't see any new permission prompts when you add monetization.
4Where Ads Can Appear
PlayaYield ads are designed to appear only within your extension's own UI surfaces. This ensures Chrome Web Store compliance and a non-intrusive user experience.
Allowed
- •Extension Popup
- •Side Panel
- •Options/Settings Page
- •Internal Extension Pages (chrome-extension://)
Not Allowed
- •Content Scripts (injected into websites)
- •User-facing web pages
- •Injected iframes on external sites
Content Script Protection
The SDK automatically detects and blocks ad requests from content scripts. If you try to call createAd() or createManagedRefreshableAd() from a content script, it will throw an error:
Error: PlayaYield Ads can only be displayed in extension pages (Side Panel, Popup, or Internal Pages). Content script injection is not allowed.
initializePlayaYield()
Initialize the SDK in your background service worker. Call this once when your extension starts.
import { initializePlayaYield } from '@playanext/playa-yield-sdk';
initializePlayaYield({
apiKey: 'your-api-key',
env: 'production'
});Parameters
apiKeyrequiredstringYour PlayaYield API key. Get yours from the dashboard.
envoptional'production' | 'test'Environment mode. Use 'test' for development and route requests through your test-key environment. Defaults to 'production'.
baseUrloptionalstringCustom API endpoint URL. Only needed for enterprise deployments.
createAd()
Request and create an ad element. Returns a ready-to-append div containing the ad HTML. This must run in extension pages (popup, side panel, or internal extension UI) and is blocked in content scripts.
import { createAd } from '@playanext/playa-yield-sdk';
const { element, impressionId } = await createAd({
placement: 'popup',
size: { width: 300, height: 250 },
categories: ['tech', 'gaming']
});
document.getElementById('ad-slot')!.appendChild(element);
console.log('Ad displayed with impression:', impressionId);Parameters
placementrequiredstringAd placement type. Common values: 'popup', 'sidebar', 'settings'
sizerequired{ width: number, height: number }Ad dimensions in pixels. Allowed sizes: 300x250, 320x50, 320x100
categoriesoptionalstring[]Optional targeting categories for better ad relevance
Returns
elementHTMLDivElementReady-to-append div element containing the ad HTML
impressionIdstringUnique impression ID for tracking
clickUrloptionalstringOptional click-through URL
createManagedRefreshableAd()
Use refreshable ads for long-lived surfaces like side panels. The SDK automatically refreshes ads every 40 seconds and enforces a 29-impression limit per rolling 30-minute session window. These values are managed internally and cannot be configured. The SDK appends the ad to your container and automatically cleans up when the element is removed from the DOM.
import { createManagedRefreshableAd } from '@playanext/playa-yield-sdk';
// Using CSS selector
const managed = await createManagedRefreshableAd({
container: '#ad-slot',
placement: 'sidebar',
size: { width: 300, height: 250 }
});
// Or using element reference
const managed = await createManagedRefreshableAd({
container: document.getElementById('ad-slot')!,
placement: 'sidebar',
size: { width: 300, height: 250 }
});
// Check if active
if (managed.isActive()) {
console.log('Ad is running');
}
// Manual cleanup (optional - auto-cleans when removed from DOM)
managed.stop();Parameters
containerrequiredHTMLElement | stringContainer element or CSS selector where ad should be appended
placementrequiredstringAd placement identifier (e.g., 'sidebar', 'popup')
sizerequired{ width: number, height: number }Ad dimensions in pixels
Returns
stop()() => voidStop refreshing and cleanup resources
isActive()() => booleanCheck if the ad is still actively refreshing
Complete Integration Example
Here's a complete example showing how to integrate PlayaYield into your Chrome extension from start to finish.
Live Example Extension
See a real Chrome extension that has been approved by the Chrome Web Store using our SDK:
View Timezone Freedom ExtensionThis extension demonstrates proper PlayaYield integration in a production environment
import { initializePlayaYield } from '@playanext/playa-yield-sdk';
// Initialize once when your extension loads
initializePlayaYield({
apiKey: 'your-api-key-here',
env: 'production' // or 'test' for development
});
console.log('PlayaYield SDK initialized');import { createAd } from '@playanext/playa-yield-sdk';
async function loadAd() {
try {
const { element, impressionId } = await createAd({
placement: 'popup',
size: { width: 300, height: 250 }
});
document.getElementById('ad-container')!.appendChild(element);
console.log('Ad loaded:', impressionId);
} catch (error) {
console.error('Failed to load ad:', error);
// Hide ad container or show fallback
}
}
// Load ad when popup opens
document.addEventListener('DOMContentLoaded', loadAd);import { createManagedRefreshableAd } from '@playanext/playa-yield-sdk';
async function loadRefreshableAd() {
try {
const managed = await createManagedRefreshableAd({
container: '#ad-slot',
placement: 'sidebar',
size: { width: 300, height: 250 }
});
console.log('Refreshable ad started');
// Optional: Stop when user navigates away
window.addEventListener('beforeunload', () => managed.stop());
} catch (error) {
console.error('Failed to load ad:', error);
}
}
document.addEventListener('DOMContentLoaded', loadRefreshableAd);<!DOCTYPE html>
<html>
<head>
<title>My Extension</title>
<style>
#ad-container {
width: 300px;
min-height: 250px;
margin: 16px auto;
}
</style>
</head>
<body>
<div id="app">
<!-- Your extension content -->
</div>
<div id="ad-container"></div>
<script src="popup.js"></script>
</body>
</html>More Examples
Additional patterns for common use cases.
Banner Ad in Popup
import { createAd } from '@playanext/playa-yield-sdk';
const { element } = await createAd({
placement: 'popup',
size: { width: 300, height: 250 }
});
document.getElementById('banner-slot')!.appendChild(element);Sidebar Ad in Extension Page
import { createAd } from '@playanext/playa-yield-sdk';
// Run this in your sidepanel, popup, or internal page
// (not a content script)
const { element } = await createAd({
placement: 'sidebar',
size: { width: 300, height: 600 }
});
document.getElementById('sidebar-ad')!.appendChild(element);Custom Styling
import { createAd } from '@playanext/playa-yield-sdk';
const { element } = await createAd({
placement: 'popup',
size: { width: 300, height: 250 }
});
// Apply custom styles to the ad container
element.style.borderRadius = '8px';
element.style.boxShadow = '0 4px 6px rgba(0,0,0,0.1)';
element.style.margin = '20px auto';
document.getElementById('ad-slot')!.appendChild(element);Multiple Ad Placements
import { createAd } from '@playanext/playa-yield-sdk';
// Load multiple ads in parallel
const [ad1, ad2] = await Promise.all([
createAd({ placement: 'popup', size: { width: 300, height: 250 } }),
createAd({ placement: 'popup', size: { width: 728, height: 90 } })
]);
document.getElementById('ad-slot-1')!.appendChild(ad1.element);
document.getElementById('ad-slot-2')!.appendChild(ad2.element);Test Mode
Use test mode during development to request ads with your test API key. The SDK still calls your configured backend in test mode.
initializePlayaYield({
apiKey: 'dev_test_key',
env: 'test',
// Optional: baseUrl: 'https://your-test-host.example'
});What You Get in Test Mode
- Requests are marked as test-mode server-side when the API key environment is test
- Safe separation between test and production analytics
- Real integration testing for placement, rendering, and tracking
- Optional custom base URL for dedicated staging/testing environments
Tracking & Compliance
PlayaYield handles all tracking automatically. You don't need to implement any tracking code.
Automatic Tracking
Tracked when the ad is at least 50% visible in the viewport using IntersectionObserver.
Tracked automatically before opening the destination URL. No additional code required.
Refreshable ads automatically track session impressions and enforce limits.
Privacy & Compliance
- •No personal data collection or third-party cookies
- •Ads only appear in extension UI (popup, side panel, internal pages)
- •No injection into user-facing websites
- •Chrome Web Store compliant
Error Handling
The SDK throws typed errors that extend PlayaYieldError. Always wrap your ad requests in try-catch blocks.
import { createAd } from '@playanext/playa-yield-sdk';
try {
const { element } = await createAd({
placement: 'popup',
size: { width: 300, height: 250 }
});
document.getElementById('ad-slot')!.appendChild(element);
} catch (error) {
if (error instanceof Error) {
switch (error.name) {
case 'NetworkError':
console.error('Network request failed:', error.message);
// Show fallback UI or retry
break;
case 'ConfigError':
console.error('Configuration error:', error.message);
// Check SDK initialization
break;
default:
console.error('Unexpected error:', error);
}
}
}Error Types
ConfigErrorextends PlayaYieldErrorThrown when SDK is not initialized, required parameters are missing, or invalid configuration is provided.
Common causes: missing apiKey, missing placement/size, calling createAd() before initializePlayaYield()
NetworkErrorextends PlayaYieldErrorThrown when the ad request fails due to network issues or server errors.
Common causes: no internet connection, server timeout, invalid API key
PlayaYieldErrorbase classBase error class with code and details properties for programmatic error handling.
Need Help?
Our team is here to help you succeed with PlayaYield.