Skip to content

Commit 8576cd4

Browse files
committed
Show ads in old post & conditional mobile ads
1 parent 3cd5b73 commit 8576cd4

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

src/components/common/AdFeed.tsx

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
1-
import React, { useEffect } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import styled from 'styled-components';
33
import { mediaQuery } from '../../lib/styles/media';
44

55
function AdFeed() {
6+
const [isMobile, setIsMobile] = useState(false);
7+
68
useEffect(() => {
7-
(window.adsbygoogle = window.adsbygoogle || []).push({});
9+
const width = window.innerWidth;
10+
if (width < 768) {
11+
setIsMobile(true);
12+
}
13+
14+
setTimeout(() => {
15+
(window.adsbygoogle = window.adsbygoogle || []).push({});
16+
}, 250);
817
}, []);
918

1019
return (
1120
<Block>
12-
{/* <ins
13-
className="adsbygoogle"
14-
style={{ display: 'block' }}
15-
data-ad-format="fluid"
16-
data-ad-layout-key="-6z+el+w-4n+70"
17-
data-ad-client="ca-pub-5574866530496701"
18-
data-ad-slot="8258809297"
19-
></ins> */}
20-
<ins
21-
className="adsbygoogle"
22-
style={{ display: 'block' }}
23-
data-ad-client="ca-pub-5574866530496701"
24-
data-ad-slot="6548419604"
25-
data-ad-format="auto"
26-
data-full-width-responsive="true"
27-
></ins>
21+
{isMobile ? (
22+
<ins
23+
className="adsbygoogle"
24+
style={{ display: 'block' }}
25+
data-ad-format="fluid"
26+
data-ad-layout-key="-6z+el+w-4n+70"
27+
data-ad-client="ca-pub-5574866530496701"
28+
data-ad-slot="8258809297"
29+
></ins>
30+
) : (
31+
<ins
32+
className="adsbygoogle"
33+
style={{ display: 'block' }}
34+
data-ad-client="ca-pub-5574866530496701"
35+
data-ad-slot="6548419604"
36+
data-ad-format="auto"
37+
data-full-width-responsive="true"
38+
></ins>
39+
)}
2840
</Block>
2941
);
3042
}

src/containers/post/PostViewer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,12 @@ const PostViewer: React.FC<PostViewerProps> = ({
367367
/>
368368
</UserProfileWrapper>
369369
<LinkedPostList linkedPosts={post.linked_posts} />
370-
<RelatedPost />
370+
<RelatedPost
371+
showAds={
372+
Date.now() - new Date(post.released_at).getTime() >
373+
1000 * 60 * 60 * 24 * 30 * 3
374+
}
375+
/>
371376
<PostComments
372377
count={post.comments_count}
373378
comments={post.comments}

src/containers/post/RelatedPost.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import VelogResponsive from '../../components/velog/VelogResponsive';
44
import { detectAnyAdblocker } from 'just-detect-adblock';
55
import media from '../../lib/styles/media';
66

7-
function RelatedPost() {
7+
function RelatedPost({ showAds }: { showAds: boolean }) {
88
const [isMobile, setIsMobile] = useState(false);
99
const [visible, setVisible] = useState(true);
1010
useEffect(() => {
@@ -37,7 +37,7 @@ function RelatedPost() {
3737
style={{ display: 'block' }}
3838
data-ad-format="autorelaxed"
3939
data-ad-client="ca-pub-5574866530496701"
40-
data-ad-slot="7478357897"
40+
data-ad-slot={showAds ? '3841144022' : '7478357897'}
4141
data-matched-content-ui-type="image_stacked"
4242
data-matched-content-rows-num="2"
4343
data-matched-content-columns-num="3"
@@ -49,7 +49,7 @@ function RelatedPost() {
4949
style={{ display: 'block' }}
5050
data-ad-format="autorelaxed"
5151
data-ad-client="ca-pub-5574866530496701"
52-
data-ad-slot="7478357897"
52+
data-ad-slot={showAds ? '3841144022' : '7478357897'}
5353
data-matched-content-ui-type="image_stacked"
5454
data-matched-content-rows-num="3"
5555
data-matched-content-columns-num="2"

0 commit comments

Comments
 (0)