-
Notifications
You must be signed in to change notification settings - Fork 18
/
adsense.tsx
64 lines (60 loc) · 1.28 KB
/
adsense.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { useEffect } from 'react';
interface Props {
className?: string;
style?: React.CSSProperties;
client: string;
slot: string;
layout?: string;
layoutKey?: string;
format?: string;
responsive?: string;
pageLevelAds?: boolean;
adTest?: string;
children?: React.ReactNode;
}
export function Adsense({
className = '',
style = { display: 'block' },
client,
slot,
layout = '',
layoutKey = '',
format = 'auto',
responsive = 'false',
pageLevelAds = false,
adTest,
children,
...rest
}: Props) {
useEffect(() => {
const p: any = {};
if (pageLevelAds) {
p.google_ad_client = client;
p.enable_page_level_ads = true;
}
try {
if (typeof window === 'object') {
((window as any).adsbygoogle = (window as any).adsbygoogle || []).push(p);
}
} catch {
// Pass
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<ins
className={`adsbygoogle ${className}`}
style={style}
data-ad-client={client}
data-ad-slot={slot}
data-ad-layout={layout}
data-ad-layout-key={layoutKey}
data-ad-format={format}
data-full-width-responsive={responsive}
data-adtest={adTest}
{...rest}
>
{children}
</ins>
);
}