v1.0.0 - Production Ready

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

ℹ️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.

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.

2Installation

Install the SDK using your preferred package manager:

npm
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.json
{
  "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.

initializePlayaYield()

Initialize the SDK in your background service worker. Call this once when your extension starts.

background.ts
import { initializePlayaYield } from '@playanext/playa-yield-sdk';

initializePlayaYield({
  apiKey: 'your-api-key',
  env: 'production'
});

Parameters

apiKeyrequiredstring

Your PlayaYield API key. Get yours from the dashboard.

envoptional'production' | 'test'

Environment mode. Use 'test' for development with dummy ads. Defaults to 'production'.

baseUrloptionalstring

Custom 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. Can be called from any content script, popup, or page.

popup.ts
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);

Parameters

placementrequiredstring

Ad placement type. Common values: 'popup', 'sidebar', 'settings'

sizerequired{ width: number, height: number }

Ad dimensions in pixels. Common sizes: 300x250, 728x90, 160x600

categoriesoptionalstring[]

Optional targeting categories for better ad relevance

Returns

elementHTMLDivElement

Ready-to-append div element containing the ad HTML

impressionIdstring

Unique impression ID for tracking

clickUrloptionalstring

Optional click-through URL

Common Use Cases

Real-world examples to get you started quickly.

Banner Ad in Popup

const { element } = await createAd({
  placement: 'popup',
  size: { width: 300, height: 250 }
});

document.getElementById('banner-slot').appendChild(element);

Sidebar Ad in Content Script

// Create sidebar container
const sidebar = document.createElement('div');
sidebar.id = 'my-extension-sidebar';
document.body.appendChild(sidebar);

// Load ad
const { element } = await createAd({
  placement: 'sidebar',
  size: { width: 300, height: 600 }
});

sidebar.appendChild(element);

Custom Styling

const { element } = await createAd({
  placement: 'popup',
  size: { width: 300, height: 250 }
});

// Apply custom styles
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

// Load multiple ads
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 display dummy ads without making real API calls or affecting your analytics.

background.ts
initializePlayaYield({
  apiKey: 'dev_test_key',
  env: 'test' // Returns dummy placeholder ads
});

What You Get in Test Mode

  • Gradient placeholder divs with "PlayaYield Test Ad" text
  • No network requests to production servers
  • Perfect for testing layout and integration
  • No impact on production analytics

Error Handling

The SDK throws typed errors for different failure scenarios. Always wrap your ad requests in try-catch blocks.

Example
try {
  const { element } = await createAd({
    placement: 'popup',
    size: { width: 300, height: 250 }
  });
  
  document.getElementById('ad-slot').appendChild(element);
} catch (error) {
  switch (error.name) {
    case 'NetworkError':
      console.log('Network request failed');
      break;
    case 'ConfigError':
      console.log('Invalid configuration');
      break;
    default:
      console.log('Unknown error:', error);
  }
}

Error Types

NetworkError

Network request to the ad server failed. Check internet connection.

ConfigError

Invalid SDK configuration. Check your API key and parameters.

ValidationError

Invalid parameters passed to createAd(). Check placement and size values.

Need Help?

Our team is here to help you succeed with PlayaYield.