How to load ads using Single Request Architecture in Google Publisher Tag?
When we want to bundle multiple ad requests to a single ad request, Single Request Architecture (SRA) from Google is good and works best.
To make the best use of single request architecture (SRA) we should define all the ad slots that need to be under SRA. After defining the ad slot with ad unit code, ad size, ad targeting, etc., we should call the display method.
The first display call will render all the ads under SRA. We don’t need to call display for each ad slot.
Code for head tag
Add the following code snippet in the HTML head tag of your webpage.
<script async src='https://securepubads.g.doubleclick.net/tag/js/gpt.js'></script> <script> window.googletag = window.googletag || {cmd: []}; googletag.cmd.push(function() { googletag.defineSlot('/6355419/toppbanner', [[1020,300]], 'div-gpt-ad-1') .addService(googletag.pubads()); googletag.defineSlot('/6355419/rightsticky', [[460,1000]], 'div-gpt-ad-2') .addService(googletag.pubads()); googletag.defineSlot('/6355419/leftsticky', [[460,1001]], 'div-gpt-ad-3') .addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.pubads().setTargeting('urlQuery', ['test:wallpaper']); googletag.enableServices(); }); </script>
Code for body tag
Add the following code snippet in the HTML body tag of your webpage.
<div id='div-gpt-ad-1'></div> <div id='div-gpt-ad-2'></div> <div id='div-gpt-ad-3'></div> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1'); }); </script>