Standalone solution (beta)

Overview

The Playgama Ads SDK provides a simple interface for displaying interstitial and rewarded advertisements on web platforms.

Beta Access

Playgama Ads is currently available in closed beta.

To request access, please contact us at [email protected].

Installation

<script src="https://playgama.com/ads/common.v0.1.js"></script>

Quick Start

// Initialize the SDK
await window.pgAds.init();
window.pgAds.updateTargeting({ playgama_clid: '<your-clid>', gameId: '<game-identifier>' });

// Show Interstitial Ads
const ads = await window.pgAds.requestOutOfPageAd('interstitial');
if (ads.state === 'ready') {
    ads.show();
} else {
    ads.addEventListener('ready', () => {
        ads.show();
    });
}

API Reference

pgAds.init(): Promise<void>

Initialize the ads service before requesting ads.

await window.pgAds.init();

pgAds.updateTargeting(targeting): void

Update targeting parameters for ad requests. Use this to identify your traffic source.

Parameters:

  • targeting (object): Key-value pairs for ad targeting

Example:

// Set your client ID for tracking
window.pgAds.updateTargeting({
    playgama_clid: '<your-clid>',
    gameId: '<game-identifier>'
});

pgAds.requestOutOfPageAd(type, timeout?): Promise<OutOfPageBanner>

Request an advertisement that displays over your content.

Parameters:

  • type (string): Ads type - interstitial or rewarded

  • timeout (number, optional): Request timeout in milliseconds (default: 1000ms)

Ad Types:

  • interstitial - Full-screen ad shown between content

  • rewarded - Video ad that rewards the user upon completion

Event Handling

Listen for ad events to handle user interactions:

// Show Rewarded Ads
const ads = await window.pgAds.requestOutOfPageAd('rewarded');

// Sometimes the ads could be in a "ready" state by the time it is requested
// In that case, the "ready" event woun't be fired, instead you need to check for ads state
if (ads.state === 'ready') {
    ads.show();
} else {
    // Ads is ready to show
    ads.addEventListener('ready', () => {
        ads.show();
    });
}

// User completed rewarded ads
ads.addEventListener('rewarded', () => {
    console.log('Grant reward to user');
});

// User closed the ads
ads.addEventListener('closed', () => {
    console.log('Resume game');
});

// No ads available
ads.addEventListener('empty', () => {
    console.log('Continue without ad');
});

// Click on banner, only for Instream Ads
ads.addEventListener('clicked', () => {
    console.log('Click on instream ads');
});

Last updated