1
1
import React , { useEffect , useRef } from 'react' ;
2
2
import styled from 'styled-components' ;
3
3
import VelogResponsive from '../../components/velog/VelogResponsive' ;
4
- import media from '../../lib/styles/media' ;
5
-
6
4
interface Props { }
7
5
8
- function initDesktopAd ( ) {
9
- if ( window . innerWidth < 768 ) return ;
10
- ( function ( ) {
11
- var size = '728x90' ,
12
- adunit = 'velog.io_728x90_leaderboard_DFP' ,
13
- childNetworkId = '22738196472' ,
14
- xmlhttp = new XMLHttpRequest ( ) ;
15
- xmlhttp . onreadystatechange = function ( ) {
16
- if ( xmlhttp . readyState == 4 && xmlhttp . status == 200 ) {
17
- var es = document . querySelectorAll ( "[data-id='" + adunit + "']" ) ;
18
- var e = Array . from ( es ) . filter ( function ( e ) {
19
- return ! e . hasAttribute ( 'data-rendered' ) ;
20
- } ) ;
21
- if ( e . length > 0 ) {
22
- e . forEach ( function ( el : any ) {
23
- var iframe = el . contentWindow . document ;
24
- iframe . open ( ) ;
25
- iframe . write ( xmlhttp . responseText ) ;
26
- iframe . close ( ) ;
27
- el . setAttribute ( 'data-rendered' , true as any ) ;
28
- } ) ;
29
- }
30
- }
31
- } ;
32
- var child = childNetworkId . trim ( ) ? ',' + childNetworkId . trim ( ) : '' ;
33
- xmlhttp . open (
34
- 'GET' ,
35
- 'https://pubads.g.doubleclick.net/gampad/adx?iu=/147246189' +
36
- child +
37
- '/' +
38
- adunit +
39
- '&sz=' +
40
- encodeURI ( size ) +
41
- '&t=Placement_type%3Dserving&' +
42
- Date . now ( ) ,
43
- true ,
44
- ) ;
45
- xmlhttp . send ( ) ;
46
- } ) ( ) ;
47
- }
48
-
49
- function initMobileAd ( ) {
50
- ( function ( ) {
51
- if ( window . innerWidth > 580 ) return ;
52
- var size = '320x100' ,
53
- adunit = 'velog.io_320x100_leaderboard_DFP' ,
54
- childNetworkId = '22738196472' ,
55
- xmlhttp = new XMLHttpRequest ( ) ;
56
- xmlhttp . onreadystatechange = function ( ) {
57
- if ( xmlhttp . readyState == 4 && xmlhttp . status == 200 ) {
58
- var es = document . querySelectorAll ( "[data-id='" + adunit + "']" ) ;
59
- var e = Array . from ( es ) . filter ( function ( e ) {
60
- return ! e . hasAttribute ( 'data-rendered' ) ;
61
- } ) ;
62
- if ( e . length > 0 ) {
63
- e . forEach ( function ( el : any ) {
64
- var iframe = el . contentWindow . document ;
65
- iframe . open ( ) ;
66
- iframe . write ( xmlhttp . responseText ) ;
67
- iframe . close ( ) ;
68
- el . setAttribute ( 'data-rendered' , true ) ;
69
- } ) ;
70
- }
71
- }
72
- } ;
73
- var child = childNetworkId . trim ( ) ? ',' + childNetworkId . trim ( ) : '' ;
74
- xmlhttp . open (
75
- 'GET' ,
76
- 'https://pubads.g.doubleclick.net/gampad/adx?iu=/147246189' +
77
- child +
78
- '/' +
79
- adunit +
80
- '&sz=' +
81
- encodeURI ( size ) +
82
- '&t=Placement_type%3Dserving&' +
83
- Date . now ( ) ,
84
- true ,
85
- ) ;
86
- xmlhttp . send ( ) ;
87
- } ) ( ) ;
88
- }
89
-
90
6
function HorizontalAd ( { } : Props ) {
91
7
const ref = useRef < HTMLDivElement > ( null ) ;
92
8
const initializedRef = useRef ( false ) ;
@@ -97,8 +13,7 @@ function HorizontalAd({}: Props) {
97
13
entries . forEach ( ( entry ) => {
98
14
if ( entry . isIntersecting && ! initializedRef . current ) {
99
15
initializedRef . current = true ;
100
- initDesktopAd ( ) ;
101
- initMobileAd ( ) ;
16
+ ( window . adsbygoogle = window . adsbygoogle || [ ] ) . push ( { } ) ;
102
17
console . log ( 'initialized!' ) ;
103
18
}
104
19
} ) ;
@@ -118,30 +33,14 @@ function HorizontalAd({}: Props) {
118
33
return (
119
34
< VelogResponsive >
120
35
< Wrapper ref = { ref } >
121
- < Desktop >
122
- < iframe
123
- title = "desktop-horizontal"
124
- data-id = "velog.io_728x90_leaderboard_DFP"
125
- frameBorder = "0"
126
- scrolling = "no"
127
- marginHeight = { 0 }
128
- marginWidth = { 0 }
129
- width = "1"
130
- height = "1"
131
- > </ iframe >
132
- </ Desktop >
133
- < Mobile >
134
- < iframe
135
- title = "mobile-horizontal"
136
- data-id = "velog.io_320x100_leaderboard_DFP"
137
- frameBorder = "0"
138
- scrolling = "no"
139
- marginHeight = { 0 }
140
- marginWidth = { 0 }
141
- width = "1"
142
- height = "1"
143
- > </ iframe >
144
- </ Mobile >
36
+ < ins
37
+ className = "adsbygoogle"
38
+ style = { { display : 'block' , maxHeight : 400 , width : '100%' } }
39
+ data-ad-client = "ca-pub-5574866530496701"
40
+ data-ad-slot = "8809887603"
41
+ data-ad-format = "auto"
42
+ data-full-width-responsive = "true"
43
+ />
145
44
</ Wrapper >
146
45
</ VelogResponsive >
147
46
) ;
@@ -153,24 +52,4 @@ const Wrapper = styled.div`
153
52
margin-bottom: 1.5rem;
154
53
` ;
155
54
156
- const Desktop = styled . div `
157
- display: flex;
158
- justify-content: center;
159
- iframe {
160
- width: 728px;
161
- height: 90px;
162
- }
163
- ${ media . small } {
164
- display: none;
165
- }
166
- ` ;
167
-
168
- const Mobile = styled . div `
169
- display: none;
170
- justify-content: center;
171
- ${ media . custom ( 580 ) } {
172
- display: flex;
173
- }
174
- ` ;
175
-
176
55
export default HorizontalAd ;
0 commit comments