Skip to content

Commit ac6b4c1

Browse files
authored
Merge pull request #27 from Seol-JY/feature/new
[FEAT]: 광고 삽입 시도
2 parents 734b68e + 002596c commit ac6b4c1

File tree

4 files changed

+90
-16
lines changed

4 files changed

+90
-16
lines changed

client/public/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html lang="kr" data-theme="light">
33
<head>
44
<meta charset="utf-8" />
5+
<meta name="google-adsense-account" content="ca-pub-8658385917169302" />
56
<meta
67
name="google-site-verification"
78
content="x96FdMXm-uHwvLPsY__UXOIvT3CNgHMApLx5Ki6TZ9w"
@@ -16,6 +17,11 @@
1617
href="https://fonts.googleapis.com/icon?family=Material+Icons"
1718
rel="stylesheet"
1819
/>
20+
<script
21+
async
22+
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8658385917169302"
23+
crossorigin="anonymous"
24+
></script>
1925
<title>Speed Coder</title>
2026
</head>
2127
<body onpaste="return false">

client/src/components/LeaderBoard.jsx

+29-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fetcher from "../utils/fetcher";
22
import { useState, useEffect, useCallback } from "react";
33
import { useInView } from "react-intersection-observer";
44
import LeaderBoardContents from "./LeaderBoardContents";
5+
import InFeedAdvertise from "./advertises/InFeedAdvertise";
56

67
export default function LeaderBoard({ daynight }) {
78
const [prev, prevInView] = useInView(); // 무한 스크롤용 ref - 이전
@@ -62,26 +63,38 @@ export default function LeaderBoard({ daynight }) {
6263
</ul>
6364
) : (
6465
<ul className="sidebarsection-rank">
65-
{items.map((s, i) => {
66-
// if (i === 2) {
67-
// return (
68-
// <li key={s._id} ref={prev}>
69-
// <LeaderBoardContents s={s} />
70-
// </li>
71-
// );
72-
if (i === items.length - 1) {
66+
{items
67+
.map((s, i) => {
68+
// if (i === 2) {
69+
// return (
70+
// <li key={s._id} ref={prev}>
71+
// <LeaderBoardContents s={s} />
72+
// </li>
73+
// );
74+
if (i === items.length - 1) {
75+
return (
76+
<li key={s._id} ref={next}>
77+
<LeaderBoardContents s={s} />
78+
</li>
79+
);
80+
}
7381
return (
74-
<li key={s._id} ref={next}>
82+
<li key={s._id}>
7583
<LeaderBoardContents s={s} />
7684
</li>
7785
);
78-
}
79-
return (
80-
<li key={s._id}>
81-
<LeaderBoardContents s={s} />
82-
</li>
83-
);
84-
})}
86+
})
87+
.reduce((acc, curr, i) => {
88+
if (i === 3) {
89+
acc.push(
90+
<li key="advertise">
91+
<InFeedAdvertise />
92+
</li>
93+
);
94+
}
95+
acc.push(curr);
96+
return acc;
97+
}, [])}
8598
{loading && (
8699
<li>
87100
<ul>

client/src/components/Sidebar.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
22
import Debug from "./Debug";
33
import LeaderBoard from "./LeaderBoard";
44
import IconGenerator from "./IconGenerator";
5+
import InFeedAdvertise from "./advertises/InFeedAdvertise";
56

67
export default function Sidebar(props) {
78
const [filestate, setFilestate] = useState("hello.py");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { useEffect } from "react";
2+
3+
const InFeedAdvertise = ({
4+
className = "adsbygoogle",
5+
client = "ca-pub-8658385917169302",
6+
slot = "1562420452",
7+
format = "fluid",
8+
layoutKey = "-fp+68-11-df+sd",
9+
}) => {
10+
useEffect(() => {
11+
if (process.env.NODE_ENV === "production")
12+
try {
13+
(window.adsbygoogle = window.adsbygoogle || []).push({});
14+
console.log("Advertise is pushed");
15+
} catch (e) {
16+
console.error("AdvertiseError", e);
17+
}
18+
}, []);
19+
20+
//production이 아닌 경우 대체 컴포넌트 표시
21+
if (process.env.NODE_ENV !== "production")
22+
return (
23+
<div
24+
style={{
25+
background: "#8aff8a",
26+
color: "black",
27+
fontSize: "18px",
28+
fontWeight: "bold",
29+
textAlign: "center",
30+
padding: "16px",
31+
}}
32+
>
33+
광고 표시 영역
34+
</div>
35+
);
36+
//production인 경우 구글 광고 표시
37+
return (
38+
<ins
39+
className={className}
40+
style={{
41+
overflowX: "auto",
42+
overflowY: "hidden",
43+
display: "block",
44+
textAlign: "center",
45+
}}
46+
data-ad-client={client}
47+
data-ad-slot={slot}
48+
data-ad-format={format}
49+
data-ad-layout-key={layoutKey}
50+
/>
51+
);
52+
};
53+
54+
export default InFeedAdvertise;

0 commit comments

Comments
 (0)