reward ads

 <!--rewarded -->

<style>

.modal .btn {

padding: .5rem;

background: #2990ea;

border: none;

border-radius: 4px;

margin: 4px;

display: none; /* Initially hide the close button */

}

.modal p {

text-align: center;

}

</style>

<script>

googletag = window.googletag || { cmd: [] };

googletag.cmd.push(() => {

const e = localStorage.getItem("hasShownRewardedAd"),

o = Date.now();

if (!e || o - parseInt(e, 10) > 6e5) {

const adSlotRewarded = googletag

.defineOutOfPageSlot("/23287284988/dsgdgd", googletag.enums.OutOfPageFormat.REWARDED) // Updated AdUnit Path

.addService(googletag.pubads());


adSlotRewarded.setForceSafeFrame(true);

googletag.pubads().enableAsyncRendering();

googletag.enableServices();


(function () {

const modal = document.getElementById("rewardModal");

const closeButton = document.querySelector('.modal .btn');


// Disable back button during ad playback

window.addEventListener("popstate", function (event) {

history.pushState(null, null, location.href);

});


// Event listeners for reward ad

googletag.pubads().addEventListener("impressionViewable", function () {

console.log("Impression viewable!");


// Show close button only after 30 seconds

setTimeout(() => {

closeButton.style.display = "block";

}, 30000); // 30 seconds delay for close button

});


googletag.pubads().addEventListener("slotRenderEnded", function (event) {

if (event.isEmpty) {

console.log("Ad is empty or failed to load");

setTimeout(function () {

modal.classList.remove("block");

modal.classList.add("hidden");

}, 0);

}

});


googletag.pubads().addEventListener("rewardedSlotReady", function (event) {

modal.classList.remove("hidden");

modal.classList.add("block");

event.makeRewardedVisible();

});


googletag.pubads().addEventListener("rewardedSlotClosed", function (event) {

modal.classList.remove("block");

modal.classList.add("hidden");

localStorage.setItem("hasShownRewardedAd", o.toString());

});


// Ensure ad is displayed

googletag.display(adSlotRewarded);

})();

}

});

</script>


<div id="rewardModal" class="hidden modal fixed z-10 pt-80 left-0 top-0 w-full h-full overflow-auto bg-black bg-opacity-5">

<div class="modal-content m-auto p-6 bg-slate-100 text-center fixed top-2/4 left-2/4 transform -translate-x-2/4 -translate-y-2/4">

<p>Watch the ad to continue.</p>

<button class="btn">Close Ad</button>

</div>

</div>

<!--rewarded end -->


No comments:

Post a Comment

Pages