refactor: detact adblock (#509)

* refactor: detact adblock

* perf: implement mobile detection
This commit is contained in:
Byungchul Kim 2022-08-15 21:31:38 +09:00 committed by GitHub
parent 516f72ad08
commit cf0bc9dc08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -53,6 +53,7 @@
"react": "17.0.2",
"react-adsense": "0.1.0",
"react-dom": "17.0.2",
"react-ga": "^3.3.1",
"react-hotkeys": "2.0.0",
"react-responsive-modal": "6.1.0",
"react-select": "4.3.1",

View File

@ -7,6 +7,7 @@ import { DefaultSeo } from 'next-seo'
import { GlobalHotKeys } from 'react-hotkeys'
import NProgress from 'nprogress'
import Package from '../package.json'
import ReactGA from 'react-ga'
import Logger from '@utils/Logger'
import { handlePWA, parseCookie, parseDockerhubTag, systemTheme } from '@utils/Tools'
@ -29,6 +30,9 @@ Router.events.on('routeChangeStart', NProgress.start)
Router.events.on('routeChangeComplete', NProgress.done)
Router.events.on('routeChangeError', NProgress.done)
// Google Analytics
ReactGA.initialize('UA-165454387-1')
const KoreanbotsApp = ({ Component, pageProps, err, cookie }: KoreanbotsProps): JSX.Element => {
const [ shortcutModal, setShortcutModal ] = useState(false)
const [ theme, setTheme ] = useState<Theme>('system')
@ -51,6 +55,10 @@ const KoreanbotsApp = ({ Component, pageProps, err, cookie }: KoreanbotsProps):
}
else setTheme(localStorage.theme)
setStandalone(handlePWA())
const script = document.querySelector('script[src*=googlesyndication]')
if (script) script.addEventListener('error', () => {ReactGA.ga('send', 'event', 'adblock', 'adblock_' + (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile|WPDesktop/i) ? 'mobile' : 'pc'))})
}, [])
return <div className={theme}>

View File

@ -7913,6 +7913,11 @@ react-fast-compare@^2.0.1:
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-2.0.4.tgz#e84b4d455b0fec113e0402c329352715196f81f9"
integrity sha512-suNP+J1VU1MWFKcyt7RtjiSWUjvidmQSlqu+eHslq+342xCbGTYmC0mEhPCOHxlW0CywylOC1u2DFAT+bv4dBw==
react-ga@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-3.3.1.tgz#d8e1f4e05ec55ed6ff944dcb14b99011dfaf9504"
integrity sha512-4Vc0W5EvXAXUN/wWyxvsAKDLLgtJ3oLmhYYssx+YzphJpejtOst6cbIHCIyF50Fdxuf5DDKqRYny24yJ2y7GFQ==
react-hotkeys@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/react-hotkeys/-/react-hotkeys-2.0.0.tgz#a7719c7340cbba888b0e9184f806a9ec0ac2c53f"