Skip to content

Commit d54a028

Browse files
committed
Load mobile sticky ads only when the reader revenue banner is not present
1 parent 4e6fd96 commit d54a028

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

bundle/src/insert/mobile-sticky.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { log } from '@guardian/libs';
12
import { createAdSlot } from '../lib/create-ad-slot';
23
import fastdom from '../lib/fastdom-promise';
34
import { shouldIncludeMobileSticky } from '../lib/header-bidding/utils';
@@ -33,15 +34,17 @@ const createAdWrapper = () => {
3334
*/
3435
export const init = (): Promise<void> => {
3536
if (shouldIncludeMobileSticky()) {
36-
const mobileStickyWrapper = createAdWrapper();
37-
return fastdom
38-
.mutate(() => {
39-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Is body really always defined?
40-
if (document.body && mobileStickyWrapper) {
41-
document.body.appendChild(mobileStickyWrapper);
42-
}
43-
})
44-
.then(() => {
37+
document.addEventListener('banner:close', () => {
38+
void (async () => {
39+
log('commercial', '🪵 Supporter revenue banner closed');
40+
const mobileStickyWrapper = createAdWrapper();
41+
42+
await fastdom.mutate(() => {
43+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Is body really always defined?
44+
if (document.body && mobileStickyWrapper) {
45+
document.body.appendChild(mobileStickyWrapper);
46+
}
47+
});
4548
if (mobileStickyWrapper) {
4649
const mobileStickyAdSlot =
4750
mobileStickyWrapper.querySelector<HTMLElement>(
@@ -51,7 +54,8 @@ export const init = (): Promise<void> => {
5154
void fillDynamicAdSlot(mobileStickyAdSlot, true);
5255
}
5356
}
54-
});
57+
})();
58+
});
5559
}
5660

5761
return Promise.resolve();

0 commit comments

Comments
 (0)