DoubleClick (DFP) ads loaded by AJAX don't display ads in Firefox

I use DoubleClick For Publishers (DFP) ads. This is the page: http://www.ifly.com

I load DFP ads via jQuery AJAX after the page load event to make my various search widgets available to user interaction as quickly as possible. The process looks something like this.

Place the initial DFP header calls in the document header.

<head> ... <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('/9358962/HP-300x250', [300, 250], 'div-gpt-ad-1353002461867-0').addService(googletag.pubads()); googletag.defineSlot('/9358962/HP-460x60', [468, 60], 'div-gpt-ad-1353002461867-1').addService(googletag.pubads()); googletag.defineSlot('/9358962/HP-728x90', [728, 90], 'div-gpt-ad-1353002461867-2').addService(googletag.pubads()); googletag.defineSlot('/9358962/HP-LAF-160x600', [160, 600], 'div-gpt-ad-1353002461867-3').addService(googletag.pubads()); googletag.defineSlot('/9358962/HP-RAF-160x600', [160, 600], 'div-gpt-ad-1353002461867-4').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(); }); </script> .... </head> 

Create an empty div as a placeholder.

 <div id='horizontalTANBanner'></div> 

After the page loads, paste the code using jQuery AJAX to retrieve the ad.

 <div id='horizontalTANBanner'> <!-- HP-728x90 --> <div id='div-gpt-ad-1353002461867-2' style='width:728px; height:90px;'> <script type='text/javascript'> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1353002461867-2'); }); </script> </div> </div> 

Google loads even more JavaScript to actually call the ad. I see that it was inserted using Firebug.

 <div id="horizontalTANBanner"> <div id="div-gpt-ad-1353002461867-2" style="width:728px; height:90px;"> <iframe id="google_ads_iframe_/9358962/HP-728x90_0" width="728" scrolling="no" height="90" frameborder="0" name="google_ads_iframe_/9358962/HP-728x90_0" marginwidth="0" marginheight="0" style="border: 0px none;"> <html> </iframe> <iframe id="google_ads_iframe_/9358962/HP-728x90_0__hidden__" width="0" scrolling="no" height="0" frameborder="0" name="google_ads_iframe_/9358962/HP-728x90_0__hidden__" marginwidth="0" marginheight="0" style="border: 0px none; visibility: hidden; display: none;"> </div> </div> 

I see that ads are displayed in every browser, but Firefox (IE, Chrome, Opera, Safari). I have confirmed to other users that they cannot see ads in Firefox. How to show ads in Firefox?

I asked this question in the DFP forum, but they are not technical and their best answer was β€œStop using AJAX,” but the experience of visitors is much better, and I expect Google to rank my pages better than not to load slowly, so I hate stop using it.

+7
source share
1 answer

I think you can complicate the loading of your dfp slots.

This code block is the part that does not work, I think.

  /*** Populate DFP ads ***/ var _pageID=$("body").find_class("pageID-"); $.get('/common/modules/ajax-get-list.php',{pageID:_pageID},function(_data){ //alert('data='+_data); if(_data!=''){ var _arrDFPList=_data.split(','); for(var i=0;i<_arrDFPList.length;i++){ //alert('DFP id = '+_arrDFPList[i]); $.get('/common/modules/ajax-get-one.php',{id:_arrDFPList[i]},function(_oneData){ var _arrDFPOne=_oneData.split('<<<>>>'); //alert('id = '+_arrDFPOne[0]+' and content = '+_arrDFPOne[1]); $("#"+_arrDFPOne[0]).append(_arrDFPOne[1]); //$("#"+_arrDFPOne[0]).html(_arrDFPOne[1]); }); } } /* if(_data!=''){ var arrDFPList=_data.split(','); $.get('/common/modules/def-get-one.php',{},function(_oneData){ }); }*/ }); /*** END Populate DFP ads ***/ 

I think firefox is probably just adding ad slot display code, but cannot rate it.

I ran into a similar problem a few months ago when we wanted to post ads after loading and also save everything very quickly, but just ... the solution I came up with was to create jquery.dfp.js . This plugin allows you to completely download the DFP download, until you want to download it, you also do not need to pre-define all your slots, as you are doing now ...

For example, your current homepage with the minimum necessary information needed to serve your ads using my plugin:

 <html> <head> <title>DFP TEST</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="https://raw.github.com/coop182/jquery.dfp.js/master/jquery.dfp.min.js"></script> </head> <body> <div class="adunit" id="HP-300x250" data-dimensions="300x250"></div> <div class="adunit" id="HP-460x60" data-dimensions="460x60"></div> <div class="adunit" id="HP-728x90" data-dimensions="728x90"></div> <div class="adunit" id="HP-LAF-160x600" data-dimensions="160x600"></div> <div class="adunit" id="HP-RAF-160x600" data-dimensions="160x600"></div> <script> $(function () { $.dfp('9358962'); }); </script> </body> </html> 

I think this is a much better way to do something. If you have any questions, let me know.

+8
source

All Articles