// Ad Management Script - Simplified and Error-Safe (function() { 'use strict'; // Prevent multiple initialization if (window.adManagerInit) return; window.adManagerInit = true; // Safe logging function function safeLog() { try { if (window.cis_show_logs && console && console.log) { console.log.apply(console, arguments); } } catch (e) {} } // Configuration var config = { prebidTimeout: 1500, cpmMarginPercent: parseInt(window.cpmMarginPercent) || 0 }; // Pixel tracking state var pixelState = { adsAmountValue: 0, lastSentValue: 0, eventFired: 0, smallEventFired: 0, smallEvents: [1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9] }; // Browser detection var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; // Initialize global pixel variables window.pixel_ads_amount_value = 0; window.pixel_last_sent_value = 0; window.pixel_event_fired = 0; window.pixel_small_event_fired = 0; window.pixel_small_events = [1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9]; window.doneAuctionsWins = window.doneAuctionsWins || []; // Setup preconnections function setupPreconnections() { var urls = [ 'https://fonts.gstatic.com', 'https://adservice.google.com', 'https://tpc.googlesyndication.com', 'https://securepubads.g.doubleclick.net', 'https://pagead2.googlesyndication.com', 'https://pubads.g.doubleclick.net', 'https://www.google-analytics.com', 'https://www.googletagservices.com', 'https://c.amazon-adsystem.com', 'https://aax.amazon-adsystem.com', 'https://connect.facebook.net' ]; for (var i = 0; i < urls.length; i++) { try { var link = document.createElement('link'); link.rel = 'preconnect'; link.href = urls[i]; document.head.appendChild(link); } catch (e) {} } } // Setup analytics function setupAnalytics() { try { window.assertiveQueue = window.assertiveQueue || []; window.assertiveQueue.push(function() { try { if (window.assertive && window.assertive.analytics && window.assertive.analytics.custom) { window.assertive.analytics.custom.custom_6 = "AY_wrapper"; window.assertive.analytics.custom.custom_4 = 'Layout_' + (window.ads_layout || 'unknown'); } } catch (e) {} }); } catch (e) {} } // Load AY wrapper script function loadAdWrapper() { try { var script = document.createElement("script"); script.src = "https://jk3yfTwHczNirJfKt.ay.delivery/manager/jk3yfTwHczNirJfKt"; script.referrerPolicy = "no-referrer-when-downgrade"; document.head.appendChild(script); } catch (e) {} } // Setup Facebook noscript function setupFacebookNoscript() { try { var noscript = document.createElement("noscript"); var img = document.createElement("img"); img.height = "1"; img.width = "1"; img.style.display = "none"; img.src = "https://www.facebook.com/tr?id=1581007252192655&ev=PageView&noscript=1"; noscript.appendChild(img); document.head.appendChild(noscript); } catch (e) {} } // Load P1 script function loadP1Script() { try { var script = document.createElement("script"); script.id = "script_p1"; script.src = "https://cdn.historycollection.com/wp-content/uploads/2024/03/p1.js"; document.head.appendChild(script); } catch (e) {} } // Send custom event function sendCustomEvent(eventName, data) { try { if (typeof fbq !== "undefined") { fbq("trackCustom", eventName, data); } if (typeof cis_send_custom_event !== "undefined") { cis_send_custom_event(eventName, data); } } catch (e) {} } // Process small events function processSmallEvents() { try { for (var i = 0; i < pixelState.smallEvents.length; i++) { var threshold = pixelState.smallEvents[i]; if (pixelState.smallEventFired <= i && pixelState.adsAmountValue > threshold) { pixelState.smallEventFired++; window.pixel_small_event_fired = pixelState.smallEventFired; var eventName = (threshold / 10) + "R" + (window.site_prefix || ''); sendCustomEvent(eventName, { currency: "USD", value: threshold }); } } } catch (e) {} } // Process incremental events function processIncrementalEvents() { try { while (pixelState.adsAmountValue > 10 && pixelState.adsAmountValue < 310 && pixelState.adsAmountValue > pixelState.lastSentValue + 10) { pixelState.lastSentValue += 10; window.pixel_last_sent_value = pixelState.lastSentValue; var eventName = (pixelState.lastSentValue / 10) + "R" + (window.site_prefix || ''); sendCustomEvent(eventName, { currency: "USD", value: pixelState.lastSentValue }); } } catch (e) {} } // Process milestone events function processMilestoneEvents() { try { var milestones = [ {threshold: 30, event: "HC_30"}, {threshold: 50, event: "HC_50"}, {threshold: 80, event: "HC_80"}, {threshold: 100, event: "HC_100"} ]; for (var i = 0; i < milestones.length; i++) { var milestone = milestones[i]; if (pixelState.adsAmountValue > milestone.threshold && pixelState.eventFired === i) { pixelState.eventFired++; window.pixel_event_fired = pixelState.eventFired; sendCustomEvent(milestone.event, { currency: "USD", value: pixelState.adsAmountValue }); } } } catch (e) {} } // Main revenue tracking function function sendPurchaseAggregatedValue(winnerCPM) { try { pixelState.adsAmountValue += winnerCPM; window.pixel_ads_amount_value = pixelState.adsAmountValue; if (typeof fbq === "undefined") return; processSmallEvents(); processIncrementalEvents(); processMilestoneEvents(); } catch (e) {} } // Handle predicted revenue events function handlePredictedRevenue(event) { try { var data = event.data; if (!data || !data.predictedRevenueCPM) return; var winnerCPM = data.predictedRevenueCPM.impression; if (winnerCPM === 0) return; safeLog("assertive_predictedRevenue", winnerCPM); sendPurchaseAggregatedValue(winnerCPM); // Apply margin if (config.cpmMarginPercent > 0) { winnerCPM = winnerCPM - (winnerCPM * config.cpmMarginPercent) / 100; } if (winnerCPM < 0) return; // Facebook pixel data var fbPixelData = { value: winnerCPM, currency: "USD", content_ids: window.location.href.split("/")[3] || '', content_type: "Product", bidder: "Google", adUnit: (data.meta && data.meta.slotId) || '' }; // Determine winner var biddingPlatformId = 3; var winner = "Google"; if (data.meta && data.meta.dfpResponseInformation) { var advertiserId = data.meta.dfpResponseInformation.advertiserId; if (advertiserId === 4566943199) { biddingPlatformId = 1; winner = (data.meta.highestBid && data.meta.highestBid.bidderCode) || winner; } else if (advertiserId === 4726541655) { biddingPlatformId = 2; winner = "amazon"; } } // Report win var winData = { biddingPlatformId: biddingPlatformId, partnerAuctionId: (data.meta && data.meta.auctionId) || '', bidderCode: winner, prebidAuctionId: (data.meta && data.meta.auctionId) || '', cpm: winnerCPM, currency: "USD", originalCpm: winnerCPM, originalCurrency: "USD", status: "rendered", placementId: (data.meta && data.meta.slotId) || '' }; if (!isChrome && typeof intentIq_612283370 !== "undefined" && intentIq_612283370.reportExternalWin) { intentIq_612283370.reportExternalWin(winData); } // Send Facebook pixel if (typeof fbq !== "undefined") { fbq("track", "Purchase", fbPixelData); } // Update analytics if (typeof intentIq_612283370 !== "undefined" && intentIq_612283370.intentIqConfig) { var testGroup = intentIq_612283370.intentIqConfig.abTesting && intentIq_612283370.intentIqConfig.abTesting.currentTestGroup; if (window.assertive && window.assertive.analytics && window.assertive.analytics.custom) { window.assertive.analytics.custom.custom_8 = testGroup === "A" ? "IIQ_Enabled" : "IIQ_Disabled"; } if (testGroup === "A") { window.iiqCallbackMethod_init = true; } } } catch (e) { safeLog('Error in handlePredictedRevenue:', e); } } // Handle log impression events function handleLogImpression(event) { try { var payload = event.data && event.data.payload; if (!payload) return; var mediaType = (payload.highestBid && payload.highestBid.mediaType) || "banner"; if (payload.unfilled || payload.sourceInternal !== "gpt") return; if (mediaType === "banner" && isIOS) { payload.revenueBias = 0.975; } } catch (e) {} } // Wait for document ready function waitForReady(callback) { if (document.readyState === "interactive" || document.readyState === "complete") { callback(); } else { var checkInterval = setInterval(function() { if (document.readyState === "interactive" || document.readyState === "complete") { clearInterval(checkInterval); callback(); } }, 20); } } // Initialize everything function init() { try { setupPreconnections(); setupAnalytics(); loadAdWrapper(); setupFacebookNoscript(); loadP1Script(); window.PREBID_TIMEOUT = config.prebidTimeout; // Setup event listeners window.addEventListener("assertive_predictedRevenue", handlePredictedRevenue, false); window.addEventListener("assertive_logImpression", handleLogImpression, false); // Add meta tag var metaTag = document.createElement('meta'); metaTag.name = 'impact-site-verification'; metaTag.content = 'bd46cba2-8f9e-4fd2-97e3-030369b052ff'; document.head.appendChild(metaTag); safeLog('AdManager initialized successfully'); } catch (e) { safeLog('Error initializing AdManager:', e); } } // Start initialization when document is ready waitForReady(init); })();
Advertisement