Loading...

test

Display a rewarded ad








Display a rewarded ad

googletag.pubads().addEventListener("rewardedSlotReady", (event) => { updateStatus("Rewarded ad slot is ready.");

document.getElementById("watchAdButton").onclick = () => { event.makeRewardedVisible(); displayModal(); updateStatus("Rewarded ad is active."); };

displayModal("reward", "Watch an ad to receive a special reward?"); });

googletag.pubads().addEventListener("rewardedSlotClosed", dismissRewardedAd);

googletag.pubads().addEventListener("rewardedSlotGranted", (event) => { rewardPayload = event.payload; updateStatus("Reward granted."); });

googletag.pubads().addEventListener("slotRenderEnded", (event) => { if (event.slot === rewardedSlot && event.isEmpty) { updateStatus("No ad returned for rewarded ad slot."); } });

googletag.enableServices(); googletag.display(rewardedSlot); } else { updateStatus("Rewarded ads are not supported on this page."); } });

function dismissRewardedAd() { if (rewardPayload) { // User was granted a reward and closed the ad. displayModal( "grant", `You have been rewarded ${rewardPayload.amount} ${rewardPayload.type}!`, ); rewardPayload = null; } else { // User closed the ad without getting a reward. displayModal(); }

updateStatus("Rewarded ad has been closed.");

if (rewardedSlot) { googletag.destroySlots([rewardedSlot]); } }

function displayModal(type = "", message = "") { const modal = document.getElementById("modal"); modal.removeAttribute("data-type");

if (type) { document.getElementById("modalMessage").textContent = message; modal.setAttribute("data-type", type); } }

function updateStatus(message) { document.getElementById("status").textContent = message; }