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
+
4
6
interface Props { }
5
7
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
+
6
90
function HorizontalAd ( { } : Props ) {
7
91
const ref = useRef < HTMLDivElement > ( null ) ;
8
92
const initializedRef = useRef ( false ) ;
@@ -13,7 +97,8 @@ function HorizontalAd({}: Props) {
13
97
entries . forEach ( ( entry ) => {
14
98
if ( entry . isIntersecting && ! initializedRef . current ) {
15
99
initializedRef . current = true ;
16
- ( window . adsbygoogle = window . adsbygoogle || [ ] ) . push ( { } ) ;
100
+ initDesktopAd ( ) ;
101
+ initMobileAd ( ) ;
17
102
console . log ( 'initialized!' ) ;
18
103
}
19
104
} ) ;
@@ -33,14 +118,30 @@ function HorizontalAd({}: Props) {
33
118
return (
34
119
< VelogResponsive >
35
120
< Wrapper ref = { ref } >
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
- />
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 >
44
145
</ Wrapper >
45
146
</ VelogResponsive >
46
147
) ;
@@ -52,4 +153,24 @@ const Wrapper = styled.div`
52
153
margin-bottom: 1.5rem;
53
154
` ;
54
155
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
+
55
176
export default HorizontalAd ;
0 commit comments