Running A9 in Parallel with OpenWrap

Document created by catherine.racette on Aug 31, 2018
Version 1Show Document
  • View in full screen mode

Introduction 

The A9 Server-to-Server (S2S) wrapper solution and client-side code is not a component of any other wrapper (e.g., Prebid). This requires running the code in parallel with OpenWrap. OpenWrap manages the entire process of detecting slots and attaching bids to DFP and does not expose any functionality to request a bid that can be consumed. Therefore, the code cannot run in parallel using callbacks and custom handling.  

Solution 

Use the following solution and samples to run A9 Wrapper with OpenWrap in parallel. 

Running A9 and OpenWrap in Parallel without Synchronization/Notification 

OpenWrap has the capability to hold DFP calls by intercepting GPT for a specified timeout, therefore, we can start executing OpenWrap, GPT and the external bidder such as A9 asynchronously. It is required that all the external bidders attach their bids to DFP in the Timeout that is set for OpenWrap. 

Example 

This sample code contains the OpenWrap and A9 setup in which, instead of calling GPT in the A9 callback, we initiate the GPT as we normally do for OpenWrap, i.e., in the PWT.jlLoaded() function: 

  1. disableInitialLoad() is not mandatory as required by A9 tag to run. 
  1. googletag.pubads().refresh(); code should not be called in A9 callback function. 
  1. googletag.display()/ googletag.pubads().refresh() function should be restored as GPT would run normally on a page. 

Sample Page Implementation 

<!DOCTYPE HTML> 
<html lang="en-us">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Wrapper Tag GPT Async Demo with A9</title>
    
    <h4>GPT implementation is ASYNC SRA <a href="https://support.google.com/dfp_premium/answer/1638622?hl=en">(Refer this for types of GPT Tags)</a></h4>
    <!-- OpenWrap Script begins here -->
    <script type="text/javascript">
    var PWT={}; //Initialize Namespace
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    PWT.jsLoaded = function(){ //PubMatic pwt.js on load callback is used to load GPT
        (function() {
            var gads = document.createElement('script');
            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);
        })();
    };
    (function() {
        var purl = window.location.href;
        var url = '//ads.pubmatic.com/AdServer/js/pwt/9999/1';
        var profileVersionId = '';
        if(purl.indexOf('pwtv=')>0){
            var regexp = /pwtv=(.*?)(&|$)/g;
            var matches = regexp.exec(purl);
            if(matches.length >= 2 && matches[1].length > 0){
                profileVersionId = '/'+matches[1];
            }
        }
        var wtads = document.createElement('script');
        wtads.async = true;
        wtads.type = 'text/javascript';
        wtads.src = url+profileVersionId+'/pwt.js';
        var node = document.getElementsByTagName('script')[0];
        node.parentNode.insertBefore(wtads, node);
    })();
    </script>
    <!--Wrapper Script ends here -->

<!-- A9 Script Start -->
    <script>
     !function(a9,a,p,s,t,A,g){if(a[a9])return;function q(c,r){a[a9]._Q.push([c,r])}a[a9]={init:function(){q("i",arguments)},fetchBids:function(){q("f",arguments)},setDisplayBids:function(){},_Q:[]};A=p.createElement(s);A.async=!0;A.src=t;g=p.getElementsByTagName(s)[0];g.parentNode.insertBefore(A,g)}("apstag",window,document,"script","//c.amazon-adsystem.com/aax2/apstag.js");
     apstag.init({
         pubID: 'xxxx',
         adServer: 'googletag'
     });
     apstag.fetchBids({
         slots: [{
             slotID: 'Div2',
             sizes: [[300, 250], [300, 600]]
         },
         {
             slotID: 'Div1',
             sizes: [[728 ,90]]
         }], 
         timeout: 2e3 // Make Sure this timeout is less than or equal to OpenWrap TimeOut
     }, function(bids) {
         googletag.cmd.push(function(){
             apstag.setDisplayBids();
            // googletag.pubads().refresh(); No need to call refresh in callback as OpenWrap takes care of display.
         });
     });
    </script>
    <!-- A9 Script End -->
    <script type="text/javascript">
        googletag.cmd.push(function() {
            var s1 = googletag.defineSlot('/15671365/DMDemo', [
                [728, 90]
            ], 'Div1').addService(googletag.pubads());
            s1.setTargeting('abc', 123);
            var s2 = googletag.defineSlot('/15671365/DMDemo1', [
                [300, 250],
                [300, 600]
            ], 'Div2').addService(googletag.pubads());
            s2.setTargeting('2abc', 123);
  
            // common targetings
            googletag.pubads().setTargeting('v', 'classifieds');
            googletag.pubads().setTargeting('article-id', '65207');
            googletag.pubads().enableSingleRequest();
            googletag.enableServices();
           
        });
    </script>
</head>
<body style='background-color:whitesmoke;'>
    <br><br>
    <!-- DMDemo -->
    Adslot : /15671365/DMDemo
    <br>
    <div id='Div1'>
    <script>
        googletag.cmd.push(function() {
           googletag.display("Div1");
        });
     </script>
    </div>
    <br><br>
    <!-- DMDemo1 -->
    Adslot : /15671365/DMDemo1
    <br>
    <div id='Div2'>
        <script>
        googletag.cmd.push(function() {
           googletag.display("Div2");
        });
     </script>
    </div>
</body>
</html>

Behavior and Limitations 

  • The external bidders must submit the bid within the timeout set for OpenWrap to be able to attach bids. 
  • The external bidder (A9) is responsible for attaching bids. 
  • The line item for external bidders should be separate in DFP. 
  • This will work with Advanced GPT implementations as well.  

Attachments

    Outcomes