Skip to content

Commit

Permalink
🐛 광고 스크립트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyu-dev authored Jan 2, 2024
2 parents c7b8b79 + 01a3bda commit b87692b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 15 deletions.
5 changes: 5 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<script defer src="https://cdn.swygbro.com/public/widget/swyg-widget.js"></script>
</head>
<body>
<script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1919598055512436"
crossorigin="anonymous"
></script>
<div id="root"></div>
</body>
</html>
52 changes: 52 additions & 0 deletions src/components/connections/DisplayAds.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useEffect, useRef } from 'react';
import styled from 'styled-components';

export const DisplayAds = () => {
const intervalId = useRef<NodeJS.Timeout | null>(null);

const clearTimer = () => {
if (intervalId.current) {
clearInterval(intervalId.current);
intervalId.current = null;
}
};

useEffect(() => {
const pushAd = () => {
try {
const adsbygoogle = window.adsbygoogle || [];
adsbygoogle.push({});
} catch (e) {
if (process.env.NODE_ENV !== 'production') {
throw e;
}
}
};

clearTimer();
intervalId.current = setInterval(() => {
if (window.adsbygoogle) {
pushAd();
clearTimer();
}
}, 1000);

return () => {
clearTimer();
};
}, []);

return (
<InsertedStyle
className="adsbygoogle"
data-ad-client="ca-pub-1919598055512436"
data-ad-slot="3745103035"
></InsertedStyle>
);
};

const InsertedStyle = styled.ins`
display: inline-block;
width: 100%;
height: 66px;
`;
1 change: 1 addition & 0 deletions src/components/connections/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { CheckModal } from './CheckModal';
export { DisplayAds } from './DisplayAds';
export { MyInfo } from './MyInfo';
export { ProtectedLogin } from './ProtectedLogin';
18 changes: 4 additions & 14 deletions src/components/templates/SearchTemplate/SearchMain/SearchMain.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { axiosFetch } from '@api/axios';
import { TBookDetail } from '@api/types';
import { Spacing } from '@components/common/Spacing';
import { DisplayAds } from '@components/connections';
import { Book } from '@components/templates/SearchTemplate/Book';
import { Alert } from '@utils/Alert';
import { convertError } from '@utils/errors';
Expand Down Expand Up @@ -58,20 +59,9 @@ export const SearchMain = () => {
return (
<Wrap>
<Spacing height={20} />
<BannerWrap
dangerouslySetInnerHTML={{
__html: `<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1919598055512436"
crossorigin="anonymous"></script>
<!-- contents/336x66 -->
<ins class="adsbygoogle"
style="display:inline-block;width:336px;height:66px"
data-ad-client="ca-pub-1919598055512436"
data-ad-slot="3745103035"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>`
}}
></BannerWrap>
<BannerWrap>
<DisplayAds />
</BannerWrap>
<Spacing height={18} />
<Title>지금 가장 인기 있는 책 TOP 10</Title>
<Spacing height={18} />
Expand Down
3 changes: 3 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare global {
var adsbygoogle: any[];
}
3 changes: 2 additions & 1 deletion src/hooks/axiosInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { setAccessToken, setLoading } from '@/store/reducers';
import { TAppDispatch } from '@/store/state';
import { authFetch, axiosFetch } from '@api/axios';
import { Alert } from '@utils/Alert';
import { convertError } from '@utils/errors';
import { useEffect } from 'react';
import { useDispatch } from 'react-redux';

Expand Down Expand Up @@ -80,7 +81,7 @@ export const useAxiosInterceptor = () => {
// 유저 토큰이 유효하지 않을 떄
else if (status === 401) {
Alert.error({
title: '유저정보가 올바르지 않습니다.',
title: convertError(message),
action: () => {
dispatch(setAccessToken(''));
localStorage.clear();
Expand Down

0 comments on commit b87692b

Please sign in to comment.