@@ -22,50 +22,25 @@ const adSlots = {
22
22
} ,
23
23
rightRail : {
24
24
id : 'div-gpt-ad-1738811978953-right-rail' ,
25
- sizes : [
26
- // [160, 600],
27
- [ 300 , 250 ] ,
28
- [ 250 , 250 ] ,
29
- ] ,
25
+ sizes : [ [ 300 , 250 ] ] ,
30
26
targeting : 'right-side-rail' ,
31
27
refreshInterval : 45_000 , // 45 seconds
32
28
} ,
33
29
leftRail : {
34
30
id : 'div-gpt-ad-1738811978953-left-rail' ,
35
- sizes : [
36
- // [160, 600],
37
- [ 300 , 250 ] ,
38
- ] ,
31
+ sizes : [ [ 300 , 250 ] ] ,
39
32
targeting : 'left-side-rail' ,
40
33
refreshInterval : 45_000 , // 45 seconds
41
34
} ,
42
- }
43
-
44
- const googleScriptFn = ( slots : typeof adSlots ) => {
45
- window . googletag = window . googletag || { cmd : [ ] }
46
- googletag . cmd . push ( function ( ) {
47
- // Define all ad slots
48
- const slotInstances = Object . values ( slots ) . map ( ( slot ) => {
49
- return googletag
50
- . defineSlot ( '/23278945940/TopLevel' , slot . sizes , slot . id )
51
- . addService ( googletag . pubads ( ) )
52
- . setTargeting ( slot . targeting , [ slot . targeting ] )
53
- } )
54
-
55
- googletag . pubads ( ) . enableSingleRequest ( )
56
- googletag . enableServices ( )
57
-
58
- // // Set individual refresh intervals for each ad
59
- // slotInstances.forEach((slotInstance, index) => {
60
- // const slot = Object.values(slots)[index]
61
- // setInterval(function () {
62
- // googletag.cmd.push(function () {
63
- // googletag.pubads().refresh([slotInstance])
64
- // })
65
- // }, slot.refreshInterval)
66
- // })
67
- } )
68
- }
35
+ } satisfies Record <
36
+ string ,
37
+ {
38
+ id : string
39
+ sizes : [ number , number ] [ ]
40
+ targeting : string
41
+ refreshInterval : number
42
+ }
43
+ >
69
44
70
45
export function GoogleScripts ( ) {
71
46
return (
@@ -74,24 +49,38 @@ export function GoogleScripts() {
74
49
async
75
50
src = "https://securepubads.g.doubleclick.net/tag/js/gpt.js"
76
51
> </ script >
77
-
78
- < script
79
- dangerouslySetInnerHTML = { {
80
- __html : `(${ googleScriptFn . toString ( ) } )(${ JSON . stringify ( adSlots ) } );` ,
81
- } }
82
- />
83
52
</ >
84
53
)
85
54
}
86
55
87
56
function Gad ( {
88
- adId ,
57
+ name ,
89
58
children,
90
59
...props
91
- } : { adId : string } & React . HTMLAttributes < HTMLDivElement > ) {
60
+ } : { name : keyof typeof adSlots } & React . HTMLAttributes < HTMLDivElement > ) {
61
+ const adSlot = adSlots [ name ] !
62
+ const adId = adSlot . id
63
+
92
64
React . useEffect ( ( ) => {
93
65
window . googletag . cmd . push ( function ( ) {
66
+ // Define all ad slots
67
+ const slot = window . googletag
68
+ . defineSlot ( '/23278945940/TopLevel' , adSlot . sizes , adSlot . id )
69
+ . addService ( window . googletag . pubads ( ) )
70
+ . setTargeting ( adSlot . targeting , [ adSlot . targeting ] )
71
+
72
+ window . googletag . pubads ( ) . enableSingleRequest ( )
73
+ window . googletag . enableServices ( )
94
74
window . googletag . display ( adId )
75
+
76
+ // // Set individual refresh intervals for each ad
77
+ // const interval = setInterval(function () {
78
+ // window.googletag.cmd.push(function () {
79
+ // window.googletag.pubads().refresh([slot])
80
+ // })
81
+ // }, slot.refreshInterval)
82
+
83
+ // return () => clearInterval(interval)
95
84
} )
96
85
} , [ ] )
97
86
@@ -121,10 +110,7 @@ export function GadLeader() {
121
110
122
111
export function GadFooter ( ) {
123
112
return (
124
- < Gad
125
- adId = { adSlots . footer . id }
126
- style = { { maxWidth : '728px' , aspectRatio : '728 / 90' } }
127
- />
113
+ < Gad name = "footer" style = { { maxWidth : '728px' , aspectRatio : '728 / 90' } } />
128
114
)
129
115
}
130
116
@@ -142,7 +128,7 @@ export function GadLeftRailSquare() {
142
128
export function GadRightRailSquare ( ) {
143
129
return (
144
130
< Gad
145
- adId = { adSlots . rightRail . id }
131
+ name = " rightRail"
146
132
className = "[aspect-ratio:250/250] xl:[aspect-ratio:300/250] flex items-center justify-center"
147
133
>
148
134
< Link
0 commit comments