我正在关注此链接上的最后一个示例:https: //support.google.com/dfp_premium/answer/4578089?vid=1-635774352437004756-19071376
它调整大小但是我的广告由于某种原因没有显示,请参见下文:
<html>
<head>
<title>GPT Training - Responsive Test Page</title>
<script>
// Load GPT asynchronously
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script>
// GPT slots
var gptAdSlots = [];
googletag.cmd.push(function() {
// Define a size mapping object. The first parameter to addSize is
// a viewport size, while the second is a list of allowed ad sizes.
var mapping = googletag.sizeMapping().
// Small ad
addSize([100, 100], [88, 31]).
// Accepts both common mobile banner formats
addSize([320, 400], [[320, 50], [300, 50]]).
// Same width as mapping above, more available height
addSize([320, 700], [300, 250]).
// Landscape tablet
addSize([750, 200], [728, 90]).
// Desktop
addSize([1050, 200], [1024, 120]).build();
// Define the GPT slot
gptAdSlots[0] = googletag.defineSlot('/1034652/Z103Home_TopLeaderboard', [728, 90], 'div-gpt-ad-1441833752374-0').
defineSizeMapping(mapping).
addService(googletag.pubads());
googletag.pubads().setTargeting("test","responsive");
// Start ad fetching
googletag.enableServices();
});
</script>
</head>
<body>
<h1>GPT Training - Responsive Test Page</h1>
<div id="div-gpt-ad-1441833752374-0">
<script>
googletag.cmd.push(function() {
googletag.display('div-gpt-ad-1441833752374-0');
});
</script>
</div>
<p><span>GPT responsive ads do not resize on change in the size of the browser.
You can add your own custom code to refresh the ad slots on resize.
To demonstrate responsive capabilities, re-size your window and refresh the page.</span></p>
</body>
</html>