Skip to content

Commit

Permalink
Merge pull request #175 from reuters-graphics/ads-collapse
Browse files Browse the repository at this point in the history
Ads collapse
  • Loading branch information
hobbes7878 authored Sep 24, 2024
2 parents 349f219 + d459852 commit 89b1f24
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilly-eyes-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reuters-graphics/graphics-components': patch
---

Ads will collapse if unfulfilled
6 changes: 6 additions & 0 deletions src/components/AdSlot/AdSlot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@
</script>

<div data-freestar-ad="{dataFreestarAd || null}" id="{adId}"></div>

<style>
:global(div.freestar-adslot:has(.unfulfilled-ad)) {
display: none;
}
</style>
2 changes: 1 addition & 1 deletion src/components/AdSlot/LeaderboardAd.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<svelte:window bind:innerWidth="{windowWidth}" />

<div
class="leaderboard__sticky {cls}"
class="freestar-adslot leaderboard__sticky {cls}"
class:sticky
class:unstick
{id}
Expand Down
13 changes: 13 additions & 0 deletions src/components/AdSlot/adScripts/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ export const loadBootstrap = () => {
// @ts-ignore window global
window.googletag.pubads().enableAsyncRendering();
window.googletag.pubads().collapseEmptyDivs(true);

window.googletag
.pubads()
.addEventListener('slotRenderEnded', function (event) {
const adDiv = document.getElementById(event.slot.getSlotElementId());
if (!adDiv) return;
// If the ad slot is empty
if (event.isEmpty) {
adDiv.classList.add('unfulfilled-ad');
} else {
adDiv.classList.remove('unfulfilled-ad');
}
});
});

// Set page-level key-values
Expand Down

0 comments on commit 89b1f24

Please sign in to comment.