(function () { // Inject necessary data from Blade const domainId = "TPLYl7bPfV"; if (!domainId) { console.error('Zone ID is missing.'); return; } const csrfToken = "7KWRI9kh4btXzPlCZpDo3IPh09IoPFzSN78sWjnV"; // CSRF token const ads = [{"id":6,"image_url":"https:\/\/monetizekoro.com\/images\/banners\/1731771529.png","click_url":"https:\/\/monetizekoro.com","cost":"0","total_imprassions":"1000000","imprassions":null,"clicks":"1675","domain_id":59,"zone_id":62}]; // Inject the ads array from the server // Function to display the banner ad async function displayBannerAd(adContainer) { // Display a loading message while fetching the ad adContainer.innerHTML = "

Loading ads...

"; if (ads && Array.isArray(ads) && ads.length > 0) { const ad = ads[Math.floor(Math.random() * ads.length)]; // Pick a random ad try { // Track the impression and get the response const impressionResponse = await trackImpression(window.location.href, domainId, ad.id); if (impressionResponse && impressionResponse.imprassion) { // Clear the loading message adContainer.innerHTML = ''; // Make the entire container clickable adContainer.style.cursor = 'pointer'; adContainer.onclick = () => { const clickUrl = `https://monetizekoro.com/ads/banner/click/SGAFGHUDSG/:imprassion_id/DSDSGSGSDG`.replace(':imprassion_id', impressionResponse.imprassion); window.open(clickUrl, '_blank'); }; // Create the ad image const adImage = document.createElement("img"); adImage.src = ad.image_url || ''; // Add the ad's image URL adImage.alt = "Advertisement"; adImage.style.width = "100%"; adImage.style.border = "none"; adImage.style.borderRadius = "8px"; // Add rounded corners adImage.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.1)"; // Light shadow effect // Append the ad image to the container adContainer.appendChild(adImage); } } catch (error) { console.error(`Failed to display ad: ${error.message}`); showError('An error occurred while loading the ad.', adContainer); } } else { showError('No ads available for this domain.', adContainer); } } // Async function to track the impression async function trackImpression(pageUrl, domainId, adId) { const trackUrl = `https://monetizekoro.com/ads/banner/banner/TPLYl7bPfV/imprassion`; try { const response = await fetch(trackUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ page_url: pageUrl, domain_id: domainId, ad_id: adId, // Send ad_id with the impression }), }); if (!response.ok) { throw new Error(`Failed to track impression. Status: ${response.status}`); } return await response.json(); // Return the impression data } catch (error) { console.error(`Tracking failed: ${error.message}`); throw error; } } // Function to display errors in the ad container function showError(errorMessage, adContainer) { adContainer.innerHTML = ''; // Clear existing content const errorDiv = document.createElement("div"); errorDiv.style.color = "#e74c3c"; errorDiv.style.textAlign = "center"; errorDiv.style.padding = "10px"; errorDiv.style.background = "#f9e6e6"; errorDiv.style.borderRadius = "8px"; errorDiv.innerHTML = `Error: ${errorMessage}`; adContainer.appendChild(errorDiv); } // Process each ad container on the page const adContainers = document.querySelectorAll(".monetize-koro-banner"); adContainers.forEach(adContainer => displayBannerAd(adContainer)); })();