{"version":3,"file":"ads.IYgjzFia.js","sources":["../../../src/lib/ads.ts"],"sourcesContent":["import { hasSubscription } from './session'\n\nenum AdSlotId {\n adOtherMobileLeaderboard = 'adOtherMobileLeaderboard',\n adOtherTopLeaderboard = 'adOtherTopLeaderboard',\n adOtherRightText1 = 'adOtherRightText1',\n adOtherRightText2 = 'adOtherRightText2',\n adOtherRightText3 = 'adOtherRightText3',\n adOtherRightWideSkyscraper = 'adOtherRightWideSkyscraper',\n adOtherRightWideSkyscraper300x250 = 'adOtherRightWideSkyscraper300x250',\n adOtherRightSponsor1 = 'adOtherRightSponsor1',\n adOtherRightSponsor2 = 'adOtherRightSponsor2',\n adOtherRightSponsor3 = 'adOtherRightSponsor3',\n adOtherBottomLeaderboard = 'adOtherBottomLeaderboard',\n adOtherMobileAdhesion = 'adOtherMobileAdhesion',\n adStudentLoanMobileLeaderboard = 'adStudentLoanMobileLeaderboard',\n adStudentLoanTopLeaderboard = 'adStudentLoanTopLeaderboard',\n adStudentLoanRightWideSkyscraper = 'adStudentLoanRightWideSkyscraper',\n adStudentLoanRightTile1 = 'adStudentLoanRightTile1',\n adStudentLoanRightTile2 = 'adStudentLoanRightTile2',\n adStudentLoanBottomLeaderboard = 'adStudentLoanBottomLeaderboard',\n adStudentLoanMobileAdhesion = 'adStudentLoanMobileAdhesion',\n adHelloBar = 'adHelloBar',\n adConversionBar = 'adConversionBar',\n adWelcomeAd = 'adWelcomeAd'\n}\n\ninterface AdSlot {\n id: AdSlotId\n adUnit: string\n size: googletag.GeneralSize\n sizeMapping?: googletag.SizeMappingArray\n}\n\nvar visibleSlots = new Set()\n\nconst getDisplayedAdSlotContainers = () => {\n const adSlotContainers = document.querySelectorAll('[data-ad-unit]') as NodeListOf\n return Array.from(adSlotContainers).filter((div) => div.offsetParent !== null)\n}\n\nconst defineAdSlot = (div: HTMLElement) => {\n const adUnit = div.getAttribute('data-ad-unit')!\n const size = JSON.parse(div.getAttribute('data-size')!) as googletag.GeneralSize\n const sizeMapping = div.getAttribute('data-size-mapping')\n ? (JSON.parse(div.getAttribute('data-size-mapping')!) as googletag.SizeMappingArray)\n : null\n\n let slot = googletag.defineSlot(adUnit, size, div.id)\n if (slot) {\n if (sizeMapping) {\n slot = slot.defineSizeMapping(sizeMapping) || null\n }\n\n slot.addService(googletag.pubads())\n }\n}\n\nconst initPubAds = () => {\n googletag.pubads().collapseEmptyDivs()\n googletag\n .pubads()\n .enableLazyLoad({ fetchMarginPercent: 300, renderMarginPercent: 200, mobileScaling: 2.0 })\n googletag.enableServices()\n}\n\nconst displayAdSlot = (div: HTMLElement) => {\n googletag.display(div.id)\n}\n\nconst hideAllAdContainers = () => {\n const displayedAdSlotContainers = getDisplayedAdSlotContainers()\n\n displayedAdSlotContainers.forEach((div) => {\n div.classList.add('hidden')\n })\n\n const adContainers = document.querySelectorAll('[data-ad-container]') as NodeListOf\n adContainers.forEach((div) => {\n div.classList.add('hidden')\n })\n}\n\nconst refreshAdsEveryThirtySeconds = () => {\n googletag.cmd.push(() => {\n googletag.pubads().addEventListener('slotVisibilityChanged', function (event) {\n // If slot is at least 80% visible, we want to refresh it.\n if (event.inViewPercentage >= 80) {\n visibleSlots.add(event.slot)\n } else {\n visibleSlots.delete(event.slot)\n }\n })\n })\n\n // Refresh every 30 seconds, but only for slots that meet threshold\n setInterval(() => {\n if (visibleSlots.size > 0) {\n googletag.cmd.push(() => {\n googletag.pubads().refresh(Array.from(visibleSlots))\n })\n }\n }, 30000)\n}\n\nconst initAds = async () => {\n window.addEventListener('load', async () => {\n const displayedAdSlotContainers = getDisplayedAdSlotContainers()\n\n if (googletag && googletag.cmd) {\n googletag.cmd.push(() => {\n displayedAdSlotContainers.forEach((div) => {\n defineAdSlot(div)\n })\n\n initPubAds()\n })\n }\n\n let userHasSubscription = false\n try {\n userHasSubscription = await hasSubscription()\n } catch (error) {\n console.error('Error checking subscription:', error)\n }\n\n if (userHasSubscription) {\n hideAllAdContainers()\n } else {\n if (googletag && googletag.cmd) {\n googletag.cmd.push(() => {\n displayedAdSlotContainers.forEach((div) => {\n displayAdSlot(div)\n })\n })\n }\n\n refreshAdsEveryThirtySeconds()\n }\n })\n}\n\nconst adSlots: AdSlot[] = [\n {\n id: AdSlotId.adOtherMobileLeaderboard,\n adUnit: '/4802340/savingforcollege_other_mobile_leaderboard',\n size: [\n [320, 50],\n [300, 50]\n ]\n },\n {\n id: AdSlotId.adOtherTopLeaderboard,\n adUnit: '/4802340/savingforcollege_other_top_leaderboard',\n size: [728, 90]\n },\n {\n id: AdSlotId.adOtherRightText1,\n adUnit: '/4802340/savingforcollege_other_right_text_1',\n size: [\n [160, 160],\n [300, 80]\n ]\n },\n {\n id: AdSlotId.adOtherRightText2,\n adUnit: '/4802340/savingforcollege_other_right_text_2',\n size: [\n [160, 160],\n [300, 80]\n ]\n },\n {\n id: AdSlotId.adOtherRightText3,\n adUnit: '/4802340/savingforcollege_other_right_text_3',\n size: [\n [160, 160],\n [300, 80]\n ]\n },\n {\n id: AdSlotId.adOtherRightWideSkyscraper,\n adUnit: '/4802340/savingforcollege_other_right_wide_skyscraper',\n size: [\n [160, 600],\n [300, 600],\n [300, 250]\n ]\n },\n {\n id: AdSlotId.adOtherRightWideSkyscraper300x250,\n adUnit: '/4802340/savingforcollege_other_right_wide_skyscraper_300x250',\n size: [[300, 250]]\n },\n {\n id: AdSlotId.adOtherRightSponsor1,\n adUnit: '/4802340/savingforcollege_other_right_sponsor_1',\n size: [[160, 160]]\n },\n {\n id: AdSlotId.adOtherRightSponsor2,\n adUnit: '/4802340/savingforcollege_other_right_sponsor_2',\n size: [[160, 160]]\n },\n {\n id: AdSlotId.adOtherRightSponsor3,\n adUnit: '/4802340/savingforcollege_other_right_sponsor_3',\n size: [[160, 160]]\n },\n {\n id: AdSlotId.adOtherBottomLeaderboard,\n adUnit: '/4802340/savingforcollege_other_bottom_leaderboard',\n size: [728, 90]\n },\n {\n id: AdSlotId.adOtherMobileAdhesion,\n adUnit: '/4802340/savingforcollege_other_mobile_adhesion',\n size: [[320, 50]]\n },\n {\n id: AdSlotId.adStudentLoanMobileLeaderboard,\n adUnit: '/4802340/savingforcollege_studentloan_mobile_leaderboard',\n size: [[320, 50]]\n },\n {\n id: AdSlotId.adStudentLoanTopLeaderboard,\n adUnit: '/4802340/savingforcollege_studentloan_top_leaderboard',\n size: [728, 90]\n },\n {\n id: AdSlotId.adStudentLoanRightWideSkyscraper,\n adUnit: '/4802340/Savingforcollege_studentloan_right_wide_skyscraper',\n size: [\n [160, 600],\n [300, 600],\n [300, 250]\n ]\n },\n {\n id: AdSlotId.adStudentLoanRightTile1,\n adUnit: '/4802340/savingforcollege_studentloan_right_tile_1',\n size: [\n [160, 600],\n [300, 250]\n ]\n },\n {\n id: AdSlotId.adStudentLoanRightTile2,\n adUnit: '/4802340/savingforcollege_studentloan_right_tile_2',\n size: [\n [160, 600],\n [300, 250]\n ]\n },\n {\n id: AdSlotId.adStudentLoanBottomLeaderboard,\n adUnit: '/4802340/savingforcollege_studentloan_bottom_leaderboard',\n size: [728, 90]\n },\n {\n id: AdSlotId.adStudentLoanMobileAdhesion,\n adUnit: '/4802340/savingforcollege_studentloan_mobile_adhesion',\n size: [[320, 50]]\n },\n {\n id: AdSlotId.adHelloBar,\n adUnit: '/4802340/savingforcollege_hello_bar',\n size: [\n [925, 131],\n [1065, 131]\n ],\n sizeMapping: [\n [\n [1065, 0],\n [1065, 131]\n ],\n [\n [925, 0],\n [925, 131]\n ]\n ]\n },\n {\n id: AdSlotId.adConversionBar,\n adUnit: '/4802340/savingforcollege_bounceexchange_website_conversion_bar',\n size: [\n [1000, 95],\n [1000, 110]\n ]\n },\n {\n id: AdSlotId.adWelcomeAd,\n adUnit: '/4802340/savingforcollege_bounceexchange_website_transitional_welcome',\n size: [\n [720, 480],\n [720, 680]\n ]\n }\n]\n\nexport { initAds, AdSlotId, type AdSlot, adSlots }\n"],"names":["AdSlotId","visibleSlots","getDisplayedAdSlotContainers","adSlotContainers","div","defineAdSlot","adUnit","size","sizeMapping","slot","initPubAds","displayAdSlot","hideAllAdContainers","refreshAdsEveryThirtySeconds","event","initAds","displayedAdSlotContainers","userHasSubscription","hasSubscription","error","adSlots"],"mappings":"8YAEK,IAAAA,GAAAA,IACHA,EAAA,yBAA2B,2BAC3BA,EAAA,sBAAwB,wBACxBA,EAAA,kBAAoB,oBACpBA,EAAA,kBAAoB,oBACpBA,EAAA,kBAAoB,oBACpBA,EAAA,2BAA6B,6BAC7BA,EAAA,kCAAoC,oCACpCA,EAAA,qBAAuB,uBACvBA,EAAA,qBAAuB,uBACvBA,EAAA,qBAAuB,uBACvBA,EAAA,yBAA2B,2BAC3BA,EAAA,sBAAwB,wBACxBA,EAAA,+BAAiC,iCACjCA,EAAA,4BAA8B,8BAC9BA,EAAA,iCAAmC,mCACnCA,EAAA,wBAA0B,0BAC1BA,EAAA,wBAA0B,0BAC1BA,EAAA,+BAAiC,iCACjCA,EAAA,4BAA8B,8BAC9BA,EAAA,WAAa,aACbA,EAAA,gBAAkB,kBAClBA,EAAA,YAAc,cAtBXA,IAAAA,GAAA,CAAA,CAAA,EAgCDC,MAAmB,IAEvB,MAAMC,EAA+B,IAAM,CACnC,MAAAC,EAAmB,SAAS,iBAAiB,gBAAgB,EAC5D,OAAA,MAAM,KAAKA,CAAgB,EAAE,OAAQC,GAAQA,EAAI,eAAiB,IAAI,CAC/E,EAEMC,EAAgBD,GAAqB,CACnC,MAAAE,EAASF,EAAI,aAAa,cAAc,EACxCG,EAAO,KAAK,MAAMH,EAAI,aAAa,WAAW,CAAE,EAChDI,EAAcJ,EAAI,aAAa,mBAAmB,EACnD,KAAK,MAAMA,EAAI,aAAa,mBAAmB,CAAE,EAClD,KAEJ,IAAIK,EAAO,UAAU,WAAWH,EAAQC,EAAMH,EAAI,EAAE,EAChDK,IACED,IACKC,EAAAA,EAAK,kBAAkBD,CAAW,GAAK,MAG3CC,EAAA,WAAW,UAAU,OAAQ,CAAA,EAEtC,EAEMC,EAAa,IAAM,CACb,UAAA,SAAS,oB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