Skip to content

Commit a7cbf85

Browse files
committed
ALL H2 ADS LOADING
1 parent 6714edf commit a7cbf85

4 files changed

Lines changed: 20 additions & 100 deletions

File tree

src/components/ads/H3Ad.astro

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/components/ads/InArticleAd.astro

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
<div class="in-article-ad-container">
66
<span class="ad-label">Advertisement</span>
77
<ins
8-
class="adsbygoogle"
9-
style="display:block; text-align:center;"
10-
data-ad-layout="in-article"
11-
data-ad-format="fluid"
12-
data-ad-client="ca-pub-7993314093599705"
13-
data-ad-slot="8594941706"></ins>
8+
class="adsbygoogle"
9+
style="display:block; text-align:center;"
10+
data-ad-layout="in-article"
11+
data-ad-format="fluid"
12+
data-ad-client="ca-pub-7993314093599705"
13+
data-ad-slot="8594941706"></ins>
14+
<script is:inline>
15+
(adsbygoogle = window.adsbygoogle || []).push({});
16+
</script>
1417
<span class="ad-label">Advertisement</span>
1518
</div>
1619

1720
<style>
1821
.in-article-ad-container {
19-
display: none; /* Hidden by default, shown via script for specific instances */
22+
display: block;
2023
margin: 2rem 0;
2124
text-align: center;
2225
overflow: hidden;

src/pages/blog/[...slug].astro

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,16 @@ const components = {
260260
// Show the ad
261261
(ad as HTMLElement).style.display = 'block';
262262

263-
// Trigger AdSense
264-
try {
265-
console.log(`H2Ad: Pushing ad #${index + 1} to adsbygoogle`);
266-
((window as any).adsbygoogle = (window as any).adsbygoogle || []).push({});
267-
} catch (e) {
268-
console.error(`H2Ad: AdSense push failed for ad #${index + 1}`, e);
269-
}
263+
// Trigger AdSense with a staggered delay (e.g., 500ms apart)
264+
// This prevents race conditions or rate limiting when pushing multiple ads
265+
setTimeout(() => {
266+
try {
267+
console.log(`H2Ad: Pushing ad #${index + 1} to adsbygoogle`);
268+
((window as any).adsbygoogle = (window as any).adsbygoogle || []).push({});
269+
} catch (e) {
270+
console.error(`H2Ad: AdSense push failed for ad #${index + 1}`, e);
271+
}
272+
}, 500 * index + 100);
270273
});
271274
});
272275
</script>

src/scripts/insertAd.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)