Introduction
Learn how to integrate ads with playgen.io games using event listeners and the built-in SDK.
playgen.io games embedded via iframe can trigger events to allow seamless ad integration within your client page. There are two main ways to integrate ads:
- Listen to game events emitted from the iframe, such as
PLAYGEN_GAME_STARTED
orPLAYGEN_REWARDED
, and use them to trigger ads using your preferred ad provider or logic. - You can use the playgen.io Ad SDK, if you want which provides a built-in solution to handle ad playback or integrate your own ad playback.
Example Game Events
PLAYGEN_GAME_STARTED
— emitted when the game session begins (ideal for pre-roll ads).PLAYGEN_REWARDED
— emitted when the user earns a reward (ideal for rewarded ads).
You can combine both methods depending on your specific use case and user experience goals.
Preroll Ads Integration
To show preroll ads when the game starts, listen for the PLAYGEN_GAME_STARTED
event from the iframe and trigger an ad accordingly.
Example
Rewarded Ads Integration
When a user completes a task or reaches a rewardable moment in a game, the game will emit the PLAYGEN_REWARDED
event. You can then show a rewarded ad.
Example
Playgen Ad SDK API
The Playgen Ad SDK allows easy integration of ad playback within your client pages using events from embedded game iframes.
SDK URL
Initialization
Methods
Playgen.showAd()
Manually trigger an ad playback based on the initialized configuration.
Playgen.ad(config)
Initializes the ad system. Accepts the following parameters:
iframeId
(string): ID of the iframe that will post events.adTag
(string): VAST tag URL to use for ad playback.
Notes
- Ensure the iframe is from a trusted origin and allows
postMessage
communication. - Ads will be displayed over the iframe and paused during playback.
- Recommended to always wait for specific events like
PLAYGEN_GAME_STARTED
orPLAYGEN_REWARDED
before triggering ads.