-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGoogleAd.tsx
35 lines (29 loc) · 914 Bytes
/
GoogleAd.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, {useEffect, useState} from 'react';
const timeout = 200;
function GoogleAd({ classNames = "", slot, googleAdId, style, format = "autorelaxed" }) {
const [googleInit, setGoogleInit] = useState(0);
useEffect(() => {
if (!googleInit) {
setGoogleInit(setTimeout(() => {
if (typeof window !== 'undefined')
((window as any).adsbygoogle = (window as any).adsbygoogle || []).push({});
}, timeout));
}
return () => {
clearTimeout(googleInit);
}
}, [googleInit])
return (
<div className={classNames}>
<ins
className="adsbygoogle"
style={style || { display: 'block', width: 768, height: 90, textAlign: "center" }}
data-ad-client={googleAdId}
data-ad-slot={slot}
data-ad-format={format || "auto"}
data-full-width-responsive="true"
></ins>
</div>
);
}
export default GoogleAd;