1import { t as api } from "../chunks/page-BvcorWMV.js"; 2import { n as utils } from "../chunks/tegna-storage-BGZLdD41.js"; 3import { t as Bem } from "../chunks/bem-DRONJtun.js"; 4import { t as tag } from "../chunks/tag-B19Di4Ua.js"; 5import "./universal-ad.js"; 6//#region Modules/Common/ad/ad.mjs 7var module = { 8 "name": "ad", 9 "class": ".ad" 10}; 11utils.broadcast(module.name, "loaded"); 12function Module(el) { 13 const that = this; 14 const bem = new Bem(el, module.name); 15 this.el = el; 16 this.module = module; 17 this.delay = parseInt(el.dataset.delay) * 1e3; 18 this.lazy = el.dataset.lazy === "true"; 19 this.refresher = null; 20 this.isRefresh = false; 21 this.refreshCount = 0; 22 this.refreshObserver = null; 23 this.init = function() { 24 const waitForGpt = (callback) => { 25 that.setTimeout(function() { 26 if (window.googletag && window.googletag.pubads) callback(); 27 else waitForGpt(callback); 28 }, 200); 29 }; 30 waitForGpt(() => { 31 that.broadcast("init", { "position": el.dataset.position }); 32 setId(); 33 const articleNumber = getArticleNumber(); 34 const fpid = window.localStorage.getItem("ope_fpid"); 35 if (articleNumber > 0) setTargeting("articleNumber", articleNumber); 36 setTargeting("refresh", false); 37 if (fpid !== null) setTargeting("1plusx_ppid", fpid); 38 that.broadcast("setup", { 39 "position": el.dataset.position, 40 "id": that.id, 41 "delay": that.delay 42 }); 43 that.listen("_gpt", "slotRenderEnded", function(source, action, data) { 44 if (data.request.domId === that.id) { 45 handleResponse(data); 46 if (data.response.isEmpty === false && data.response.size.width > 1 && data.response.size.height > 1) rudderStack.adImpression(); 47 } 48 }); 49 whenAdIsOnScreenOrTimedOut(function() { 50 showAd(); 51 }); 52 }); 53 that.broadcast("ready"); 54 }; 55 const setTargeting = (key, value) => { 56 const fullKey = utils.dashesToCamel(`targeting-${key}`); 57 const attribute = `data-targeting-${key}`; 58 if (typeof value === "undefined" || value === null) { 59 that.broadcast("removingTargeting", { 60 "position": el.dataset.position, 61 "target": key 62 }); 63 el.removeAttribute(attribute); 64 } else if (el.dataset[fullKey] !== value.toString()) { 65 that.broadcast("settingTargeting", { 66 "position": el.dataset.position, 67 "target": key, 68 "value": value.toString() 69 }); 70 el.dataset[fullKey] = value.toString(); 71 } else that.broadcast("ignoringExistingTargeting", { 72 "position": el.dataset.position, 73 "target": key, 74 "value": value.toString() 75 }); 76 }; 77 function stopRefresher(restarting) { 78 if (that.refresher) { 79 if (!restarting) that.broadcast("refreshStopped", { "position": el.dataset.position }); 80 that.clearTimeout(that.refresher); 81 that.clearInterval(that.refreshCountdown); 82 that.refresher = null; 83 } 84 } 85 function showAdWhenVisible() { 86 if (document.hidden) { 87 that.broadcast("refreshBlocked", { "position": el.dataset.position }); 88 that.on(document, "visibilitychange", () => { 89 that.broadcast("refreshUnblocked", { "position": el.dataset.position }); 90 showAdWhenVisible(); 91 }, { once: true }); 92 } else showAd(); 93 } 94 function restartRefresher() { 95 if (el.dataset.refreshEnabled === "true") { 96 let refreshInterval = parseInt(el.dataset.refreshInterval); 97 stopRefresher(true); 98 that.refresher = that.setTimeout(() => { 99 that.refreshCount++; 100 that.isRefresh = true; 101 setTargeting("refresh", true); 102 showAdWhenVisible(); 103 }, refreshInterval * 1e3); 104 that.refreshRemaining = refreshInterval; 105 that.refreshCountdown = that.setInterval(() => { 106 that.refreshRemaining--; 107 if (that.refreshRemaining < 1) that.clearInterval(that.refreshCountdown); 108 else that.broadcast("refreshCountdown", { 109 "position": el.dataset.position, 110 "remaining": that.refreshRemaining 111 }); 112 }, 1e3); 113 that.broadcast("refreshRestarted", { "position": el.dataset.position }); 114 that.broadcast("refreshCountdown", { 115 "position": el.dataset.position, 116 "remaining": that.refreshRemaining 117 }); 118 } 119 } 120 const getArticleNumber = () => { 121 const allSections = document.querySelectorAll(".grid__section"); 122 const thisSection = el.closest(".grid__section"); 123 let currentArticleNumber = 0; 124 let articleNumber = 0; 125 allSections.forEach((section, _i) => { 126 if (section.querySelector(".article")) { 127 currentArticleNumber++; 128 if (section === thisSection) articleNumber = currentArticleNumber; 129 } 130 }); 131 return articleNumber; 132 }; 133 const getA9BidsAsync = () => { 134 return new Promise((resolve) => { 135 that.broadcast("startingA9Bidding", { "position": el.dataset.position }); 136 let slots = []; 137 if (el.dataset.outstreamEnabled === "true") slots.push({ 138 "slotID": that.id, 139 "slotName": el.dataset.path, 140 "mediaType": "multi-format", 141 "multiFormatProperties": { 142 "display": { "sizes": JSON.parse(el.dataset.sizes) }, 143 "video": { "sizes": JSON.parse(el.dataset.outstreamSizes) } 144 } 145 }); 146 else slots.push({ 147 "slotID": that.id, 148 "slotName": el.dataset.path, 149 "sizes": JSON.parse(el.dataset.sizes) 150 }); 151 window.apstag.fetchBids({ "slots": slots }, function(bids) { 152 if (bids.length > 0) { 153 that.broadcast("receivedA9Bids", { 154 "bids": bids, 155 "position": el.dataset.position 156 }); 157 if (window.googletag && window.googletag.cmd) window.googletag.cmd.push(function() { 158 that.broadcast("refreshing", { "position": el.dataset.position }); 159 [ 160 "amznbid", 161 "amzniid", 162 "amznsz", 163 "amznp" 164 ].forEach((target) => { 165 const value = bids[0][target]; 166 setTargeting(target, value); 167 }); 168 }); 169 resolve(); 170 } else { 171 if (window.googletag && window.googletag.cmd) window.googletag.cmd.push(function() { 172 that.broadcast("noAmazonBids", { "position": el.dataset.position }); 173 that.broadcast("refreshing", { "position": el.dataset.position }); 174 }); 175 resolve(); 176 } 177 }); 178 }); 179 }; 180 const getOnePlusXProfileData = () => { 181 let resolved = false;
182 return new Promise((resolve) => { 183 that.broadcast("gettingOnePlusXProfile", { "position": el.dataset.position }); 184 window.tegna.getOnePlusXProfileData((segments, topics) => { 185 that.broadcast("receivedOnePlusXProfileData", { 186 "segments": segments, 187 "topics": topics, 188 "position": el.dataset.position 189 }); 190 setTargeting("1plusX", segments); 191 setTargeting("opectx", topics); 192 resolved = true; 193 resolve(); 194 }); 195 that.setTimeout(function() { 196 if (!resolved) { 197 that.broadcast("timedOutOnePlusXProfileData", { "position": el.dataset.position }); 198 resolve(); 199 } 200 }, 1e3); 201 }); 202 }; 203 const showAd = () => { 204 const bidderOptions = [{ 205 "name": "a9", 206 "enabled": "apstag" in window && "fetchBids" in window.apstag, 207 "ready": "apstag" in window && "fetchBids" in window.apstag, 208 "request": getA9BidsAsync 209 }, { 210 "name": "oneplusxprofile", 211 "enabled": "getOnePlusXProfileData" in window.tegna, 212 "ready": "getOnePlusXProfileData" in window.tegna, 213 "request": getOnePlusXProfileData 214 }]; 215 let bidPromises = []; 216 bidderOptions.forEach((bidder) => { 217 if (bidder.enabled && bidder.ready) bidPromises.push(bidder.request()); 218 else that.broadcast(`${bidder.name}BiddingSkipped`, { 219 "name": bidder.name, 220 "enabled": bidder.enabled, 221 "ready": bidder.ready 222 }); 223 }); 224 Promise.allSettled(bidPromises).then(() => { 225 that.broadcast("refreshing", { "position": el.dataset.position }); 226 const getClosestIabCategory = () => { 227 const getArticleCategory = () => { 228 const section = el.closest(".grid__section"); 229 if (section) { 230 const articles = section.getElementsByClassName("article"); 231 if (articles.length > 0) { 232 const articleCategory = articles[0].dataset["iabCategoryId-2.2"]; 233 if (articleCategory !== null) return articleCategory; 234 } 235 } 236 return null; 237 }; 238 const getPageCategory = () => { 239 if (api.model["iabCategoryId-2.2"]) return api.model["iabCategoryId-2.2"]; 240 const article = document.querySelector(".article[data-module=\"article\"]"); 241 if (article) return article.dataset["iabCategoryId-2.2"]; 242 return null; 243 }; 244 const articleCategory = getArticleCategory(); 245 const pageCategory = getPageCategory(); 246 if (articleCategory) return articleCategory; 247 if (pageCategory) return pageCategory; 248 return null; 249 }; 250 const closestIabCategory = getClosestIabCategory(); 251 if (closestIabCategory !== null) setTargeting("content_cat", closestIabCategory); 252 setTargeting("refresh_count", that.refreshCount); 253 setTargeting("refresh_delay", parseInt(el.dataset.refreshInterval)); 254 window.tegna.ads.refresh(that.id); 255 }); 256 }; 257 const whenAdIsOnScreenOrTimedOut = (callback) => { 258 if (that.lazy) that.observe(el, (entry) => { 259 if (entry.isIntersecting) { 260 if (that.timeout !== null) { 261 that.clearTimeout(that.timeout); 262 callback(); 263 } 264 } 265 }); 266 else if (that.delay > 0) { 267 that.timeout = that.setTimeout(function() { 268 that.timeout = null; 269 callback(); 270 }, that.delay); 271 that.observe(el, (entry) => { 272 if (entry.isIntersecting) { 273 if (that.timeout !== null) { 274 that.clearTimeout(that.timeout); 275 callback(); 276 } 277 } 278 }); 279 } else callback(); 280 }; 281 const setId = () => { 282 var id = el.dataset.position; 283 if (document.getElementById(id)) { 284 let i = 1; 285 while (document.getElementById(`${id}_${i}`) !== null) i++; 286 id += "_" + i; 287 } 288 that.id = id; 289 el.firstElementChild.setAttribute("id", that.id); 290 }; 291 const removeBorderIfFullWidth = (width) => { 292 if (document.getElementsByClassName("page")[0].dataset.platform === "desktop" && width >= 1080) bem.selectElements("inner").setModifier("border", false); 293 }; 294 const removeBorderIfOutOfPage = (isEmpty, width) => { 295 if (width < 3) { 296 if (isEmpty === false) { 297 bem.selectElements("inner").setModifier("border", false); 298 bem.selectElements("inner").setModifier("background", false); 299 } 300 } 301 }; 302 const handleResponse = (data) => { 303 that.broadcast("received", { 304 "position": el.dataset.position, 305 "payload": data 306 }); 307 if (el.dataset.collapse === "true" && data.response.isEmpty) { 308 that.el.style.display = "none"; 309 return; 310 } 311 if (el.dataset.refreshEnabled === "true") if (that.refreshObserver) restartRefresher(); 312 else { 313 that.refreshObserver = true; 314 that.observe(el, (entry) => { 315 if (entry.isIntersectingThreshold && !that.viewable) { 316 that.broadcast("viewable", { "position": el.dataset.position }); 317 restartRefresher(); 318 } else { 319 that.viewable = false;
320 that.broadcast("unviewable", { "position": el.dataset.position }); 321 stopRefresher(); 322 } 323 }, { "threshold": 1 }); 324 } 325 removeBorderIfFullWidth(data.response.size.width); 326 removeBorderIfOutOfPage(data.response.isEmpty, data.response.size.width); 327 }; 328 const basicProps = tag.getBaseRudderProperties(); 329 const rudderStack = { adImpression: () => { 330 try { 331 tag.fire(null, { 332 event: "Ad Impressions", 333 ...basicProps, 334 ad_id: el.dataset.position, 335 ad_type: (el.dataset.position || "").includes("universal") ? "high-impact" : "banner", 336 campaign_name: api.model.campaignName, 337 ad_duration: bem.currentBlockName === "video" ? api.model.videoDuration : "Not applicable" 338 }, "rudder"); 339 } catch (error) { 340 console.warn("Rudder Analytics Error: ", error); 341 } 342 } }; 343} 344utils.createModule(module.name, Module); 345//#endregion 346 347//# sourceMappingURL=ad.js.map
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.