Skip to content

Commit 1730ffc

Browse files
committed
fixes
1 parent a35d32d commit 1730ffc

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

app/components/GoogleScripts.tsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,28 @@ function Gad({
6262
const adId = adSlot.id
6363

6464
React.useEffect(() => {
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])
65+
if (window.googletag) {
66+
window.googletag.cmd.push(function () {
67+
// Define all ad slots
68+
const slot = window.googletag
69+
.defineSlot('/23278945940/TopLevel', adSlot.sizes, adSlot.id)
70+
.addService(window.googletag.pubads())
71+
.setTargeting(adSlot.targeting, [adSlot.targeting])
7172

72-
window.googletag.pubads().enableSingleRequest()
73-
window.googletag.enableServices()
74-
window.googletag.display(adId)
73+
window.googletag.pubads().enableSingleRequest()
74+
window.googletag.enableServices()
75+
window.googletag.display(adId)
7576

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)
77+
// // Set individual refresh intervals for each ad
78+
// const interval = setInterval(function () {
79+
// window.googletag.cmd.push(function () {
80+
// window.googletag.pubads().refresh([slot])
81+
// })
82+
// }, slot.refreshInterval)
8283

83-
// return () => clearInterval(interval)
84-
})
84+
// return () => clearInterval(interval)
85+
})
86+
}
8587
}, [])
8688

8789
return (

0 commit comments

Comments
 (0)