-
-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathgpt.js
50 lines (41 loc) · 1.45 KB
/
gpt.js
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
// prevent loading ads in localhost
const development = window.location.host !== 'react-tooltip.com'
// use sandbox ads to test in localhost
const slotPathRightSidebarAdUnit = development
? '/6355419/Travel/Europe/France/Paris'
: '/22862227500/desktop-sidebar-right'
const slotPathAnchorAdUnit = development ? '/6355419/Travel' : '/22862227500/desktop-sidebar-right'
window.reactTooltipAds = {
initialized: {},
}
window.googletag = window.googletag || { cmd: [] }
window.googletag.cmd.push(function () {
window.googletag
.defineSlot(slotPathRightSidebarAdUnit, [300, 250], 'right-sidebar-ads')
.addService(window.googletag.pubads())
window.googletag.enableServices()
})
window.googletag.cmd.push(function () {
window.googletag
.defineOutOfPageSlot(slotPathAnchorAdUnit, window.googletag.enums.OutOfPageFormat.BOTTOM_ANCHOR)
.addService(window.googletag.pubads())
window.googletag.enableServices()
})
const handleLoadAds = (event) => {
const { id } = event.detail
if (window.innerWidth < 1024 && !id.includes('anchor')) {
return
}
window.googletag.cmd.push(function () {
if (window.reactTooltipAds.initialized[id]) {
window.googletag.cmd.push(function () {
window.googletag.pubads().refresh()
})
window.googletag.display(id)
} else {
window.googletag.display(id)
window.reactTooltipAds.initialized[id] = true
}
})
}
window.addEventListener('AdsContainerMounted', handleLoadAds)