Community Forums › Forums › Archived Forums › General Discussion › Collapsible Div Tags for Google Ads
Tagged: Collapsible Div Tags
- This topic has 4 replies, 2 voices, and was last updated 9 years, 8 months ago by Brad Dalton.
-
AuthorPosts
-
April 6, 2015 at 8:12 pm #146866CJWheelsMember
This is an odd one that has me stumped. I have a client running Google Ads. They have mobile ads that do not show up unless on mobile. The problem is, they still take up space on desktop browsers. The Google Ad contact keeps referring us to this page: https://support.google.com/dfp_sb/answer/3419382?hl=en
I have it placed in the <head> script:
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
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 type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/50217444/Momsnacks_160x600', [160, 600], 'div-gpt-ad-1427162132059-0').addService(googletag.pubads());
googletag.defineSlot('/50217444/Momsnacks_300x250', [300, 250], 'div-gpt-ad-1427162132059-1').addService(googletag.pubads());
googletag.defineSlot('/50217444/Momsnacks_300x250(mobile)', [300, 250], 'div-gpt-ad-1427162132059-2').addService(googletag.pubads());
googletag.defineSlot('/50217444/Momsnacks_320x100(mobile)', [320, 100], 'div-gpt-ad-1427162132059-3').addService(googletag.pubads());
googletag.defineSlot('/50217444/Momsnacks_320x50(mobile)', [320, 50], 'div-gpt-ad-1427162132059-4').addService(googletag.pubads());
googletag.defineSlot('/50217444/MomSnacks_728x90', [728, 90], 'div-gpt-ad-1427162132059-5').addService(googletag.pubads());
.setCollapseEmptyDiv(true); //Collapsible div--Collapse this slot before ad fetch
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>Specifically, this code was added: .setCollapseEmptyDiv(true); //Collapsible div--Collapse this slot before ad fetch
You'll see the ads are not generating, but the space is still parked. The Google contact is basically no help and I have no idea how to get it to collapse when ads do not show. I have it on a test site that is Genesis Magazine theme out of the box.
Any wisdom on this most appreciated.
http://celebrouhaha.com/April 6, 2015 at 10:04 pm #146872Brad DaltonParticipantThis might be better asked on the Javascipt tag at Stackoverflow.com as i have seen this question before unanswered maybe because its not exactly specific to Genesis or StudioPress. Hope that helps.
April 7, 2015 at 9:19 am #146917CJWheelsMemberHey Brad, thanks for the direction. Straight up, I think it's something that falls on the Google end. I can't figure out why they'd hand out mobile code that doesn't take up space on desktops. They keep telling my client it's a developer issue. I disagree.
My client said, "Ask the smartest people you know." So I came here 😉
I'll head over there. If I get a fix, I'll post it here as well.
Cynthia
April 8, 2015 at 9:31 am #147072CJWheelsMemberI got this to work thanks to your help! I added the .setCollapseEmptyDiv(true); //Collapsible div–Collapse this slot before ad fetch to each seperate ad I wanted to collapse. Folds down perfectly now.
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
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 type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/50217444/Momsnacks_160x600', [160, 600], 'div-gpt-ad-1427162132059-0').addService(googletag.pubads());
googletag.defineSlot('/50217444/Momsnacks_300x250', [300, 250], 'div-gpt-ad-1427162132059-1').addService(googletag.pubads());
googletag.defineSlot('/50217444/Momsnacks_300x250(mobile)', [300, 250], 'div-gpt-ad-1427162132059-2').addService(googletag.pubads())
.setCollapseEmptyDiv(true); //Collapsible div–Collapse this slot before ad fetch
googletag.defineSlot('/50217444/Momsnacks_320x100(mobile)', [320, 100], 'div-gpt-ad-1427162132059-3').addService(googletag.pubads())
.setCollapseEmptyDiv(true); //Collapsible div–Collapse this slot before ad fetch
googletag.defineSlot('/50217444/Momsnacks_320x50(mobile)', [320, 50], 'div-gpt-ad-1427162132059-4').addService(googletag.pubads())
.setCollapseEmptyDiv(true); //Collapsible div–Collapse this slot before ad fetch
googletag.defineSlot('/50217444/MomSnacks_728x90', [728, 90], 'div-gpt-ad-1427162132059-5').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>You have to remember to remove the ";" after each ad set when you ad in the collapsible div tag code. That was my mistake.
April 8, 2015 at 9:37 am #147074Brad DaltonParticipant -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.