v1.3.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

1Quick Start

Get up and running with PlayaYield in under an hour. 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

Language for Implementation

Advertising Disclosure

Extensions that integrate the PlayaYield SDK display ads within the extension interface. To ensure transparency for users and compliance with Chrome Web Store policies, developers should include disclosure language in both their Chrome Web Store description and their Privacy Policy.

Suggested Language for Extension Description

Include language in your description similar to the following:

Our extension provides ads within the extension interface, including in the popup, the side panel, and/or other internal extension pages.

Suggested Language for Privacy Policy

Include an advertising section in your Privacy Policy similar to the following:

This extension may display advertisements provided by third-party partners, including PlayaYield. To deliver and measure advertising, limited technical information such as IP address, device type, browser type, and interaction data may be transmitted to advertising partners. For more information, see PlayaYield's Privacy Policy: https://www.playayield.com/privacy

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"
  }
}

No Extra Permissions Required

PlayaYield works within your existing extension permissions. Users won't see any new permission prompts when you add monetization.

4Supported Ad Sizes

PlayaYield currently supports the following standard ad sizes. Attempting to request any other size will result in an error.

300x250
Card
320x100
Banner
320x50
Bar

5Where 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.

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

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

Parameters

apiKeyrequiredstring

Your PlayaYield API key. Get yours from the dashboard.

debugoptionalboolean

Enable verbose SDK logging to the console. Useful during development to see detailed logs. You can also toggle this at runtime by running localStorage.setItem('playayield:debug', 'true') in your extension's DevTools console. Defaults to false.

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.

popup.ts
import { createAd } from '@playanext/playa-yield-sdk';

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

document.getElementById('ad-slot')!.appendChild(element);
console.log('Ad displayed with impression:', impressionId);

Parameters

placementrequiredstring

Ad placement type. Common values: 'popup', 'sidepanel', 'internal'

sizerequired{ width: number, height: number }

Ad dimensions in pixels. Allowed sizes: 300x250, 320x50, 320x100

Returns

elementHTMLDivElement

Ready-to-append div element containing the ad HTML

impressionIdstring

Unique impression ID for tracking

clickUrloptionalstring

Optional click-through URL

createManagedRefreshableAd()

Use refreshable ads for long-lived surfaces like side panels to maximize your earnings. By automatically rotating new ads, refreshable units lead to significantly higher revenues compared to static placements. The SDK automatically refreshes ads every 40 seconds and enforces a 29-impression limit per rolling 30-minute session window.

sidepanel.ts
import { createManagedRefreshableAd } from '@playanext/playa-yield-sdk';

// Using CSS selector - SDK handles everything automatically
await createManagedRefreshableAd({
  container: '#ad-slot',
  placement: 'sidepanel',
  size: { width: 300, height: 250 }
});

// Or using element reference
await createManagedRefreshableAd({
  container: document.getElementById('ad-slot')!,
  placement: 'sidepanel',
  size: { width: 300, height: 250 }
});

Parameters

containerrequiredHTMLElement | string

Container element or CSS selector where ad should be appended

placementrequiredstring

Ad placement identifier (e.g., 'sidepanel', 'popup')

sizerequired{ width: number, height: number }

Ad dimensions in pixels

Returns

Returns a control object with stop() and isActive() methods. These are typically not needed — the SDK automatically manages the ad lifecycle including cleanup when the container is removed from DOM. However, for Single Page Applications (SPAs) like React or Vue, it is best practice to manually call stop() in your component's cleanup function to prevent memory leaks.

Live Integration Example

Here's a live 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 Extension

This extension demonstrates proper PlayaYield integration in a production environment

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

// Initialize once when your extension loads
initializePlayaYield({
  apiKey: 'your-api-key-here'
});

console.log('PlayaYield SDK initialized');
2popup.ts - Display a one-time ad
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);
3sidepanel.ts - Display a refreshable ad
import { createManagedRefreshableAd } from '@playanext/playa-yield-sdk';

async function loadRefreshableAd() {
  try {
    await createManagedRefreshableAd({
      container: '#ad-slot',
      placement: 'sidepanel',
      size: { width: 300, height: 250 }
    });

    console.log('Refreshable ad started');
  } catch (error) {
    console.error('Failed to load ad:', error);
  }
}

document.addEventListener('DOMContentLoaded', loadRefreshableAd);
4popup.html - Add ad container
<!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);

Sidepanel 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: 'sidepanel',
  size: { width: 320, height: 100 }
});

document.getElementById('sidepanel-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: 320, height: 50 } })
]);

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. Test mode delivers realistic ads for integration testing but does not generate revenue or fire tracking events.

background.ts
initializePlayaYield({
  apiKey: 'dev_test_key'
});

What You Get in Test Mode

  • Requests are marked as test-mode server-side based on the API key
  • 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

Impressions

Tracked when the ad is at least 50% visible in the viewport using IntersectionObserver.

Clicks

Tracked automatically before opening the destination URL. No additional code required.

Session Management

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.

Example
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 PlayaYieldError

Thrown 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 PlayaYieldError

Thrown when the ad request fails due to network issues or server errors.

Common causes: no internet connection, server timeout, invalid API key

PlayaYieldErrorbase class

Base error class with code and details properties for programmatic error handling.

Need Help?

Our team is here to help you succeed with PlayaYield.