Skip to content

Commit 6ab8ad1

Browse files
committed
fix: in-article ads
1 parent 4214621 commit 6ab8ad1

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ url: "https://pyweekly.qiwihui.com" # change this to the base hostname & protoco
77
permalink: /:title
88

99
google_analytics: "UA-46660488-11"
10-
# google_adsense: "ca-pub-8935595858652656"
10+
google_adsense: "ca-pub-8935595858652656"
1111

1212
# cayman-blog date format
1313
# refer to http://shopify.github.io/liquid/filters/date/ if you want to customize this

_includes/analytics.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% if site.google_analytics %}
2+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
3+
<script>
4+
window.dataLayer = window.dataLayer || [];
5+
function gtag(){dataLayer.push(arguments);}
6+
gtag('js', new Date());
7+
gtag('config', '{{ site.google_analytics }}');
8+
</script>
9+
{% endif %}

_includes/auto-ads.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1+
<!--
12
{% if site.google_adsense %}
23
<script data-ad-client="{{ site.google_adsense }}" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">
34
</script>
5+
{% endif %}
6+
-->
7+
8+
{% if page.layout == 'post' %}
9+
{% if site.google_adsense %}
10+
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
11+
<ins class="adsbygoogle"
12+
style="display:block; text-align:center;"
13+
data-ad-layout="in-article"
14+
data-ad-format="fluid"
15+
data-ad-client="{{ site.google_adsense }}"
16+
data-ad-slot="2654019047"></ins>
17+
<script>
18+
(adsbygoogle = window.adsbygoogle || []).push({});
19+
</script>
20+
{% endif %}
421
{% endif %}

_layouts/default.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@
22
<html lang="{{ page.lang | default: site.lang | default: "en" }}">
33

44
<head>
5-
6-
{% if site.google_analytics %}
7-
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
8-
<script>
9-
window.dataLayer = window.dataLayer || [];
10-
function gtag(){dataLayer.push(arguments);}
11-
gtag('js', new Date());
12-
gtag('config', '{{ site.google_analytics }}');
13-
</script>
14-
{% endif %}
5+
6+
{% include analytics.html %}
157

168
{% include auto-ads.html %}
179

0 commit comments

Comments
 (0)