App Nexus与react-gpt集成

时间:2018-02-14 07:25:34

标签: reactjs ads adsense google-dfp

我们正在尝试将app nexus(https://www.appnexus.com/en)与react-gpt(https://github.com/nfl/react-gpt)库集成在一起。但是,启用应用程序nexus时,不会显示广告。当app nexus被禁用时,它们显示正常。 以下是相同的示例代码,显示广告的代码部分正在使用react-gpt库实现,而不是普通的js,如下面的代码段所示 - https://jsfiddle.net/prebid/bhn3xk2j/458/

<html>
<head>
  <!-- Prebid Config Section START -->
  <!-- Make sure this is inserted before your GPT tag -->
  <script> 
    var PREBID_TIMEOUT = 700;

    var adUnits = [{
        code: 'div-gpt-ad-1460505748561-0',
        sizes: [[300, 250], [300,600]],
        bids: [{
            bidder: 'appnexus',
            params: {
               placementId: '10433394'
            }
        }]
    },{
        code: 'div-gpt-ad-1460505661639-0',
        sizes: [[728, 90], [970, 90]],
        bids: [{
            bidder: 'appnexus',
            params: {
               placementId: '10433394'
            }
        }]
    }];

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

  </script>
  <!-- Prebid Config Section END -->

  <!-- Prebid Boilerplate Section START. No Need to Edit. -->
  <script type="text/javascript" src="//acdn.adnxs.com/prebid/not-for-prod/prebid.js" async></script>
  <script>
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    googletag.cmd.push(function() {
        googletag.pubads().disableInitialLoad();
    });

    pbjs.que.push(function() {
        pbjs.addAdUnits(adUnits);
        pbjs.requestBids({
            bidsBackHandler: sendAdserverRequest
        });
    });

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

    setTimeout(function() {
        sendAdserverRequest();
    }, PREBID_TIMEOUT);

  </script>
  <!-- Prebid Boilerplate Section END -->

  <script>
    (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>
    googletag.cmd.push(function () {
        googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());

        googletag.defineSlot('/19968336/header-bid-tag1', [[728, 90], [970, 90]], 'div-gpt-ad-1460505661639-0').addService(googletag.pubads());

        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
    });
  </script>
</head>

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

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

</body>
</html>

关于它为什么不起作用的任何想法?

0 个答案:

没有答案