这是我的代码
<script>
window.googletag = window.googletag || { cmd: [] };
var gptAdSlots = [];
googletag.cmd.push(function() {
var pageConfig = {
allowOverlayExpansion: true,
allowPushExpansion: true,
sandbox: true
};
var mapping = googletag
.sizeMapping()
.addSize(
[1420, 90],
[
[970, 90],
[728, 90],
[300, 600],
[300, 250]
]
)
.addSize([769, 200], [[970, 90], [728, 90], [300, 600][(300, 250)]])
.addSize(
[320, 700],
[
[300, 250],
[300, 100],
[320, 100]
]
)
.build();
gptAdSlots[0] = googletag
.defineSlot(
"/542XXX9/ECC_Middle1_Desktop_HOME",
[
[970, 90],
[728, 90]
],
"div-gpt-ad-id-0"
)
.defineSizeMapping(mapping)
.addService(googletag.pubads());
gptAdSlots[1] = googletag
.defineSlot("/542XXX9/ECC_Left1_Desktop_HOME", [300, 250], "div-gpt-ad-id-0")
.defineSizeMapping(mapping)
.addService(googletag.pubads());
gptAdSlots[3] = googletag
.defineSlot("/542XXX9/ECC_Verical_Desktop_HOME", [300, 600], "div-gpt-ad-id-0")
.defineSizeMapping(mapping)
.addService(googletag.pubads());
gptAdSlots[4] = googletag
.defineSlot(
"/542XXX9/ECC_Middle1_Mobile_HOME",
[
[300, 100],
[320, 100]
],
"div-gpt-ad-id-0"
)
.defineSizeMapping(mapping)
.addService(googletag.pubads());
gptAdSlots[5] = googletag
.defineSlot("/542XXX9/ECC_Left1_Mobile_HOME", [300, 250], "div-gpt-ad-id-0")
.defineSizeMapping(mapping)
.addService(googletag.pubads());
gptAdSlots[7] = googletag
.defineSlot(
"/542XXX9/Header_desktop_HOME",
[
[970, 90],
[728, 90]
],
"div-gpt-ad-id-0"
)
.defineSizeMapping(mapping)
.addService(googletag.pubads());
gptAdSlots[8] = googletag
.defineSlot(
"/542XXX9/ECC_Header_mobile_HOME",
[
[300, 100],
[320, 100]
],
"div-gpt-ad-id-0"
)
.defineSizeMapping(mapping)
.addService(googletag.pubads());
googletag.pubads().setForceSafeFrame(true);
googletag.pubads().setSafeFrameConfig(pageConfig);
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
显然一切都正确显示,尽管有时广告没有呈现。
在控制台中有警告“googletag.Slot defineSizeMapping 的使用不正确:大小映射必须是一个数组”,因为我可以解决这个问题,我已经在许多论坛和网站上进行了审查,但我无法修复它。
感谢帮助!