I am trying to load banners depending on the size of the browser. Therefore, in the place where I have a 728x90 banner, 300x250 will show whether it will be on a mobile phone.
The problem is that 728x90 is loading onto the desktop. but 300x250 is not displayed on the mobile phone.
I tried to follow the example here
<script type='text/javascript'> googletag.cmd.push(function() { // This mapping will only display ads when user is on desktop sized viewport var mapLeader = googletag.sizeMapping(). addSize([0, 0], []). addSize([768, 200], [728, 90]). build(); // This mapping will only display ads when user is on mobile or tablet sized viewport var mapLeader2 = googletag.sizeMapping(). addSize([0, 0], []). addSize([768, 200], []). // Desktop addSize([300, 200], [300, 250]). // Tablet build(); window.LeaderSlot= googletag.defineSlot('/XXXXXXX/leaderboard-1', [728, 90], 'div-gpt-ad-1455251022145-0'). defineSizeMapping(mapLeader). setCollapseEmptyDiv(true). addService(googletag.pubads()); window.LeaderSlot= googletag.defineSlot('/XXXXXXX/medium-rectangle-1', [300, 250], 'div-gpt-ad-1458546777123-0'). defineSizeMapping(mapLeader2). setCollapseEmptyDiv(true). addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.pubads().enableSyncRendering(); // Start ad fetching googletag.enableServices(); }); </script>
and in my HTML
<div id='div-gpt-ad-1455251022145-0' style='height:90px; width:728px;' class="center"> <script type='text/javascript'> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1455251022145-0'); }); </script> </div> <div id='div-gpt-ad-1458546777123-0' style='height:250px; width:300px;'> <script type='text/javascript'> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1458546777123-0'); }); </script> </div>
Do I need to put a <div> for each size in one place? How can I load a 300x250 banner? 728x90 works great. I know that I could hide / show the size of the browser using CSS. but I do not want to do this. Downloading multiple sizes in one place slows down the loading of my sites.
javascript adsense google-dfp gpt
user2636556
source share