Skip to content

Commit eceb7b2

Browse files
feat(ads): AdSense 자동 광고 → 수동 배치로 전환
자동 광고(auto_ads) 비활성화하고 3곳에 수동 광고 배치: - 포스트 본문 중간 (5번째 문단 이후, JS 동적 삽입) - 포스트 본문 하단 (content 끝) - 좌우 플로팅 광고 (1400px 이상 화면에서만 표시)
1 parent 0563b01 commit eceb7b2

6 files changed

Lines changed: 101 additions & 2 deletions

File tree

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ google_analytics: G-E2F9P3J8TQ # 실제 GA4 측정 ID로 교체 필요
1616
# Google AdSense
1717
adsense:
1818
client: ca-pub-4992764083187170
19-
auto_ads: true
19+
auto_ads: false
2020
show_ads: true
2121

2222
# Comments system

_includes/ad-banner.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% if site.adsense.client and site.adsense.show_ads %}
2+
<div class="ad-container">
3+
<ins class="adsbygoogle"
4+
style="display:block"
5+
data-ad-client="{{ site.adsense.client }}"
6+
data-ad-slot="2396306733"
7+
data-ad-format="auto"
8+
data-full-width-responsive="true"></ins>
9+
<script>
10+
(adsbygoogle = window.adsbygoogle || []).push({});
11+
</script>
12+
</div>
13+
{% endif %}

_includes/ad-floating.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% if site.adsense.client and site.adsense.show_ads %}
2+
<div class="ad-floating ad-floating-left">
3+
<ins class="adsbygoogle"
4+
style="display:block"
5+
data-ad-client="{{ site.adsense.client }}"
6+
data-ad-slot="2396306733"
7+
data-ad-format="vertical"
8+
data-full-width-responsive="false"></ins>
9+
<script>
10+
(adsbygoogle = window.adsbygoogle || []).push({});
11+
</script>
12+
</div>
13+
<div class="ad-floating ad-floating-right">
14+
<ins class="adsbygoogle"
15+
style="display:block"
16+
data-ad-client="{{ site.adsense.client }}"
17+
data-ad-slot="2396306733"
18+
data-ad-format="vertical"
19+
data-full-width-responsive="false"></ins>
20+
<script>
21+
(adsbygoogle = window.adsbygoogle || []).push({});
22+
</script>
23+
</div>
24+
{% endif %}

_layouts/default.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@
8787
<!-- Header -->
8888
{% include header.html %}
8989

90+
<!-- Floating Side Ads -->
91+
{% include ad-floating.html %}
92+
9093
<!-- Main Content -->
9194
<main class="main-content">
9295
{{ content }}
9396
</main>
94-
97+
9598
<!-- Footer -->
9699
{% include footer.html %}
97100

_layouts/post.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ <h1 class="post-title">{{ page.title }}</h1>
9898
<div class="post-content">
9999
<div class="container">
100100
{{ content }}
101+
102+
{% include ad-banner.html %}
101103
</div>
102104
</div>
103105

@@ -181,3 +183,23 @@ <h3 class="nav-heading">{{ lang_data.ui.other_posts | default: "Other Posts" }}<
181183
});
182184
}
183185
</script>
186+
187+
{% if site.adsense.client and site.adsense.show_ads %}
188+
<script>
189+
document.addEventListener('DOMContentLoaded', function() {
190+
var postContent = document.querySelector('.post-content .container');
191+
if (!postContent) return;
192+
193+
var paragraphs = postContent.querySelectorAll(':scope > p');
194+
if (paragraphs.length < 6) return;
195+
196+
var target = paragraphs[4];
197+
var adDiv = document.createElement('div');
198+
adDiv.className = 'ad-container ad-in-article';
199+
adDiv.innerHTML = '<ins class="adsbygoogle" style="display:block" data-ad-client="{{ site.adsense.client }}" data-ad-slot="2396306733" data-ad-format="auto" data-full-width-responsive="true"></ins>';
200+
target.parentNode.insertBefore(adDiv, target.nextSibling);
201+
202+
(adsbygoogle = window.adsbygoogle || []).push({});
203+
});
204+
</script>
205+
{% endif %}

assets/css/main.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,3 +1797,40 @@ a:hover {
17971797
gap: var(--spacing-xs);
17981798
}
17991799
}
1800+
1801+
/* ===========================
1802+
ADSENSE
1803+
=========================== */
1804+
.ad-container {
1805+
margin: 2rem 0;
1806+
text-align: center;
1807+
min-height: 100px;
1808+
}
1809+
1810+
.ad-in-article {
1811+
margin: 2.5rem 0;
1812+
}
1813+
1814+
/* Floating side ads */
1815+
.ad-floating {
1816+
position: fixed;
1817+
top: 50%;
1818+
transform: translateY(-50%);
1819+
width: 160px;
1820+
z-index: 50;
1821+
display: none;
1822+
}
1823+
1824+
.ad-floating-left {
1825+
left: calc((100vw - 1000px) / 2 - 180px);
1826+
}
1827+
1828+
.ad-floating-right {
1829+
right: calc((100vw - 1000px) / 2 - 180px);
1830+
}
1831+
1832+
@media (min-width: 1400px) {
1833+
.ad-floating {
1834+
display: block;
1835+
}
1836+
}

0 commit comments

Comments
 (0)