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.

2Chrome 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, internal extension pages, and/or content scripts.

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

3Installation

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

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 within your extension's own UI surfaces by default, with optional support for content scripts controlled subject to approval by PlayaYield. Contact us to request approval for content script placements.

Allowed

  • Extension Popup (placement: 'popup')
  • Side Panel (placement: 'sidepanel')
  • Options / Settings Page (placement: 'internal')
  • Content Scripts (placement: 'content_script')

Not Allowed

  • User-facing web pages
  • Injected iframes on external sites

SDK Validation & Backend Control

The SDK validates that the requested placement matches the actual execution context:

  • Calling createAd() from a content script with placement: 'popup' (or 'sidepanel' / 'internal') throws a ConfigError. You must use placement: 'content_script'.
  • Calling createAd() from an extension page with placement: 'content_script' is allowed, but typically you should match the page type.

The backend reads the placement query param to determine the request origin. When placement=content_script, the backend checks your extension's approval status and either serves an ad or returns 403 Forbidden. Unapproved extensions that attempt content script ads will be denied by the backend.

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.

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 }
});

CSS Selector Behavior

If you pass a CSS selector that matches multiple elements, the SDK will only use the first matching element. Ensure your selector is specific enough to match a single element, or use an element reference instead.

Parameters

containerrequiredHTMLElement | string

Container element or CSS selector where ad should be appended

placementrequiredstring

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

sizerequired{ width: number, height: number }

Ad dimensions in pixels

createAd()

Request and create an ad element. Returns a ready-to-append div containing the ad HTML. Must be called from an extension page (popup, side panel, or internal page) or from a content script. Note that content scripts must use the 'content_script' placement.

popup.ts or content-script.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. Values: 'popup', 'sidepanel', 'internal', 'content_script'

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

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, internal page, or content script
// Content scripts must use placement: 'content_script'
const { element } = await createAd({
  placement: 'sidepanel',
  size: { width: 320, height: 100 }
});

document.getElementById('sidepanel-ad')!.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
  • Only requests made using production api keys generate analytics
  • Real integration testing for placement, rendering, and tracking

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(), unapproved content script placement

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.