【发布时间】:2020-09-23 04:40:04
【问题描述】:
我正在尝试将 AdSense 自适应广告添加到我的 React 网络应用中。我按照 AdSense 帮助的Exact ad unit size per screen width example 创建了一个 AdComponent:
import React from 'react';
import styled from 'styled-components';
class AdComponent extends React.Component {
componentDidMount() {
(window.adsbygoogle = window.adsbygoogle || []).push({});
}
render() {
return (
<CustomIns
className="adsbygoogle"
style={{ display: 'inline-block' }}
data-ad-client="ca-pub-5555444121816745"
data-ad-slot="2476129802"
/>
);
}
}
export default AdComponent;
const CustomIns = styled.ins`
width: 320px;
height: 100px;
@media (min-width: 500px) {
width: 468px;
height: 60px;
}
@media (min-width: 800px) {
width: 728px;
height: 90px;
}
`;
每当网站加载时,都会显示完美尺寸的广告,但当我调整(或旋转)屏幕大小时,广告会保持相同的初始尺寸。预期的行为是,每当我遇到断点时,广告就会被替换为适合新尺寸的调整大小的广告。
【问题讨论】:
-
AdSense 应在请求新广告时检测屏幕旋转并相应调整广告位大小。例如,尝试使用移动仿真 nbeloglazov.com/adsense.html 并旋转它 - 您会看到广告刷新和调整大小。你是说当你旋转屏幕时广告不会改变?
标签: css reactjs responsive-design responsive adsense