Help needed: Calling renderAd twice
Type of issue
Question
Description
Hi! Recently I've been trying a prebid implementation (here you can see the live example: http://guitadigital.com/larissa/testando-prebid-loucamente/?pbjs_debug=true), but somehow I'm getting the pbjs.renderAd call twice on a unique ad request.
Here's the main code I wrote (it has some changes/adaptations):
var PERSONARE_CDN_URL = 'https://s3.amazonaws.com/psr-commercial/header-bidding';
var PREBID_TIMEOUT = 5000;
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
function loadAsyncScriptWithCallback(url, callback) {
var s = document.createElement('script');
s.type = 'text/javascript';
if(s.readyState) {
s.onreadystatechange = function() {
var isLoaded = (s.readyState === 'loaded' || s.readyState === 'complete');
if (isLoaded) {
s.onreadystatechange = null;
if (typeof callback === 'function') {
callback();
}
}
};
} else {
s.onload = function() {
if (typeof callback === 'function') {
callback();
}
};
}
s.async = true;
s.src = url;
document.getElementsByTagName('head')[0].appendChild(s);
};
function getRealValue(bidCpm) {
var defaultCotation = 3.25;
var hasPersonareCotation = typeof PERSONARE_HB_DOLLAR_COTATION !== 'undefined';
if (hasPersonareCotation) {
return bidCpm * PERSONARE_HB_DOLLAR_COTATION;
} else {
return bidCpm * defaultCotation;
}
};
function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
};
function callAdUnits () {
googletag.cmd.push(function () {
googletag.defineSlot('/8948849/opecTeste_SB', [728, 90], 'psr-ads-SR-qmfc1ee').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
window.onload = function(){
googletag.cmd.push(function() { googletag.display('psr-ads-SR-qmfc1ee'); });
}
};
loadAsyncScriptWithCallback('//www.googletagservices.com/tag/js/gpt.js', function(){
loadAsyncScriptWithCallback(PERSONARE_CDN_URL + '/dollar-quotation.js');
loadAsyncScriptWithCallback(PERSONARE_CDN_URL + '/prebid/prebid.js',function(){
pbjs.bidderSettings = {
appnexus: {
bidCpmAdjustment : getRealValue
},
aol: {
bidCpmAdjustment : getRealValue
},
rubicon: {
bidCpmAdjustment : getRealValue
}
};
loadAsyncScriptWithCallback('http://guitadigital.com/larissa/wp-content/uploads/2016/12/setorreciclagem.js', function(){
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad();
});
pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest
});
});
});
});
});
this code is kept in a .js external file and called through the following script tag in the of the site
<script type="text/javascript" src="http://guitadigital.com/larissa/wp-content/uploads/2016/12/pbjs_main.js" onload="callAdUnits()" async></script>
the key objective here is to keep the less code possible in our header and to display the ad, we call an empty div tag matching the ID "psr-ads-SR-qmfc1ee"
<div id='psr-ads-SR-qmfc1ee'></div>
Here's the console log:

I was hoping that someone here could help me with this. Thanks.
Seems that the problem is that the site americanexpress.com doesnt allow to be embeded in an iframe use another domain to test.
SRC: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
Closing this as answered, please reopen if additional info.