1window.googletag = window.googletag || { cmd: [] }; 2window.pbjs = window.pbjs || {}; 3pbjs.que = pbjs.que || []; 4pbjs.adUnitsAdded = pbjs.adUnitsAdded || false; 5pbjs.initAdserverSet = pbjs.initAdserverSet || false; 6pbjs.configSet = pbjs.configSet || false; 7 8window.defineSlotArticle = function (inreadCount) { 9 console.log("Definição de slots iniciada."); 10 11 function waitForCardEditoria(callback) { 12 const observer = new MutationObserver((mutations, obs) => { 13 const cardEditoria = document.querySelector('meta[name="gtm-editorial"]')?.content; 14 if (cardEditoria && cardEditoria !== "undefined") { 15 obs.disconnect(); 16 callback(cardEditoria); 17 } 18 }); 19 observer.observe(document, { childList: true, subtree: true }); 20 } 21 22 console.log('Return mapping sizes:', getMappingSizes('topo_header')); 23 24 function refreshSlots() { 25 const slots = googletag.pubads().getSlots(); 26 27 slots.forEach(slot => { 28 const slotElementId = slot.getSlotElementId(); 29 30 console.log('Forçando display para slot:', slotElementId); 31 googletag.display(slotElementId); 32 33 }); 34 35 googletag.pubads().addEventListener('impressionViewable', function (event) { 36 const slot = event.slot; 37 const targeting = slot.getTargeting('refresh_key'); 38 const refresh_interval = 30000; 39 40 if (targeting && targeting.includes('true')) { 41 setTimeout(function () { 42 if (slot.getTargeting('refreshed_slot')) { 43 slot.setTargeting('refreshed_slot', 'true'); 44 } 45 googletag.pubads().refresh([slot]); 46 console.log('Fez refresh no slot -- ', slot.getSlotElementId()); 47 }, refresh_interval); 48 } 49 }); 50 } 51 52 function refreshEmptySlot() { 53 googletag.pubads().refresh(); 54 console.log('Entrou no refreshEmptySlot ---- '); 55 const refresh_interval = 30000; 56 googletag.pubads().addEventListener("slotRenderEnded", (event) => { 57 const slot = event.slot; 58 const idElement = slot.getSlotElementId() 59 if (idElement === 'artigo_offer_stripe') return; 60 const element = document.getElementById(idElement) 61 const rect = element.getBoundingClientRect() 62 const windowHeight = window.innerHeight 63 const windowWidth = window.innerWidth 64 console.group("Slot", slot.getSlotElementId(), "finished rendering."); 65 66 // Log details of the rendered ad. 67 console.log("Advertiser ID:", event.advertiserId); 68 console.log("Campaign ID:", event.campaignId); 69 console.log("Company IDs:", event.companyIds); 70 console.log("Creative ID:", event.creativeId); 71 console.log("Creative Template ID:", event.creativeTemplateId); 72 console.log("Is backfill?:", event.isBackfill); 73 console.log("Is empty?:", event.isEmpty); 74 console.log("Label IDs:", event.labelIds); 75 console.log("Line Item ID:", event.lineItemId); 76 console.log("Size:", event.size); 77 console.log("Slot content changed?", event.slotContentChanged); 78 console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId); 79 console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId); 80 console.log("Yield Group IDs:", event.yieldGroupIds); 81 console.groupEnd(); 82 83 if (event.isEmpty) { 84 if ( 85 rect.top >= 0 && 86 rect.left >= 0 && 87 rect.bottom <= windowHeight && 88 rect.right <= windowWidth 89 ) { 90 setTimeout(() => { 91 if (slot.getTargeting('refreshed_slot')) { 92 slot.setTargeting('refreshed_slot', 'true'); 93 } 94 googletag.pubads().refresh([slot]); 95 console.log('**** Slot carregou vazio e deu refresh após 30seg ---- '); 96 }, refresh_interval); 97 } 98 } 99 }); 100 101 } 102 103 function getActivesSizes(slot) { 104 const screenWidth = 105 window.innerWidth || document.documentElement.clientWidth; 106 const sizeTarget = slot.getTargeting("size_targeting")[0]; 107 const sizeMapping = getMappingSizes(sizeTarget); 108 let activeSizes = []; 109 110 if (sizeMapping) { 111 for (const [breakpoint, sizes] of sizeMapping) { 112 if (screenWidth < 768 && screenWidth >= breakpoint[0]) { 113 // console.log("screen menor a 768 (mobile)", slot.getSlotElementId(), " - ", sizes); 114 activeSizes = sizes; 115 break; 116 } else if (screenWidth >= 768 || screenWidth >= breakpoint[0]) { 117 // console.log("screen maior ou igual a 768 (desktop)", slot.getSlotElementId(), " - ", sizes); 118 activeSizes = sizes; 119 break; 120 } 121 } 122 } 123 if (activeSizes.length === 0) { 124 activeSizes = slot 125 .getSizes() 126 .map((size) => [size.getWidth(), size.getHeight()]); 127 } 128 return activeSizes; 129 } 130 131 function getGamSlotsFormatted(format) { 132 console.log("Obtendo slots formatados para o formato:", format); 133 return googletag 134 .pubads() 135 .getSlots() 136 .filter((slot) => {
137 return slot.getTargeting("refresh_key")[0] === "true"; 138 }) 139 .map((slot) => { 140 const activeSizes = getActivesSizes(slot); 141 142 if (format === "amazon") { 143 return { 144 slotID: slot.getSlotElementId(), 145 sizes: activeSizes, 146 slotName: slot.getAdUnitPath(), 147 }; 148 } else if (format === "prebid") { 149 return { 150 code: slot.getAdUnitPath(), 151 mediaTypes: { 152 banner: { 153 sizes: activeSizes, 154 }, 155 }, 156 bids: [ 157 { 158 bidder: "teads", 159 params: { 160 placementId: 230147, 161 pageId: 213697, 162 }, 163 }, 164 ], 165 }; 166 } 167 return null; 168 }) 169 .filter((slot) => slot !== null); 170 } 171 172 function amazonFetchBids() { 173 console.log("Fetching bids from Amazon..."); 174 const slots = getGamSlotsFormatted("amazon"); 175 console.log("Slots formatados para a APS:", slots); 176 177 apstag.fetchBids({ slots }, (bids) => { 178 console.log("Bids retornados pela APS:", bids); 179 googletag.cmd.push(() => { 180 apstag.setDisplayBids(); 181 console.log("Slots atualizados com os bids da APS."); 182 }); 183 }); 184 } 185 186 function amazonInit() { 187 !function (a9, a, p, s, t, A, g) { 188 if (a[a9]) return; 189 function q(c, r) { a[a9]._Q.push([c, r]) } 190 a[a9] = { 191 init: function () { q("i", arguments) }, 192 fetchBids: function () { q("f", arguments) }, 193 setDisplayBids: function () { }, 194 targetingKeys: function () { return [] }, 195 _Q: [] 196 }; 197 A = p.createElement(s); A.async = !0; 198 A.src = t; 199 g = p.getElementsByTagName(s)[0]; 200 g.parentNode.insertBefore(A, g) 201 }("apstag", window, document, "script", "https://c.amazon-adsystem.com/aax2/apstag.js"); 202 203 // Inicialização da APS 204 apstag.init({ 205 pubID: 'ee79b9e9-a905-4adf-925b-211c64726bba', //pubID 206 adServer: 'googletag', 207 simplerGPT: true, 208 enableDebug: true, 209 }); 210 211 amazonFetchBids(); 212 }; 213 214 function initAdserver() { 215 if (pbjs.initAdserverSet) return; 216 pbjs.initAdserverSet = true; 217 googletag.cmd.push(function () { 218 if (pbjs.libLoaded) { 219 pbjs.que.push(function() { 220 pbjs.setTargetingForGPTAsync(); 221 googletag.pubads().refresh(); 222 }); 223 } else { 224 googletag.pubads().refresh(); 225 } 226 }); 227 } 228 229 function setConfigAndLoadPrebid() { 230 console.log("Iniciando Set de config e carregamento de Prebid..."); 231 const adUnits = getGamSlotsFormatted("prebid"); 232 console.log("Ad units formatados para o Prebid:", adUnits); 233 pbjs.que.push(function () { 234 if (!pbjs.adUnitsAdded) { 235 pbjs.addAdUnits(adUnits); 236 pbjs.adUnitsAdded = true; 237 } 238 if (!pbjs.configSet) { 239 pbjs.setConfig({ 240 debug: true, 241 bidderTimeout: 3000, 242 enableSendAllBids: true, 243 priceGranularity: "medium", 244 userSync: { 245 auctionDelay: 500, 246 syncDelay: 3000, 247 syncEnabled: true, 248 syncsPerBidder: 5, 249 filterSettings: { 250 image: { 251 bidders: "*", 252 filter: "include" 253 } 254 } 255 }, 256 userId: { 257 // Correto: define o uso de cache para os módulos de ID 258 config: { 259 // Adapte conforme os módulos de ID que estiver usando (ex: navegg, id5, etc) 260 // Exemplo: 261 // naveggId: { ... }, 262 // id5id: { ... }, 263 }, 264 // Isso ativa o cache de ID para evitar execuções repetidas 265 useUserIdCache: true 266 } 267 }); 268 } else { 269 console.log('[Prebid] setConfig já foi chamado anteriormente, ignorando nova execução.'); 270 } 271 272 273 274 }); 275 } 276 277 function prebidInit() { 278 console.log("Iniciando Prebid..."); 279 setConfigAndLoadPrebid() 280 const PREBID_TIMEOUT = 700; 281 282 pbjs.que.push(function () { 283 pbjs.requestBids({ 284 bidsBackHandler: function() { 285 console.log("Todos os bids foram recebidos."); 286 initAdserver(); 287 }, 288 // timeout: 1000, 289 }); 290 }); 291 292 setTimeout(function () { 293 if (!pbjs.initAdserverSet) { 294 console.warn("Timeout atingido, carregando adserver sem bids..."); 295 initAdserver(); 296 } 297 }, PREBID_TIMEOUT); 298 } 299 300 function desativaLazy() { 301 const slots = googletag.pubads().getSlots(); 302
303 slots.forEach(slot => { 304 const slotElementId = slot.getSlotElementId(); 305 if (slotElementId.includes('artigo_topo_header') || slotElementId.includes('artigo_half_page_1') || slotElementId.includes('artigo_offer_stripe')) { 306 console.log('Não tem Lazyload no bloco ------ ', slotElementId); 307 } else { 308 googletag.pubads().enableLazyLoad({ 309 fetchMarginPercent: 200, 310 renderMarginPercent: 50, 311 mobileScaling: 1.0, 312 }); 313 } 314 }); 315 } 316 317 function getMappingSizes(mappingName) { 318 319 const topoHeader = googletag.sizeMapping() 320 .addSize([0, 0], [[300, 50], [300, 100], [320, 50], [320, 100]]) 321 .addSize([960, 0], [[300, 50], [300, 100], [320, 50], [320, 100]]) 322 .addSize([1100, 0], [[728, 90], [970, 90], [970, 250], [1190, 250], [980, 250]]) 323 .build() 324 325 const halfPage1 = googletag.sizeMapping() 326 .addSize([1100, 0],[[300, 250], [336, 280]]) 327 .build() 328 329 const halfPage2 = googletag.sizeMapping() 330 .addSize([1100, 0],[[160, 600], [300, 250], [336, 280], [300, 600]]) 331 .build() 332 333 const inreadRetangulo = googletag.sizeMapping() 334 .addSize([1100, 0], [[1, 1], [300, 250], [336, 280]]) 335 .build(); 336 337 const blocoAnchor = googletag.sizeMapping() 338 .addSize([0, 0], [[300, 50], [320, 50], [320, 100], [300, 100]]) 339 .addSize([960, 0], [[300, 50], [320, 50], [320, 100], [300, 100]]) 340 .addSize([1100, 0], [[970, 90], [728, 90]]) 341 .build(); 342 343 const mappings = { 344 topo_header: topoHeader, 345 half_page_1: halfPage1, 346 half_page_2: halfPage2, 347 inread_retangulo: inreadRetangulo, 348 bloco_anchor: blocoAnchor 349 }; 350 351 return mappings[mappingName]; 352 } 353 354 function setRecomendationsTargetings() { 355 console.log("Entrou no setRecomendationsTargetings ---- "); 356 //leitura das recomendacoes 357 const recommendations_high = JSON.parse(localStorage.getItem("SIIM_REC")) || {value:{r:{pps_v1:[]}}}; 358 const recommendations = recommendations_high.value.r || {pps_v1:[]}; 359 console.log("RECOMMENDATIONS ---- ", recommendations); 360 if (recommendations) { 361 //setup de custom key values 362 for (let key in recommendations) { 363 googletag.pubads().setTargeting("SIIM_"+key, recommendations[key]); 364 } 365 366 //setup de pps 367 googletag.setConfig({ 368 pps: { 369 taxonomies: { 370 IAB_AUDIENCE_1_1: { values: recommendations.pps_v1 }, 371 }, 372 }, 373 }); 374 } 375 376 //setup de ppid 377 const siimid = localStorage.getItem("SIIM_LOGED_ID") || localStorage.getItem("SIIM_ANON_ID"); 378 if (siimid) { 379 googletag.pubads().setPublisherProvidedId(siimid); 380 } 381 } 382 383 384 waitForCardEditoria((cardEditoria) => { 385 const wildcard = cardEditoria ? 'wildcard'.replace(/wildcard/g, cardEditoria) : 'home'; 386 const hiddenForMobile = window.screen.width >= 768; 387 388 googletag.cmd.push(function () { 389 setRecomendationsTargetings(); 390 googletag.pubads().disableInitialLoad(); 391 392 393 const OOP_DIV = document.getElementById('artigo_background'); 394 if (OOP_DIV) { 395 const backgroundOutOfPage = googletag
396 .defineOutOfPageSlot('/14159828/' + wildcard + '/artigo_background', 'artigo_background') 397 .setTargeting('position', 'artigo_background') 398 .addService(window.googletag.pubads()); 399 } 400 401 const topoSlot = googletag 402 .defineSlot('/14159828/' + wildcard + '/artigo_topo_header', [ 403 [300, 50], [300, 100], [320, 50], [320, 100], 404 [728, 90], [970, 90], [970, 250], [980, 250], [1190, 250] 405 ], 'artigo_topo_header') 406 .defineSizeMapping(getMappingSizes('topo_header')) 407 .setTargeting('size_targeting', 'topo_header') 408 .setTargeting('refresh_key', 'true') 409 .setTargeting('refreshed_slot', 'false') 410 .setTargeting('position', 'artigo_topo_header') 411 .setCollapseEmptyDiv(true, true) 412 .addService(googletag.pubads()); 413 414 const offerStripe = googletag 415 .defineOutOfPageSlot('/14159828/' + wildcard + '/artigo_offer_stripe', 'artigo_offer_stripe') 416 .setTargeting('position', 'artigo_offer_stripe') 417 .addService(window.googletag.pubads()); 418 419 function defineVideoSliderSlot(slotId, position) { 420 let attempts = 0; 421 function tryDefineSlot() { 422 const div = document.getElementById(slotId); 423 if (div) { 424 googletag
425 .defineSlot('/14159828/' + wildcard + '/artigo_video_slider', [1, 1], slotId) 426 .setTargeting('position', position) 427 .addService(window.googletag.pubads()); 428 } else if (attempts < 5) { 429 attempts++; 430 setTimeout(tryDefineSlot, 200); 431 } else { 432 console.warn('Div não encontrada para o slot:', slotId); 433 } 434 } 435 tryDefineSlot(); 436 } 437 438 defineVideoSliderSlot('artigo_video_slider_2', 'artigo_video_slider_2'); 439 defineVideoSliderSlot('artigo_video_slider_3', 'artigo_video_slider_3'); 440 441 const slotHalfPage1 = hiddenForMobile && googletag 442 .defineSlot('/14159828/' + wildcard + '/artigo_half_page', [[300, 250], [336, 280]], 'artigo_half_page_1') 443 .addService(googletag.pubads()) 444 .defineSizeMapping(getMappingSizes('half_page_1')) 445 .setTargeting('size_targeting', 'half_page_1') 446 .setTargeting('refresh_key', 'true') 447 .setTargeting('refreshed_slot', 'false') 448 .setTargeting('position', 'artigo_half_page_1'); 449 450 const slotHalfPage2 = hiddenForMobile && googletag
451 .defineSlot('/14159828/' + wildcard + '/artigo_half_page', [[160, 600], [300, 250], [336, 280], [300, 600]], 'artigo_half_page_2') 452 .addService(googletag.pubads()) 453 .defineSizeMapping(getMappingSizes('half_page_2')) 454 .setTargeting('size_targeting', 'half_page_2') 455 .setTargeting('refresh_key', 'true') 456 .setTargeting('refreshed_slot', 'false') 457 .setTargeting('position', 'artigo_half_page_2'); 458 459 460 const inreadSlots = []; 461 for (let i = 1; i <= inreadCount; i++) { 462 const inreadSlot = googletag 463 .defineSlot('/14159828/' + wildcard + '/artigo_inread_retangulo_' + i, [[1, 1], [300, 250], [336, 280]], 'div-otempo-o-inread-' + i) 464 .addService(googletag.pubads()) 465 .defineSizeMapping(getMappingSizes('inread_retangulo')) 466 .setTargeting('size_targeting', 'inread_retangulo') 467 .setTargeting('refresh_key', 'true') 468 .setTargeting('refreshed_slot', 'false') 469 .setTargeting('position', 'artigo_inread_retangulo_' + i); 470 inreadSlots.push(inreadSlot); 471 } 472 473 const fimSlot = googletag
474 .defineSlot('/14159828/' + wildcard + '/artigo_fim_retangulo', [[300, 250], [336, 280]], 'artigo_fim_retangulo') 475 .setTargeting('refresh_key', 'true') 476 .setTargeting('refreshed_slot', 'false') 477 .setTargeting('position', 'artigo_fim_retangulo') 478 .setCollapseEmptyDiv(true, true) 479 .addService(googletag.pubads()); 480 481 // const anchor = googletag.defineOutOfPageSlot( 482 // '/14159828/' + wildcard + '/artigo_bloco_anchor', 483 // googletag.enums.OutOfPageFormat.BOTTOM_ANCHOR 484 // ); 485 486 // if (anchor) { 487 // anchor 488 // .setTargeting('refresh_key', 'true') 489 // .setTargeting('refreshed_slot', 'false') 490 // .setTargeting('position', 'artigo_bloco_anchor') 491 // .setCollapseEmptyDiv(true, true) 492 // .addService(googletag.pubads()); 493 494 // window.anchor = anchor; 495 // console.log("Anchor slot created:", window.anchor); 496 // } 497 498 const anchor = googletag 499 .defineSlot('/14159828/' + wildcard + '/artigo_bloco_anchor', [[300, 50], [320, 50], [320, 100], [300, 100], [970, 90], [728, 90]], 'artigo_bloco_anchor') 500 .defineSizeMapping(getMappingSizes('bloco_anchor')) 501 .setTargeting('size_targeting', 'bloco_anchor') 502 .setTargeting('refresh_key', 'true') 503 .setTargeting('refreshed_slot', 'false') 504 .setTargeting('position', 'artigo_bloco_anchor') 505 .setCollapseEmptyDiv(true, true) 506 .addService(googletag.pubads()); 507 508 509 // prebidInit(); 510 amazonInit(); 511 512 googletag.pubads().setCentering(true); 513 514 desativaLazy(); 515 516 googletag.enableServices(); 517 518 refreshSlots(); 519 refreshEmptySlot(); 520 521 522 523 console.log("Todos os slots definidos e prontos para exibição!"); 524 console.log("Exibindo os slots..."); 525 // googletag.cmd.push(() => { 526 // // googletag.display('artigo_topo_header'); 527 // googletag.display('artigo_offer_stripe'); 528 // // hiddenForMobile && googletag.display('artigo_half_page_1'); 529 // // inreadSlots.forEach(slot => googletag.display(slot)); 530 // // hiddenForMobile && googletag.display('artigo_half_page_2'); 531 // // googletag.display('artigo_fim_retangulo'); 532 // // googletag.display('artigo_video_slider_1'); 533 // // googletag.display('artigo_video_slider_2'); 534 // // googletag.display('artigo_bloco_anchor'); 535 // }); 536 }); 537 }); 538}; 539 540 541 542window.scrollingHeaderAds = function (elementClassName) { 543 console.log("Iniciando scrollingHeaderAds para:", elementClassName); 544 // Seletores principais 545 const adsElement = document.querySelector(elementClassName); 546 if (!adsElement) return; 547 548 const adsContainer = adsElement.children[0]; 549 if (!adsContainer) return; 550 551 const header = document.querySelector(".header__container"); 552 if (!header) { 553 console.warn("Header container não encontrado"); 554 return; 555 } 556 557 // Configurações e contexto 558 const isMobile = window.matchMedia("(max-width: 768px)").matches; 559 const pageType = document.querySelector('meta[name="gtm-editorial_type"]')?.getAttribute("content") || ""; 560 561 // Estado principal da função 562 let currentState = "static"; 563 let offsetTop = 0; 564 let timeoutId = null; 565 let hasDisplayedOnce = false; 566 let headerHeights = getHeaderHeights(); 567 568 // Funções utilitárias 569 function getHeaderHeights() { 570 const headerHeight = header.offsetHeight; 571 return { 572 full: headerHeight, 573 fixed: header.classList.contains("fixed") ? headerHeight : headerHeight, 574 }; 575 } 576 577 function applyInitialStyles() { 578 // adsContainer.style.backgroundColor = "red"; 579 adsContainer.style.transition = "top 0.3s ease-in-out"; 580 adsElement.style.position = "relative"; 581 adsElement.style.width = "100%"; 582 583 if(pageType === "home") { 584 adsElement.closest('.template-container').style.zIndex = "40"; 585 if(isMobile) { 586 adsElement.style.paddingTop = "50px" 587 adsElement.style.paddingBottom = "50px" 588 } 589 } else if (pageType === "editoria") { 590 adsElement.closest('.cp012-ads').style.zIndex = "40"; 591 if(isMobile) { 592 adsElement.style.paddingTop = "50px" 593 adsElement.style.paddingBottom = "50px" 594 } 595 } else if (pageType === "article") { 596 adsElement.style.zIndex = "40"; 597 } 598 599 if(elementClassName === ".capa_topo_header") { 600 601 document.querySelectorAll(".template-container").forEach(container => { 602 const adContainer = container.querySelector(".capa_topo_header"); 603 container.style.zIndex = adContainer ? "40" : "20"; 604 }); 605 } 606 607 } 608 609 function updateOffsetTop() { 610 headerHeights = getHeaderHeights(); 611 offsetTop = header.classList.contains("fixed") 612 ? headerHeights.fixed 613 : (isMobile ? headerHeights.full : 0); 614 } 615 616 function setAdStatic() { 617 adsContainer.style.position = (isMobile && pageType !== "article") ? "absolute" : "static"; 618 if(pageType === "home" || pageType === "editoria") { 619 adsContainer.style.top = isMobile ? "0px" : "auto"; 620 } else { 621 adsContainer.style.top = isMobile ? headerHeights.full + "px" : "auto"; 622 } 623 adsContainer.style.zIndex = isMobile ? 30 : "auto"; 624 adsContainer.style.width = ""; 625 currentState = "static"; 626 } 627 628 function setAdFixed() { 629 adsContainer.style.position = "fixed"; 630 adsContainer.style.top = offsetTop + "px"; 631 adsContainer.style.width = adsContainer.parentElement.offsetWidth + "px"; 632 currentState = "fixed"; 633 clearTimeout(timeoutId); 634 timeoutId = setTimeout(() => { 635 setAdStatic(); 636 destroyFn(); 637 }, 3000); 638 } 639 640 function handleHeaderMutation() { 641 const wasOffset = offsetTop; 642 updateOffsetTop(); 643 if (offsetTop !== wasOffset && currentState === "fixed") { 644 adsContainer.style.top = offsetTop + "px"; 645 } 646 } 647 648 function adjustAdPosition() { 649 const scrollY = window.scrollY; 650 const headerMainHeight = headerHeights.full; 651 const adRect = adsContainer.getBoundingClientRect(); 652 const topDiff = adRect.top - offsetTop; 653 const buffer = isMobile ? 10 : 2; 654 655 if (scrollY <= headerMainHeight) { 656 setAdStatic(); 657 return; 658 } 659 if ( 660 topDiff <= -buffer && 661 currentState !== "fixed" && 662 scrollY > headerMainHeight && 663 !hasDisplayedOnce 664 ) { 665 setAdFixed(); 666 hasDisplayedOnce = true; 667 return; 668 } 669 if (topDiff > buffer && currentState !== "static" && scrollY > headerMainHeight) { 670 setAdStatic(); 671 } 672 } 673 674 // Inicialização 675 applyInitialStyles(); 676 updateOffsetTop(); 677 adjustAdPosition(); 678 679 // Observer do header para detectar mudança de status fixo/normal 680 const observer = new MutationObserver(handleHeaderMutation); 681 observer.observe(header, { attributes: true, attributeFilter: ["class", "style"] }); 682 683 // Handler scroll com throttle 684 let isScrollScheduled = false;
685 function onScroll() { 686 console.log("Scroll detected"); 687 if (isScrollScheduled) return; 688 isScrollScheduled = true; 689 requestAnimationFrame(() => { 690 adjustAdPosition(); 691 isScrollScheduled = false; 692 }); 693 } 694 document.addEventListener("scroll", onScroll, { passive: true }); 695 696 // Cleanup 697 function destroyFn() { 698 document.removeEventListener("scroll", onScroll); 699 clearTimeout(timeoutId); 700 } 701 702 return { destroy: destroyFn }; 703}; 704 705var inReadAdsStart = false; 706var inReadAdsLoaded = false; 707 708// window.addEventListener("load", function () { 709// if (inReadAdsStart && inReadAdsLoaded) { 710// window.displayDelayEventAllAds('inReadAds'); 711// } 712// }); 713 714class inReadAds { 715 constructor() { 716 this.htmlBreakPoint = 'p'; 717 this.qtyBreakPoint = 1; 718 this.limitBreakPoint = 3; 719 this.isCardElection = false; 720 this.injectionContent = 'Add Content'; 721 this.injectionCallback = function () { return false; }; 722 this.elementParent = '.article-whole'; 723 } 724 725 start() { 726 let article = document.querySelector(this.elementParent); 727 let unfilteredBreaks = article.querySelectorAll(this.htmlBreakPoint); 728 let breaks = Array.from(unfilteredBreaks).filter(item => item.textContent.trim() !== ''); 729 730 let qtdy = 1; 731 let splits = 1; 732 let _this = this; 733 for (let iterator = 0; iterator < breaks.length; iterator++) { 734 const el = breaks[iterator]; 735 let createNewDiv = false; 736 737 if (this.qtyBreakPoint == 1) { 738 createNewDiv = true; 739 this.qtyBreakPoint += 2; 740 splits = 0; 741 } else if (splits >= this.qtyBreakPoint) { 742 createNewDiv = true; 743 splits = 0; 744 if (this.limitBreakPoint !== false && qtdy >= this.limitBreakPoint) { 745 console.log('return'); 746 break; 747 } 748 } 749 750 if (createNewDiv) { 751 let div = ''; 752 if(this.isCardElection){ 753 div = document.createElement("li"); 754 div.style.width = '100%'; 755 } else { 756 div = document.createElement("aside"); 757 } 758 759 const divClass = this.qtyBreakPoint == 1 ? 'firstReadads' : 'inreadads'; 760 div.classList.add(divClass, divClass + '-' + qtdy); 761 div.innerHTML = this.contentWildcards(qtdy); 762 article.insertBefore(div, el.nextSibling); 763 this.doCallback(this.injectionCallback, qtdy); 764 qtdy++; 765 } 766 splits++; 767 } 768 inReadAdsLoaded = true; 769 770 } 771 772 contentWildcards(num) { 773 return this.injectionContent.replace('{num}', num).replace('{num}', num); 774 } 775 776 doCallback(callback) { 777 callback(arguments[1]); 778 } 779} 780 781// addig the Register ADS Function Mananger 782// 783// 784window.newWildcard = function (inputString) { 785 const cardEditoria = document.querySelector('meta[name="gtm-editorial"]').content 786 let replacedString = ''; 787 788 if (inputString.includes('wildcard') && cardEditoria !== null && cardEditoria !== '') { 789 replacedString = inputString.replace(/wildcard/g, cardEditoria); 790 return replacedString; 791 } else { 792 replacedString = inputString.replace(/wildcard/g, 'home'); 793 return replacedString; 794 } 795}; 796 797window.newRegisterAds = function (el) { 798 window.otempoadstagsctl = window.otempoadstagsctl || {}; 799 var blockAds, display, id, path, sizes, mapping, lazy, refresh, position, delayEvent, callDelay, parsedMap, parsedSizes, outOfPage; 800 var outofpage = false; 801 802 if (typeof (el) == 'undefined' || el == null) { 803 return false; 804 } 805 806 if (typeof (el.nodeName) != 'undefined') { 807 var { blockAds, display, id, path, sizes, mapping, lazy, refresh, position, outofpage } = el.dataset; 808 if (typeof lazy == 'undefined') { 809 lazy = el.dataset.lazyload; 810 } 811 } else { 812 var [ 813 blockAds, 814 display, 815 id, 816 path, 817 sizes, 818 mapping, 819 lazy, 820 refresh, 821 position, 822 delayEvent, 823 callDelay, 824 ] = el; 825 if (typeof lazy == 'undefined') { 826 lazy = el.lazyload; 827 } 828 } 829 830 if (typeof window.otempoadstag != 'undefined') { 831 for (var oadsI = 0; oadsI < window.otempoadstag.length; oadsI++) { 832 if (window.otempoadstag[oadsI].id == id) { 833 834 window.otempoadstag[oadsI].displayOn(); 835 836 if (window.otempoadstag[oadsI].id.indexOf("outofpage") > 0 || window.otempoadstag[oadsI].oOTB == true) { 837 window.googletag.pubads().refresh([window.otempoadstag[oadsI].googletag]); 838 } 839 840 return false;
841 } 842 } 843 } 844 845 if (typeof lazy == 'undefined') { 846 lazy = false; 847 } 848 849 if (typeof lazy === 'string') { 850 lazy = lazy.toLowerCase() === "true"; 851 } 852 853 lazy = true; 854 try { parsedMap = JSON.parse(mapping); } catch (error) { parsedMap = {}; } 855 try { parsedSizes = JSON.parse(sizes); } catch (error) { parsedSizes = []; } 856 let wildCardPath = window.newWildcard(path); 857 if (blockAds == 'true') { 858 console.log('RegisterADS: A página bloqueou o acesso a publicidade'); 859 } else { 860 if (display == 'desktoponly' && window.innerWidth <= 768) { 861 console.log('RegisterADS: ' + id + ': Propaganda apenas funcionará no Desktop'); 862 } else if (display == 'mobileonly' && window.innerWidth > 768) { 863 console.log('RegisterADS: ' + id + ': Propaganda apenas funcionará no Mobile'); 864 } else { 865 const callbacks = { 866 slotResponseReceived: function (event) { }, 867 slotRequested: function (event) { }, 868 slotOnload: function (event) { }, 869 slotRenderEnded: function (event) { }, 870 }; 871 872 /* 873 Set position numbered 874 */ 875 window.otempoadstagsctl[position] = (typeof window.otempoadstagsctl[position] == "undefined" ? 1 : window.otempoadstagsctl[position] + 1); 876 position = position + '_' + window.otempoadstagsctl[position]; 877 878 const targets = [ 879 { key: 'position', value: position } 880 ]; 881 882 const adM = new AdMananger(); 883 adM.load( 884 { 885 'id': id, 886 'path': wildCardPath, 887 'sizes': parsedSizes, 888 'mapping': parsedMap, 889 'refresh': refresh, 890 'lazy': lazy, 891 'targets': targets, 892 'callbacks': callbacks 893 } 894 ) 895 896 if (outofpage == 'true') { 897 adM.setOOTB(); 898 } 899 900 if (callDelay) { 901 adM.setDelay(callDelay, delayEvent); 902 } 903 904 adM.defineSlot(); 905 906 adM.put(); 907 908 } 909 } 910}; 911 912 913window.checkRegisterAds = function () { 914 if (window.otempoadstagreg.length >= window.otempoadstag.length) { 915 window.otempoadstagstatus = true; 916 return true; 917 } else { 918 return false; 919 } 920}; 921window.onload = function () { displayStartAds(); } 922 923// starting google admananger library 924window.displayStartAds = function () { 925 window.enabledServicesAds(); 926 window.displayStartUpAds(); 927} 928 929window.displayStartUpAds = function () { 930 window.otempoadstagstatus = true; 931 932 if (typeof window.otempoadstag == 'object') { 933 if (window.otempoadstag.length > 0) { 934 let temp = []; 935 for (var oadsI = 0; oadsI < window.otempoadstag.length; oadsI++) { 936 if (window.otempoadstag[oadsI].firstCall == true && window.otempoadstag[oadsI].amazonBid == true) { 937 continue; 938 } 939 940 if (window.otempoadstag[oadsI].firstCall == true && window.otempoadstag[oadsI].id.indexOf("offer_stripe") > 0) { 941 continue; 942 } 943 944 if (window.otempoadstag[oadsI].firstCall == true && window.otempoadstag[oadsI].id.indexOf("outofpage") > 0) { 945 continue; 946 } 947 948 if (!window.otempoadstag[oadsI].isDelay()) { 949 window.googletag.pubads().refresh([window.otempoadstag[oadsI].googletag]); 950 console.log('Ads Display Ignored in First Round...', window.otempoadstag[oadsI]); 951 } else { 952 temp.push(window.otempoadstag[oadsI]); 953 } 954 } 955 window.otempoadstag = temp; 956 } 957 } 958 959 if (typeof window.otempoadstagsdelay == 'object') { 960 if (window.otempoadstagsdelay.length > 0) { 961 for (var oadsI = 0; oadsI < window.otempoadstagsdelay.length; oadsI++) { 962 let item = window.otempoadstagsdelay[oadsI]; 963 window.displayDelayEventAds(item[0], item[1]); 964 } 965 } 966 } 967 968} 969 970window.displayDelayEventAds = function (el, event) { 971 if (!window.otempoadstagstatus) { 972 console.log('All Ads not registered, add event to queue...', window.otempoadstagstatus, el, event); 973 window.otempoadstagsdelay.push([el, event]); 974 return false; 975 } 976 977 if (window.otempoadstag.length > 0) { 978 console.log('Ads Display With Event Starting by Event...', event); 979 let temp = []; 980 for (var oadsI = 0; oadsI < window.otempoadstag.length; oadsI++) { 981 if ( 982 window.otempoadstag[oadsI].callDelay && 983 window.otempoadstag[oadsI].delayEvent == event && 984 window.otempoadstag[oadsI].id == el 985 ) { 986 window.otempoadstag[oadsI].displayOn(); 987 } else { 988 temp.push(window.otempoadstag[oadsI]); 989 } 990 } 991 window.otempoadstag = temp; 992 } 993}; 994 995 996 997window.displayDelayEventAllAds = function (event) { 998 if (!window.otempoadstagstatus) { 999 console.log('All Ads not registered, add event to queue...', window.otempoadstagstatus, 'not element', event); 1000 window.otempoadstagsdelay.push(['', event]); 1001 return false;
1002 } 1003 1004 if (window.otempoadstag.length > 0) { 1005 console.log('Ads Display With Event Starting...', event); 1006 let temp = []; 1007 for (var oadsI = 0; oadsI < window.otempoadstag.length; oadsI++) { 1008 if ( 1009 window.otempoadstag[oadsI].callDelay && 1010 window.otempoadstag[oadsI].delayEvent == event 1011 ) { 1012 window.otempoadstag[oadsI].displayOn(); 1013 } else { 1014 temp.push(window.otempoadstag[oadsI]); 1015 } 1016 } 1017 window.otempoadstag = temp; 1018 } 1019}; 1020 1021window.enabledServicesAds = function () { 1022 if ( 1023 typeof window.googletag.pubadsReady == 'undefined' || 1024 window.googletag.pubadsReady == false 1025 ) { 1026 console.log('Ads Google Admananger - Enabled Services'); 1027 window.googletag.enableServices(); 1028 } 1029} 1030 1031// adding the google admanager to the libraries 1032// 1033// 1034class AdMananger { 1035 constructor(id, path, sizes, mapping, refresh, lazy, targets, callbacks, display) { 1036 this.id = id; 1037 this.path = path; 1038 this.sizes = sizes; 1039 this.mapping = mapping; 1040 this.refresh = refresh; 1041 this.lazy = lazy; 1042 this.callbacks = callbacks; 1043 this.targets = targets; 1044 this.callDelay = false; 1045 this.delayEvent = ''; 1046 this.googletag = false; 1047 this.amazonBid = false; 1048 this.firstCall = false; 1049 this.priority = 1; 1050 this.oOTB = false; 1051 1052 if (typeof this.targets === 'undefined') { 1053 this.targets = {}; 1054 } 1055 1056 if (typeof id !== 'undefined') { 1057 this.initGTag(); 1058 this.defineSlot(); 1059 if (display) { 1060 this.put(); 1061 } 1062 } 1063 1064 this.timeToRefresh = 30000; 1065 this.qtyRefresh = 0; 1066 this.limitRefresh = 20; 1067 } 1068 1069 setOOTB() { 1070 this.oOTB = true; 1071 } 1072 1073 setDelay(delay, event) { 1074 this.callDelay = true; 1075 this.delayEvent = event; 1076 this.priority = 2; 1077 } 1078 1079 isDelay() { 1080 return this.callDelay; 1081 } 1082 1083 load(obj) { 1084 this.id = obj.id; 1085 this.path = obj.path; 1086 this.sizes = obj.sizes; 1087 this.mapping = obj.mapping; 1088 this.lazy = obj.lazy; 1089 this.refresh = obj.refresh; 1090 this.callbacks = obj.callbacks; 1091 this.targets = obj.targets; 1092 this.googletag = false; 1093 this.oOTB = false; 1094 this.refreshing = false; 1095 this.amazonBid = false; 1096 this.firstCall = false; 1097 this.initGTag(); 1098 this.eventScroll(); 1099 if (typeof this.targets === 'undefined') { 1100 this.targets = {}; 1101 } 1102 } 1103 setTarget(_key, _value) { 1104 let obj = { 1105 key: _key, 1106 value: _value, 1107 }; 1108 this.targets.push(obj); 1109 } 1110 initGTag() { 1111 window.googletag = window.googletag || { cmd: [] }; 1112 window.otempoadstag = window.otempoadstag || []; 1113 window.otempoadstagreg = window.otempoadstagreg || []; 1114 window.otempoadstagstatus = window.otempoadstagstatus || false; 1115 window.otempoadstagsdelay = window.otempoadstagsdelay || []; 1116 window.otempoadstagtrack = window.otempoadstagtrack || []; 1117 window.otempoadstagtracklisten = window.otempoadstagtracklisten || false; 1118 } 1119 1120 eventScroll() { 1121 if (!window.otempoadstagtracklisten) { 1122 document.addEventListener("scroll", (event) => { 1123 for (var oadsI = 0; oadsI < window.otempoadstagtrack.length; oadsI++) { 1124 let el = window.otempoadstagtrack[oadsI]; 1125 let div = document.getElementById(el.id); 1126 if (el.elementIsVisibleInViewport(div, true)) { 1127 window.otempoadstagtrack.splice(oadsI, 1); 1128 console.log("Ads into Viewport area, new search in " + el.timeToRefresh + "ms...", el.id, el, event, window.otempoadstagtrack); 1129 setTimeout( 1130 function (obj) { 1131 obj.doRefresh(); 1132 }, 1133 el.timeToRefresh, 1134 el, 1135 ); 1136 } 1137 }; 1138 }); 1139 window.otempoadstagtracklisten = true; 1140 } 1141 } 1142 1143 defineSlot() { 1144 let _this; 1145 window.googletag.cmd.push( 1146 function () { 1147 1148 if (_this.oOTB) { 1149 _this.googletag = window.googletag.defineOutOfPageSlot(_this.path, _this.id); 1150 // if (_this.id.includes('anchor')) { 1151 // console.log('Definindo Slot: slot anchor definido', _this); 1152 // _this.googletag = window.googletag.defineOutOfPageSlot(_this.path, window.googletag.enums.OutOfPageFormat.BOTTOM_ANCHOR); 1153 // console.log('Definindo Slot: slot anchor definido', _this.googletag); 1154 // } else { 1155 // _this.googletag = window.googletag.defineOutOfPageSlot(_this.path, _this.id); 1156 1157 // } 1158 } else { 1159 _this.googletag = window.googletag.defineSlot(_this.path, _this.sizes, _this.id); 1160 } 1161 1162 let mapping = []; 1163 if (typeof _this.mapping === 'object' && _this.oOTB == false) { 1164 const adMapping = window.googletag.sizeMapping(); 1165 Object.keys(_this.mapping).forEach((breakpoint) => { 1166 adMapping.addSize([Number(breakpoint), 0], _this.mapping[breakpoint]); 1167 }); 1168 mapping = adMapping.build(); 1169 _this.googletag.defineSizeMapping(mapping); 1170 } 1171 1172 if (typeof _this.targets !== 'undefined' && _this.targets !== false) { 1173 if (_this.targets.length > 0) {
1174 _this.targets.forEach(function (target) { 1175 _this.googletag.setTargeting(target.key, target.value); 1176 }); 1177 } 1178 } 1179 _this.googletag.pubads = window.googletag.pubads; 1180 _this.googletag.addService(window.googletag.pubads()); 1181 1182 if (_this.refresh == 'true' || _this.refresh === true) { 1183 _this.googletag.setTargeting('refresh', 'true'); 1184 _this.googletag.setTargeting('refreshed_slot', false); 1185 _this.googletag.setTargeting('refreshed_number', '0'); 1186 } else { 1187 _this.googletag.setTargeting('refresh', 'false'); 1188 } 1189 if (!_this.googletag.pubads().isInitialLoadDisabled()) { 1190 _this.googletag.pubads().disableInitialLoad() 1191 } 1192 _this.googletag.pubads().setCentering(true); 1193 1194 let __this; 1195 _this.googletag.pubads().addEventListener("slotRenderEnded", (event) => { 1196 const slot = event.slot; 1197 const el = document.getElementById(slot.getSlotElementId()); 1198 if (slot === __this.googletag) { 1199 if (event.isEmpty) { 1200 if (__this.qtyRefresh <= (__this.limitRefresh)) { 1201 if (__this.elementIsVisibleInViewport(el, true)) { 1202 console.log("!Ads Not Render, search return empty, new attemps in " + __this.timeToRefresh + "ms...", slot.getSlotElementId(), __this, event); 1203 setTimeout( 1204 function (obj) { 1205 obj.doRefresh(); 1206 }, 1207 __this.timeToRefresh, 1208 __this, 1209 ); 1210 } else { 1211 console.log("!Ads Not Render, waiting active view area for attemps new search", slot.getSlotElementId(), __this, event); 1212 window.otempoadstagtrack.push(__this); 1213 } 1214 } 1215 } else { 1216 console.log("Ads Render...", slot.getSlotElementId(), __this, event); 1217 } 1218 } 1219 }, [(__this = _this)]); 1220 1221 1222 1223 if (_this.callbacks !== false) {
1224 Object.keys(_this.callbacks).forEach((callback) => { 1225 _this.googletag.pubads().addEventListener(callback, _this.callbacks[callback]); 1226 }); 1227 } 1228 window.enabledServicesAds(); 1229 window.otempoadstagreg.push(_this); 1230 console.log('RegisterADS: Ads Registrado', _this, _this.lazy == true); 1231 if (_this.lazy == true) { 1232 _this.googletag.pubads().enableLazyLoad({ 1233 fetchMarginPercent: 300, // 75 // 500 1234 renderMarginPercent: 100, // 15 // 200 1235 mobileScaling: 1.0, // 2.0 1236 }); 1237 } 1238 1239 if (_this.id.indexOf("offer_stripe") > 0) { 1240 _this.googletag.pubads().refresh([_this.googletag]) 1241 } 1242 1243 _this.displayOn(); 1244 }, 1245 [(_this = this)], 1246 ); 1247 1248 if (this.id.indexOf("outofpage") > 0) { 1249 window.googletag.pubads().refresh([this.googletag]); 1250 } 1251 1252 1253 this.amazonDoBid(); 1254 } 1255 1256 amazonDoBid() { 1257 let _this; 1258 let amzSizes = this.amazonSizeRemap(); 1259 if (!this.oOTB) { 1260 console.log('APSTAG: Amazon Ads Bid', this, amzSizes); 1261 apstag.fetchBids({ 1262 slots: [{ 1263 slotID: this.id, 1264 slotName: this.path, 1265 sizes: amzSizes 1266 }], 1267 timeout: 2e3 1268 }, function (bids) { 1269 if (_this.amazonBid) { 1270 console.log('APSTAG: Amazon Ads Refresh', bids, _this); 1271 _this.doRefresh(); 1272 } else { 1273 _this.amazonBidDisplay(bids) 1274 } 1275 }, [(_this = this)]); 1276 } 1277 } 1278 amazonBidDisplay(bids) { 1279 let _bids; 1280 let _this; 1281 window.googletag.cmd.push(function () { 1282 console.log('APSTAG: Amazon Ads Display', _bids, _this); 1283 apstag.setDisplayBids(); 1284 window.googletag.pubads().refresh([_this.googletag]); 1285 _this.amazonBid = true; 1286 _this.firstCall = true; 1287 _this.setRefresh(); 1288 }, [(_bids = bids), _this = this]); 1289 } 1290 1291 amazonSizeRemap() { 1292 let amzSizes = []; 1293 let tempSizes = []; 1294 const screenW = screen.width; 1295 if (typeof this.mapping === "object") { 1296 let _this = this; 1297 Object.keys(this.mapping).forEach( 1298 function (breakpointMap) { 1299 let nB = Number(breakpointMap); 1300 if (screenW > nB) { 1301 tempSizes = []; 1302 let sizes = _this.mapping[breakpointMap];
1303 sizes.forEach(function (size) { tempSizes.push(size) }); 1304 } 1305 } 1306 ); 1307 amzSizes = tempSizes; 1308 } 1309 1310 if (amzSizes.length <= 0) { 1311 amzSizes = this.sizes; 1312 } 1313 1314 return amzSizes; 1315 } 1316 1317 put() { 1318 if (this.lazy == true) { 1319 window.otempoadstag.push(this); 1320 let order = [0, 1, 2, 3]; 1321 window.otempoadstag.sort((x, y) => order.indexOf(x.priority) - order.indexOf(y.priority)); 1322 } 1323 } 1324 displayOn() { 1325 let _this; 1326 window.googletag.cmd.push( 1327 function () { 1328 let placeAds = document.getElementById(_this.id); 1329 if (placeAds) { 1330 window.googletag.display(_this.googletag); 1331 _this.firstCall = true; 1332 console.log('Ads Display...', _this); 1333 } 1334 }, 1335 [(_this = this)], 1336 ); 1337 }; 1338 1339 setRefresh() { 1340 let _this; 1341 this.googletag.pubads().addEventListener( 1342 'impressionViewable', 1343 function (event) { 1344 const slot = event.slot; 1345 if (slot === _this.googletag && !_this.refreshing && _this.refresh) { 1346 if (_this.qtyRefresh <= _this.limitRefresh) { 1347 console.log('Ads impressionViewable... Refresh to', _this.timeToRefresh, _this, slot.getSlotElementId()); 1348 _this.refreshing = true; 1349 setTimeout( 1350 function (obj) { 1351 if (!obj.amazonBid) { 1352 obj.doRefresh(); 1353 } else { 1354 obj.amazonDoBid(); 1355 } 1356 }, 1357 _this.timeToRefresh, 1358 _this, 1359 ); 1360 } 1361 } 1362 }, 1363 [(_this = this)] 1364 ); 1365 }; 1366 1367 doRefresh() { 1368 let _this; 1369 window.googletag.cmd.push( 1370 function () { 1371 _this.googletag.setTargeting('refreshed_slot', true); 1372 _this.qtyRefresh++; 1373 _this.googletag.setTargeting('refreshed_number', _this.qtyRefresh); 1374 console.log('Ads Refreshed...', _this.qtyRefresh, _this); 1375 _this.refreshing = false; 1376 window.googletag.pubads().refresh([_this.googletag]); 1377 }, 1378 [(_this = this)], 1379 ); 1380 }; 1381 1382 elementIsVisibleInViewport(el, partiallyVisible = false) { 1383 const { top, left, bottom, right } = el.getBoundingClientRect(); 1384 const { innerHeight, innerWidth } = window; 1385 return partiallyVisible 1386 ? ((top > 0 && top < innerHeight) || 1387 (bottom > 0 && bottom < innerHeight)) && 1388 ((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth)) 1389 : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth; 1390 }; 1391}; 1392 1393 1394// addig the amazon ads libraries 1395// 1396// 1397function AdAmazonBids(googletag) { 1398 this.apstag = {} 1399 this.breakpoint = 1100; 1400 this.screentype = screen.width < this.breakpoint ? 'mobile' : 'desktop'; 1401 this.googletag = googletag; 1402 1403 if (!googletag) { 1404 this.loadLibrary(); 1405 return false; 1406 } 1407 1408 if (googletag.sizes.length <= 0) { 1409 return false; 1410 } 1411 1412 this.loadLibrary(); 1413 1414 var slot = { 1415 slotID: googletag.id, 1416 slotName: googletag.path, 1417 sizes: [] 1418 }; 1419 1420 var _this = this; 1421 var _googletag = this.googletag; 1422 1423 if (typeof googletag.mapping === "object") { 1424 Object.keys(googletag.mapping).forEach( 1425 function (breakpointMap) { 1426 if (_this.screentype == "mobile") { 1427 if (Number(breakpointMap) < _this.breakpoint) { 1428 var sizes = _googletag.mapping[breakpointMap];
1429 sizes.forEach(function (size) { slot.sizes.push(size) }); 1430 } 1431 } else { 1432 if (Number(breakpointMap) >= _this.breakpoint) { 1433 var sizes = _googletag.mapping[breakpointMap]; 1434 sizes.forEach(function (size) { slot.sizes.push(size) }); 1435 } 1436 } 1437 } 1438 ); 1439 } 1440 1441 if (slot.sizes.length <= 0) { 1442 slot.sizes = googletag.sizes; 1443 } 1444 console.log('Amazon: fetchBids', this); 1445 apstag['_Q'] = this.apstag._Q; 1446 apstag.fetchBids({ slots: [slot] }, function (bid) { 1447 var __this = {}; 1448 window.googletag.cmd.push(function () { 1449 try { 1450 __this.apstag.setDisplayBids(); 1451 //window.googletag.pubads().refresh([__this.googletag.googletag]); 1452 console.log('Amazon: setDisplayBids', __this); 1453 } catch (error) { 1454 console.log('Amazon: setDisplayBidsError', error, __this); 1455 } 1456 }, [(__this = _this)]); 1457 }, [(_this = this)]); 1458} 1459 1460AdAmazonBids.prototype.loadLibrary = function () { 1461 console.log('load', window.thirdPartAdsAmazon); 1462 if (typeof window.thirdPartAdsAmazon !== 'object') { 1463 apstag.init({ 1464 pubID: 'ee79b9e9-a905-4adf-925b-211c64726bba', 1465 adServer: 'googletag', 1466 bidTimeout: 2e3 1467 }); 1468 console.log('Amazon: loadLibrary', apstag); 1469 this.apstag = window.apstag; 1470 window.thirdPartAdsAmazon = this.apstag; 1471 } else { 1472 console.log('Amazon Ja Carregado: loadLibrary', apstag); 1473 this.apstag = window.thirdPartAdsAmazon; 1474 } 1475} 1476 1477// addig the thirdPartAds Mananger 1478// 1479// 1480window.thirdPartAds = function (gtag) { 1481 try { 1482 AdAB = new AdAmazonBids(gtag); 1483 } catch (error) { 1484 console.log('Amazon: Start Error', error, gtag); 1485 } 1486} 1487window.thirdPartAdsLoad = function () { 1488 try { 1489 AdAB = new AdAmazonBids(false); 1490 } catch (error) { 1491 console.log('Amazon: Load Error'); 1492 } 1493} 1494window.thirdPartAdsRegister = function (gtag) { 1495 try { 1496 window.thirdPartAdsItens.push(gtag); 1497 } catch (error) { 1498 console.log('Amazon: Register Error'); 1499 } 1500} 1501 1502window.thirdPartAdsLoadRegister = function () { 1503 try { 1504 if (typeof window.thirdPartAdsItens == 'object') { 1505 if (window.thirdPartAdsItens.length > 0) { 1506 for (var oadsI = 0; oadsI < window.thirdPartAdsItens.length; oadsI++) { 1507 window.thirdPartAds(thirdPartAdsItens[oadsI]); 1508 } 1509 } 1510 } 1511 } catch (error) { 1512 console.log('Amazon: Register Load Error'); 1513 } 1514}
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.