From 52eab435e7a104a942eee17816f6b69329678258 Mon Sep 17 00:00:00 2001 From: hobbes7878 Date: Tue, 24 Sep 2024 05:54:59 +0100 Subject: [PATCH 1/2] collapse unfulfilled ads by adding a class to the ad unit and collapsing the container with css :has --- src/components/AdSlot/AdSlot.svelte | 6 ++++++ src/components/AdSlot/LeaderboardAd.svelte | 2 +- src/components/AdSlot/adScripts/bootstrap.ts | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/AdSlot/AdSlot.svelte b/src/components/AdSlot/AdSlot.svelte index e258fb46..b6dee7e0 100644 --- a/src/components/AdSlot/AdSlot.svelte +++ b/src/components/AdSlot/AdSlot.svelte @@ -53,3 +53,9 @@
+ + diff --git a/src/components/AdSlot/LeaderboardAd.svelte b/src/components/AdSlot/LeaderboardAd.svelte index 80f7a359..20952495 100644 --- a/src/components/AdSlot/LeaderboardAd.svelte +++ b/src/components/AdSlot/LeaderboardAd.svelte @@ -47,7 +47,7 @@
{ // @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 From d4598527a72b7cfb743b5f00611fc572aef753ba Mon Sep 17 00:00:00 2001 From: hobbes7878 Date: Tue, 24 Sep 2024 05:55:33 +0100 Subject: [PATCH 2/2] docs(changeset): Ads will collapse if unfulfilled --- .changeset/chilly-eyes-hear.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilly-eyes-hear.md diff --git a/.changeset/chilly-eyes-hear.md b/.changeset/chilly-eyes-hear.md new file mode 100644 index 00000000..868f9742 --- /dev/null +++ b/.changeset/chilly-eyes-hear.md @@ -0,0 +1,5 @@ +--- +'@reuters-graphics/graphics-components': patch +--- + +Ads will collapse if unfulfilled