Link Search Menu Expand Document

PDF

OA.JS Samples

OpenAudience

Publishers


Use the following samples as a reference on how to implement oa.js.


Prebid Basic Sample

Expand the code sample on this page
<html>

    <head>
        <link rel="icon" type="image/png" href="/favicon.png">
        <script async src="//www.googletagservices.com/tag/js/gpt.js"></script>
        <script async src="./prebid.js"></script>
        <script src="https://oa.openxcdn.net/oa.js"></script>
        <script>
        oajs.start(
          {
            "placementID": '16',
            "tdidPartnerID": 'openx',
            "storageType": 'localStorage',
            "logging": 'debug',
            "oaID": 'test',
            "email": 'fake.person@aol.com'
          });
        </script>

        <script>
            var PREBID_TIMEOUT = 2000;
            var FAILSAFE_TIMEOUT = 3000;

            var adUnits = [{
                code: "div-1",
                mediaTypes: {
                    banner: {
                        sizes: [
                            [300, 250],[300,600]
                        ]
                    }
                },
                bids: [{
                    bidder: "openx",
                    params: {
                        unit: "540096529",
                        delDomain: "sademo-d.openx.net"
                    }
                },
                {
                    bidder: "appnexus",
                    params: {
                        placementId: 13144370
                    }
                }]
            },
            {
                code: "div-2",
                mediaTypes: {
                    banner: {
                        sizes: [
                            [728, 90],[970, 250]
                        ]
                    }
                },
                bids: [{
                    bidder: "openx",
                    params: {
                        unit: "540096529",
                        delDomain: "sademo-d.openx.net"
                    }
                },
                {
                    bidder: "appnexus",
                    params: {
                        placementId: 13144370
                    }
                }]
            }];

            var googletag = googletag || {};
            googletag.cmd = googletag.cmd || [];
            googletag.cmd.push(function() {
                googletag.pubads().disableInitialLoad();
            });

            var pbjs = pbjs || {};
            pbjs.que = pbjs.que || [];

            pbjs.que.push(function() {
                  pbjs.setConfig({
                  userSync: {
                      userIds: [{
                        name: "unifiedId",
                        params: {
                            url: "https://match.adsrvr.org/track/rid?ttd_pid=openx&fmt=json"
                        },
                        storage: {
                            type: "cookie",
                            name: "pbjs_unifiedid",
                            expires: 7
                        }
                    },{
                          name: "identityLink",
                          params: {
                              pid: '16'             // Set your real identityLink placement ID here
                          },
                          storage: {
                              type: "cookie",
                              name: "idl_env",       // create a cookie with this name
                              expires: 7            // cookie can last for seven days
                          }
                      }],
                      syncDelay: 3000
                  }
                });
                pbjs.addAdUnits(adUnits);
                pbjs.requestBids({
                    bidsBackHandler: initAdserver,
                    timeout: PREBID_TIMEOUT
                });
            });

            function initAdserver() {
                if (pbjs.initAdserverSet) return;
                pbjs.initAdserverSet = true;
                googletag.cmd.push(function() {
                    pbjs.que.push(function() {
                        pbjs.setTargetingForGPTAsync();
                        googletag.pubads().refresh();
                    });
                });
            }
            // in case PBJS doesn't load
            setTimeout(function() {
                initAdserver();
            }, FAILSAFE_TIMEOUT);

            googletag.cmd.push(function() {
                googletag.defineSlot('/19968336/header-bid-tag-0',  [[300, 250],[300,600]], 'div-1').addService(googletag.pubads());
                googletag.pubads().enableSingleRequest();
                googletag.enableServices();
            });
            googletag.cmd.push(function() {
                googletag.defineSlot('/19968336/header-bid-tag-1',  [[728, 90],[970, 250]], 'div-2').addService(googletag.pubads());
                googletag.pubads().enableSingleRequest();
                googletag.enableServices();
            });

        </script>

    </head>

    <body>
        <h2>Basic Prebid.js Example</h2>
        <h5>Div-1</h5>
        <div id='div-1'>
            <script type='text/javascript'>
                googletag.cmd.push(function() {
                    googletag.display('div-1');
                });

            </script>
        </div>

        <br>

        <h5>Div-2</h5>
        <div id='div-2'>
            <script type='text/javascript'>
                googletag.cmd.push(function() {
                    googletag.display('div-2');
                });

            </script>
        </div>

    </body>

</html>

> Load on a web page the code sample to inspect


Prebid Asynchronous Sample

Expand the code sample on this page
<html>

    <head>
        <link rel="icon" type="image/png" href="/favicon.png">
        <script async src="//www.googletagservices.com/tag/js/gpt.js"></script>
        <script async src="./prebid.js"></script>
        <script async src="https://oa.openxcdn.net/oa.js"></script>

        <script>
            var PREBID_TIMEOUT = 2000;
            var FAILSAFE_TIMEOUT = 3000;

            var adUnits = [{
                code: "div-1",
                mediaTypes: {
                    banner: {
                        sizes: [
                            [300, 250],[300,600]
                        ]
                    }
                },
                bids: [{
                    bidder: "openx",
                    params: {
                        unit: "540096529",
                        delDomain: "sademo-d.openx.net"
                    }
                },
                {
                    bidder: "appnexus",
                    params: {
                        placementId: 13144370
                    }
                }]
            },
            {
                code: "div-2",
                mediaTypes: {
                    banner: {
                        sizes: [
                            [728, 90],[970, 250]
                        ]
                    }
                },
                bids: [{
                    bidder: "openx",
                    params: {
                        unit: "540096529",
                        delDomain: "sademo-d.openx.net"
                    }
                },
                {
                    bidder: "appnexus",
                    params: {
                        placementId: 13144370
                    }
                }]
            }];

            var googletag = googletag || {};
            googletag.cmd = googletag.cmd || [];
            googletag.cmd.push(function() {
                googletag.pubads().disableInitialLoad();
            });

            var pbjs = pbjs || {};
            pbjs.que = pbjs.que || [];

            pbjs.que.push(function() {
                  pbjs.setConfig({
                  userSync: {
                      userIds: [{
                        name: "unifiedId",
                        params: {
                            url: "https://match.adsrvr.org/track/rid?ttd_pid=openx&fmt=json"
                        },
                        storage: {
                            type: "cookie",
                            name: "pbjs_unifiedid",
                            expires: 7
                        }
                    },{
                          name: "identityLink",
                          params: {
                              pid: '16'             // Set your real identityLink placement ID here
                          },
                          storage: {
                              type: "cookie",
                              name: "idl_env",       // create a cookie with this name
                              expires: 7            // cookie can last for seven days
                          }
                      }],
                      syncDelay: 3000              // 3 seconds after the first auction
                  }
                });
                pbjs.addAdUnits(adUnits);
            });

            function initAdserver() {
                if (pbjs.initAdserverSet) return;
                pbjs.initAdserverSet = true;
                googletag.cmd.push(function() {
                    pbjs.que.push(function() {
                        pbjs.setTargetingForGPTAsync();
                        googletag.pubads().refresh();
                    });
                });
            }

            window.oajs = window.oajs || {cmd: []};

            oajsConfig = {
              "placementID": '16',
              "tdidPartnerID": 'openx',
              "storageType": 'localStorage',
              "logging": 'debug',
              "oaID": 'test',
              "email": 'fake.person@aol.com'
            }

            oajs.cmd.push(function () {
                oajs.start(oajsConfig);
                pbjs.que.push(function() {
                    pbjs.requestBids({
                        bidsBackHandler: initAdserver,
                        timeout: PREBID_TIMEOUT
                    })
                });
            });

            // in case PBJS doesn't load
            setTimeout(function() {
                initAdserver();
            }, FAILSAFE_TIMEOUT);

            googletag.cmd.push(function() {
                googletag.defineSlot('/19968336/header-bid-tag-0',  [[300, 250],[300,600]], 'div-1').addService(googletag.pubads());
                googletag.pubads().enableSingleRequest();
                googletag.enableServices();
            });
            googletag.cmd.push(function() {
                googletag.defineSlot('/19968336/header-bid-tag-1',  [[728, 90],[970, 250]], 'div-2').addService(googletag.pubads());
                googletag.pubads().enableSingleRequest();
                googletag.enableServices();
            });

        </script>

    </head>

    <body>
        <h2>Basic Prebid.js Example</h2>
        <h5>Div-1</h5>
        <div id='div-1'>
            <script type='text/javascript'>
                googletag.cmd.push(function() {
                    googletag.display('div-1');
                });

            </script>
        </div>

        <br>

        <h5>Div-2</h5>
        <div id='div-2'>
            <script type='text/javascript'>
                googletag.cmd.push(function() {
                    googletag.display('div-2');
                });

            </script>
        </div>

    </body>

</html>

> Load on a web page the code sample to inspect