1window.googletag = window.googletag || {cmd: []}; 2googletag.cmd.push(function() { 3 const ads = window.drupalSettings?.ads 4 const suppressAds = window.drupalSettings?.ads?.suppressAds 5 6 if (ads && !suppressAds) { 7 let adUnitPath = ads.customAdUnitPath || ads.defaultAdUnitPath 8 let { baseDivId, isRAA, isNeaToday, isNeaTodayHome, isNeaTodayIssue, staticAdSlots, fetchMarginPercent, renderMarginPercent, mobileScaling } = ads 9 let firstAd, panorama, neaTodayHomeStatic, secondAd 10 11 googletag.pubads().collapseEmptyDivs(); 12 13 // Disable single request mode. See NEA-114. 14 // googletag.pubads().enableSingleRequest(); 15 16 // Lazy load ads. This code is adapted from Google's documentation on lazy 17 // loading: https://developers.google.com/publisher-tag/samples/lazy-loading 18 // Numbers were adjusted slightly. 19 googletag.pubads().enableLazyLoad({ 20 // Fetch ads that within that are within X viewports (if X = 200, fetch 21 // when the user is within 2 viewports of the ad.) This setting has no 22 // effect when enableSingleRequest() is enabled. 23 fetchMarginPercent: fetchMarginPercent, 24 25 // Render ads that are within X viewports (if X = 100, render when the 26 // user is within 1 viewport of the ad.) 27 renderMarginPercent: renderMarginPercent, 28 29 // Double the above values on mobile, where viewports are smaller 30 // and users tend to scroll faster. 31 mobileScaling: mobileScaling, 32 }); 33 34 if (isRAA) { 35 // Handle RAA-specific panorama. 36 panorama = googletag.sizeMapping() 37 .addSize([1030, 0], [980, 120]) // >= 1030px wide, show 980x120 38 .addSize([0, 0], [320, 50]) // >= 0px && < 820px wide, show 320x50 39 .build() 40 41 firstAd = googletag.sizeMapping() 42 .addSize([1060, 0], [970, 250]) // >= 1060px wide, show 970x250 43 .addSize([0, 0], [320, 50]) // >= 0px && < 1060px wide, show 320x50 44 .build() 45 46 secondAd = googletag.sizeMapping() 47 .addSize([1060, 0], [970, 250]) // >= 1060px wide, show 970x250 48 .addSize([0, 0], [320, 50]) // >= 0px && < 1060px wide, show 320x50 49 .build() 50 } 51 else if (isNeaToday) { 52 // NEA Today has special ad sizes. See https://airtable.com/app44D0oFjtU8Lrbp/tblMXCfpg1Vd2lCy7/viwXJ8jgKKjtXou0t/recPs5lwThhshIWxG?blocks=hide 53 panorama = googletag.sizeMapping() 54 .addSize([1060, 0], [970, 250]) // >= 1060px wide, show 970x250 55 .addSize([1030, 0], [980, 120]) // >= 1030px wide, show 980x120 56 .addSize([820, 0], [728, 90]) // >= 820px wide, show 728x90 57 .addSize([0, 0], [300, 250]) // >= 0px && < 1060px wide, show 300x250 58 .addSize([0, 0], [320, 50]) // >= 0px && < 1060px wide, show 320x50 59 .build() 60 61 if (isNeaTodayHome) { 62 // Static ad after the third body component. 63 neaTodayHomeStatic = googletag.sizeMapping() 64 .addSize([1060, 0], [970, 250]) // >= 1060px wide, show 970x250 65 .addSize([1030, 0], [980, 120]) // >= 1030px wide, show 980x120 66 .addSize([820, 0], [728, 90]) // >= 820px wide, show 728x90 67 .addSize([0, 0], [300, 250]) // >= 0px && < 1060px wide, show 300x250 68 .addSize([0, 0], [320, 50]) // >= 0px && < 1060px wide, show 320x50 69 .build() 70 } 71 72 if (isNeaTodayHome || isNeaTodayIssue) { 73 // Larger size ad before the NEA Today Promo. 74 firstAd = googletag.sizeMapping() 75 .addSize([1060, 0], [970, 250]) // >= 1060px wide, show 970x250 76 .addSize([1030, 0], [980, 120]) // >= 1030px wide, show 980x120 77 .addSize([820, 0], [728, 90]) // >= 820px wide, show 728x90 78 .addSize([0, 0], [300, 250]) // >= 0px && < 1060px wide, show 300x250 79 .addSize([0, 0], [320, 50]) // >= 0px && < 1060px wide, show 320x50 80 .build() 81 } 82 } 83 84 if (!(isRAA || isNeaTodayHome || isNeaTodayIssue)) { 85 firstAd = googletag.sizeMapping() 86 .addSize([1060, 0], [[970, 250], [728, 90]]) // >= 1060px wide, show 970x250 or 728Ã90 87 .addSize([820, 0], [728, 90]) // >= 820px wide, show 728x90 88 .addSize([0, 0], [320, 50]) // >= 0px && < 1060px wide, show 320x50 89 .build() 90 91 // Second ad uses 300Ã250 instead of 320Ã50 92 secondAd = googletag.sizeMapping() 93 .addSize([1060, 0], [[970, 250], [300, 250]]) // >= 1060px wide, show 970x250 or 300Ã250 94 .addSize([0, 0], [300, 250]) // >= 0px && < 1060px wide, show 300x250 95 .build() 96 } 97 98 if (isRAA) { 99 googletag.defineSlot(adUnitPath, [[980, 120], [320, 50]], baseDivId + '2').addService(googletag.pubads()).defineSizeMapping(panorama) 100 } 101 102 if (isNeaToday ) { 103 googletag.defineSlot(adUnitPath, [[970, 250], [980, 120], [728, 90], [300, 250], [320, 50]], baseDivId + '2').addService(googletag.pubads()).defineSizeMapping(panorama) 104 } 105 106 if (isNeaTodayHome || isNeaTodayIssue) { 107 if (isNeaTodayHome) { 108 googletag.defineSlot(adUnitPath, [[970, 250], [980, 120], [728, 90], [300, 250], [320, 50]], baseDivId + 'home-static').addService(googletag.pubads()).defineSizeMapping(neaTodayHomeStatic) 109 } 110 111 // For both NEA Today Home and NEA Today Issue pages. 112 googletag.defineSlot(adUnitPath, [[970, 250], [980, 120], [728, 90], [300, 250], [320, 50]], baseDivId + '0').addService(googletag.pubads()).defineSizeMapping(firstAd) 113 } 114 115 if (!(isNeaTodayHome || isNeaTodayIssue)) { 116 // Regular ads. 117 googletag.defineSlot(adUnitPath, [[970, 250], [728, 90], [320, 50]], baseDivId + '0').addService(googletag.pubads()).defineSizeMapping(firstAd) 118 119 if (staticAdSlots > 1) { 120 googletag.defineSlot(adUnitPath, [[970, 250], [300, 250]], baseDivId + '1').addService(googletag.pubads()).defineSizeMapping(secondAd) 121 } 122 } 123 124 // Register event handlers to observe lazy loading behavior. 125 // These are just here for demonstration purposes. @todo remove 126 googletag.pubads().addEventListener("slotRequested", (event) => { 127 updateSlotStatus(event.slot.getSlotElementId(), "fetched"); 128 }); 129 130 googletag.pubads().addEventListener("slotOnload", (event) => { 131 updateSlotStatus(event.slot.getSlotElementId(), "rendered"); 132 }); 133 134 googletag.enableServices(); 135 136 // @todo remove before pushing live. 137 function updateSlotStatus(slotId, state) { 138 console.dir(`${slotId} - ${state}`) 139 } 140 141 } 142});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.