Ads & revenue · Demo 4 of 5
Page ads that refresh as readers play
A quiz keeps readers on the page for minutes. This page listens to Riddle events and reloads the ad next to the quiz after answers, never more often than every five seconds.
Riddle features: JavaScript events
Setup: about 20 minutes
Google Publisher Tag refresh()
Live Riddle
Quiz · 5 questions
Answer a question and watch the inspector: the 300×250 ad on the right is requested again.
What just happened
Riddle events drive the page's own ad slot.
01
Riddle sends events
Every view, start and answer is posted to the embedding page as a Riddle event.
02
The page filters them
Views are ignored; answers and next clicks count. A cooldown keeps refreshes at least five seconds apart.
03
GPT refreshes the slot
googletag.pubads().refresh() requests a new ad for the slot next to the quiz.
Build it yourself
All of it is page code.
1 · On your page
Define the slot as usual, then refresh it on answer events with a cooldown.
var slot, last = 0;
googletag.cmd.push(function () {
slot = googletag.defineSlot('/1234/site/mrec', [300, 250], 'ad-mrec')
.addService(googletag.pubads());
googletag.enableServices();
googletag.display('ad-mrec');
});
window.addEventListener('message', function (e) {
if (e.origin !== 'https://www.riddle.com' || !e.data.isRiddle2Event) return;
if (!/Block_(Next|Submit)/.test(e.data.action)) return;
if (Date.now() - last < 5000) return;
last = Date.now();
googletag.cmd.push(function () { googletag.pubads().refresh([slot]); });
});
2 · In Riddle and Ad Manager
Nothing to switch on in the Riddle.
- Riddle: every script embed posts its events to the page. No setting needed.
- Ad Manager: declare the ad unit as refreshed where your setup or agreements require it.
- Page: keep the cooldown, and refresh only slots that are on screen.
Play fair
Refresh on reader actions, not on a timer.
- Tie refreshes to real interactions, like an answer, and keep a minimum gap.
- Check your Ad Manager policies and buyer agreements for refresh rules.
- Refreshing a slot nobody can see wastes impressions and hurts viewability.
Next demo · 5 of 5