Skip to content

Commit 01c4a6f

Browse files
committed
chore: add initial anchor implementation for ads
1 parent 340f388 commit 01c4a6f

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, { useEffect } from 'react'
2+
import styles from './styles.module.css'
3+
4+
const AdsContainerElement = ({ id }) => {
5+
useEffect(() => {
6+
if (typeof window !== 'undefined') {
7+
window.dispatchEvent(new CustomEvent('AdsContainerMounted', { detail: { id } }))
8+
}
9+
}, [])
10+
11+
return <div id={id} className={styles.adsContainer} />
12+
}
13+
14+
export default AdsContainerElement
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
.adsContainer {
32
position: sticky;
43
top: calc(3.75rem + 12rem);
5-
width: 300px;
6-
height: 250px;
4+
/* width: 300px; */
5+
/* height: 250px; */
76
}

docs/src/theme/Footer/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable import/no-unresolved */
2+
import React from 'react'
3+
import Footer from '@theme-original/Footer'
4+
// import AdsContainerElement from '@site/src/components/AdsContainerElement'
5+
6+
export default function FooterWrapper(props) {
7+
return (
8+
<>
9+
<Footer {...props} />
10+
{/* <AdsContainerElement id="mobile-anchor-ads" /> */}
11+
</>
12+
)
13+
}

docs/src/theme/TOC/index.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
import React, { useEffect } from 'react'
1+
/* eslint-disable import/no-unresolved */
2+
import React from 'react'
23
import TOC from '@theme-original/TOC'
3-
4-
import styles from './index.module.css'
5-
6-
const AdsContainerElement = ({ id }) => {
7-
useEffect(() => {
8-
if (typeof window !== 'undefined') {
9-
window.dispatchEvent(new CustomEvent('AdsContainerMounted', { detail: { id } }))
10-
}
11-
}, [])
12-
13-
return <div id={id} className={styles.adsContainer} />
14-
}
4+
import AdsContainerElement from '@site/src/components/AdsContainerElement'
155

166
export default function TOCWrapper(props) {
177
return (

docs/static/js/gpt.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// prevent loading ads in localhost
22
const development = window.location.host !== 'react-tooltip.com'
33
// use sandbox ads to test in localhost
4-
const slotPath = development
4+
const slotPathRightSidebarAdUnit = development
55
? '/6355419/Travel/Europe/France/Paris'
66
: '/22862227500/desktop-sidebar-right'
7+
const slotPathAnchorAdUnit = development ? '/6355419/Travel' : '/22862227500/desktop-sidebar-right'
78

89
window.reactTooltipAds = {
910
initialized: {},
@@ -13,15 +14,22 @@ window.googletag = window.googletag || { cmd: [] }
1314

1415
window.googletag.cmd.push(function () {
1516
window.googletag
16-
.defineSlot(slotPath, [300, 250], 'right-sidebar-ads')
17+
.defineSlot(slotPathRightSidebarAdUnit, [300, 250], 'right-sidebar-ads')
18+
.addService(window.googletag.pubads())
19+
window.googletag.enableServices()
20+
})
21+
22+
window.googletag.cmd.push(function () {
23+
window.googletag
24+
.defineOutOfPageSlot(slotPathAnchorAdUnit, window.googletag.enums.OutOfPageFormat.BOTTOM_ANCHOR)
1725
.addService(window.googletag.pubads())
1826
window.googletag.enableServices()
1927
})
2028

2129
const handleLoadAds = (event) => {
2230
const { id } = event.detail
2331

24-
if (window.innerWidth < 1024) {
32+
if (window.innerWidth < 1024 && !id.includes('anchor')) {
2533
return
2634
}
2735

0 commit comments

Comments
 (0)