/*
Copyright Mediasquare 2018-2019
*/
var asq_prebid = {
timeout: 2000,
is_prebid_loaded: false,
safe_frame: true,
random: Math.floor(Math.random()*9999999999),
lazy_loading: [],
price_granularity : {"buckets" : [{"precision": 6, "min" : 0,"max" : 20,"increment" : 0.000001}]},
getTopElement: function(el, iframe) {
try {
var i = 0, iframew = iframe;
while (i < 10 && iframew != top) {
if (iframew.frameElement) {
el=iframew.frameElement.parentNode;
iframew=iframew.parent;
}
i++;
}
if (iframew == top)
return el;
else
return false;
}
catch(e) {
return false;
}
},
appnexus_bidders: ["msq", "msqBrand", "msqMaxView", "msqMax", "msqv", "msqvBrand", "asqBrand", "asq", "asqMaxView", "asqMax", "asqv", "asqvBrand"],
confiant_cdnHost: 'clarium.global.ssl.fastly.net',
confiant_propertyId: 'ClK7aEIwdxQM5c6saIrgv0cF8P8',
confiant_callback: function(blockingType, blockingId, isBlocked, propertyId, tagId, impressionData) {
console.log("w00t one more bad ad nixed.", arguments);
},
msqLog: function(code, text) {
if (code.split('_').length == 3)
code = code.split('_')[2]
console.log('%cMSQ%c'+code+'%c '+text, 'padding: 2px; border-radius: 4px; background-color: #FF574D; color: white; font-weight: bolder;', 'background-color: #0d3885; color: white; padding: 2px; border-radius: 4px; font-weight: bolder;', 'color: black; font-weight: normal')
},
createAsqResize: function() {
try {
top.window.asq_resize = function(iframe, width, height) {
var regex = new RegExp('%$');
if (typeof width == 'number' || !width.match(regex))
width += 'px';
if (typeof height == 'number' || !height.match(regex))
height += 'px';
var i = 0, iframew = iframe;
//try {
while (i < 10 && iframew != top) {
if (iframew.frameElement) {
iframew.frameElement.style.width = width;
iframew.frameElement.style.height = height;
iframew.frameElement.width = width;
iframew.frameElement.height = height;
iframew=iframew.parent;
}
else break;
i++;
}
//}
//catch (e) {}
};
}
catch (e) {}
},
setOnFocus: function(id) {
try {
if(top.ONFOCUS==undefined && typeof id == "number"){
top.ONFOCUS = {
app_id: 40000+id,
tag_s: new Date().getTime()
};
(function(a,b,c,d){d=top.document.createElement("iframe"),d.src="javascript:false",(d.frameElement||d).style.cssText="width: 0; height: 0; border: 0; display:none;",c=top.document.getElementsByTagName("script")[0],c.parentNode.insertBefore(d,c);try{b=d.contentWindow.document}catch(c){a=top.document.domain,d.src="javascript:var d=document.open();d.domain='"+a+"';void(0);",b=d.contentWindow.document}b.open()._l=function(){var b=this.createElement("script");a&&(this.domain=a),b.id="boomr-if-as",b.src=top.window.location.protocol+"//fogl1onf.com/"+top.ONFOCUS.app_id+"/b.js",this.body.appendChild(b)},b.write('
'),b.close()}());
}
}
catch (e) {console.error("Could not set onfocus.");}
},
postProcess: function(code, winner) {
try {
if (winner) {
var logrevenue = document.createElement("img");
var src = '//balance.mediasquare.fr/revenue.gif?code='+code+'&cpm='+winner.cpm+'&bidder='+winner.bidder+'&size='+winner.size+'&cb=' + asq_prebid.random+'&adId='+winner.adId
if (winner.creativeId)
src += '&creative_id='+winner.creativeId;
if (winner.auctionId)
src += '&auction_id='+winner.auctionId;
if (winner.requestId)
src += '&request_id='+winner.requestId;
logrevenue.setAttribute('src', src);
logrevenue.setAttribute('style', 'display: none');
tag_div.appendChild(logrevenue);
}
/*var all_bids = asq_pbjs.getBidResponsesForAdUnitCode(code).bids;
for (which_bid = 0; which_bid < all_bids.length; which_bid++)
if (all_bids[which_bid].adId != winner.adId) {
var logloss = document.createElement("img");
logloss.setAttribute('src', '//balance.audiencesquare.com/lost.gif?code='+code+'&cpm='+all_bids[which_bid].cpm+'&bidder='+all_bids[which_bid].bidder+'&size='+all_bids[which_bid].size+'&cb=' + asq_prebid.random+'&adId='+all_bids[which_bid].adId);
tag_div.appendChild(logloss);
}*/
} catch (e) {}
},
confiantWrap: function(a,b,c,d,e,f,g){
'v2.202003091435';function h(a){for(var b in l)if(b===a&&l[b])return l[b];return null}function i(a){if("string"!=typeof a)return a;var b=a.match(/[^\u0000-\u024F\u1E00-\u1EFF\u2C60-\u2C7F\uA720-\uA7FF]/g);if(!b)return a;for(var c=0;cwindow["'+d+'"]={};'+'window["'+d+'"]["tpid"]="'+b+'";'+'window["'+d+'"]["'+b+'"]='+r.stringify(e)+";"+""+w+">",k="<"+w+" on"+z+'="void('+i+'())" '+x+'="'+h+'" type="text/java'+w+'" >'+w+">";f&&(k="<"+w+" on"+z+'="void('+i+'())" '+'" type="text/java'+w+'" >'+unescape(f)+""+w+">"),a[B](j+k)}var l=b.adserverTargeting,m=b.bidder,n=null,o=b.size;g=g||{},f=f||null;var p=g.devMode,q=a.parentWindow||a.defaultView,r=q.JSON,s=q.btoa,t=q.encodeURIComponent;if(!r||!s)return!1;var u="t",v="i",w="script",x="src",y="replace",z="error",A="stringify",B="wr"+v+u+"e";c.indexOf("http")<0&&(c="https://"+c);var C,D=c+"/?wrapper="+t(d)+"&tpid=";C=h("oz_winner")||"ozone"===m?{k:{hb_bidder:[h("oz_winner")],hb_size:[o]}}:{k:{hb_bidder:[m],hb_size:[o]}};var E=!1,F=!(!window._clrm||!window._clrm.gpt),G=!(!window.confiant||!window.confiant.settings),H=window.confiant||window._clrm||{};return F||G||H.isListener||(H.isListener=!0,function(){function a(a){var b="cb";if("string"==typeof a.data&&a.data.indexOf(b+d)>-1){var c=a.data.substr(b.length+d.length),f=atob(c),g=window.JSON.parse(f);try{e.apply(this,g)}catch(a){console.log("Custom callback failed with an error: "+a)}"undefined"!=typeof confiantAutoRFCb&&confiantAutoRFCb.apply(null,g)}}if(window.addEventListener)try{window.top.addEventListener("message",a,!1)}catch(b){window.addEventListener("message",a,!1)}else window.top.attachEvent("onmessage",a)}()),function(){try{n=j(d+"/"+C.k.hb_bidder[0]+":"+C.k.hb_size[0]);var c={wh:n,wd:r.parse(r[A](C)),wr:0};2===p&&(c.cb=1e3*Math.random());var f={prebid:{adId:b.adId,cpm:b.cpm,crId:b.creativeId,s:b.adUnitCode}},h=!1;try{h=!!q.frameElement.getAttribute("data-forced-sandbox")}catch(a){}var i={d:c,t:escape(b.ad),isE:!0,cb:e,id:f,isFSb:h,devMode:p,isPerf:g.isPerf};k(n,j(r[A](c)),i,function(){a[B](b.ad)})}catch(a){E=!0;var c={property_id:d,uh:n||"wt_not_established",url:window.location.href||window.top.location.href||document.url||"url not found",label:"confiantWrap_initialize",msg:a.message},l=new XMLHttpRequest;l.open("POST","https://protected-by.clarium.io/werror",!0),l.send(s(r.stringify(c)))}}(),a.close(),!E
},
getIframeElement: function(code) {
var apnxsiframe = document.createElement("iframe");
apnxsiframe.setAttribute('id', 'post_'+code);
apnxsiframe.setAttribute('scrolling', 'no');
apnxsiframe.setAttribute('marginheight', '0');
apnxsiframe.setAttribute('marginwidth', '0');
apnxsiframe.setAttribute('frameborder', '0');
apnxsiframe.setAttribute('allowtransparency', 'yes');
return apnxsiframe;
},
renderFooter: function(code, winner, tag_div) {
topdom = top.document;
tophead = topdom.getElementsByTagName('head')[0];
topbody = topdom.getElementsByTagName('body')[0];
var asq_footer_degrade=top.document.createElement("div");
asq_footer_degrade.setAttribute("id", "asq_footer_degrade");
var asq_footer_main=top.document.createElement("div");
asq_footer_main.setAttribute("id", "asq_footer_main_div");
var asq_footer_positionz=top.document.createElement("div");
asq_footer_positionz.setAttribute("id", "asq_footer_positionZ");
var asq_footer_close=top.document.createElement("a");
asq_footer_close.setAttribute('href', 'javascript:qsaFooterClose()');
asq_footer_close.setAttribute('id', 'asq_footer_close');
asq_footer_close.setAttribute('title', 'fermer ce bandeau');
var asq_footer_close_text = top.document.createTextNode("fermer");
asq_footer_close.appendChild(asq_footer_close_text);
var asq_footer_css=top.document.createElement("link");
asq_footer_css.setAttribute('rel', 'stylesheet');
asq_footer_css.setAttribute('type', 'text/css');
asq_footer_css.setAttribute('href', 'https://cdn.mediasquare.fr/footer/asq_footer.css');
asq_footer_main.appendChild(asq_footer_close);
asq_footer_main.appendChild(asq_footer_positionz);
tophead.appendChild(asq_footer_css);
topbody.appendChild(asq_footer_main);
topbody.appendChild(asq_footer_degrade);
asq_prebid.renderNormal(code, winner, tag_div);
top.document.getElementById('post_'+code).setAttribute("class", "asq_footer_iframe");
window.top.qsaFooterClose = function() {
top.document.getElementById('asq_footer_main_div').style.display='none';
top.document.getElementById('asq_footer_degrade').style.display='none';
}
},
renderSkin: function(code, winner, tag_div) {
asq_prebid.msqLog(code,' habillage won !');
var c;
var exactMatch = false;
if (typeof asq_skin_params['insertBefore'] == 'undefined')
c = top.document.getElementById('tagHabillage');
for (i=0;i';
tmp_struct += '';
tmp_struct += '__NATIVE_TITLE__
';
tmp_struct += '__NATIVE_BODY__
';
tmp_struct += '';
if (typeof msq_native_conf != 'undefined') {
if (typeof msq_native_conf['stylesheet'] != 'undefined')
stylesheet_file = msq_native_conf['stylesheet']
if (typeof msq_native_conf['struct'] != 'undefined' && msq_native_conf['struct'] != null)
tmp_struct = msq_native_conf['struct'];
}
tmp_struct = tmp_struct.replace('__NATIVE_TITLE__', nat.hb_native_title);
tmp_struct = tmp_struct.replace('__NATIVE_BODY__', nat.hb_native_body);
if (typeof nat.hb_native_brand!='undefined')
tmp_struct = tmp_struct.replace('__NATIVE_BRAND__', ' par '+nat.hb_native_brand);
else
tmp_struct = tmp_struct.replace('__NATIVE_BRAND__', '');
tmp_struct = tmp_struct.replace('__NATIVE_LINK__', nat.hb_native_linkurl);
tmp_struct = tmp_struct.replace('__NATIVE_IMAGE__', nat.hb_native_image);
iframeDoc.write('');
iframeDoc.write(tmp_struct);
if (typeof winner.native.impressionTrackers == "object")
for (i=0; i < winner.native.impressionTrackers.length; i++)
iframeDoc.write('');
if (typeof msq_native_conf == 'undefined' || (typeof msq_native_conf != 'undefined' && typeof msq_native_conf['width'] == 'undefined'))
iframeDoc.write('');
else
iframeDoc.write('');
if (typeof winner.native.clickTrackers == "object") {
iframeDoc.write('');
iframeDoc.close();
window.postMessage(JSON.stringify({message: 'Prebid Native',adId: nat.hb_adid}), '*');
},
renderParallax: function(code, winner, tag_div) {
top.window.checkVisibility = function(trigger) {
td=top.document;
if (td.compatMode == 'CSS1Compat') var d = td.documentElement;
else var d = td.body;
for (i = 0; i < top.window.asq_parallaxes.length; i++) {
t = top.window.asq_parallaxes[i];
top_element = asq_prebid.getTopElement(t, window).getBoundingClientRect();
if (top_element)
if (top_element.top+t.offsetHeight >= 0 && top_element.top+t.offsetHeight <= (top.window.innerHeight))
t.scrollTop=t.clientHeight*((top.window.innerHeight)-t.clientHeight-top_element.top)/((top.window.innerHeight)-t.clientHeight)
}
if (trigger == 'auto')
setTimeout("top.window.checkVisibility('auto')", 250);
};
asq_prebid.renderNormal(code, winner, tag_div);
height = (winner.height / 2 +10);
tag_div.style.cssText='overflow: hidden; height: '+height+'px';
if (typeof top.window.asq_parallaxes == "undefined")
top.window.asq_parallaxes = [];
top.window.asq_parallaxes.push(document.getElementById(code))
e=top.document.getElementById('post_'+code);
top.window.save_onscroll = top.window.onscroll;
if (typeof top.window.onscroll != 'function')
top.window.onscroll = function() {top.window.checkVisibility('event');}
else
top.window.onscroll = function () {
if (top.window.save_onscroll) top.window.save_onscroll();
top.window.checkVisibility('event');
}
top.window.checkVisibility('auto');
top.window.asq_resize(window, winner.width, height);
},
getAdUnitByCode: function(code) {
for (var i = 0; i < asq_pbjs.adUnits.length; i++)
if (asq_pbjs.adUnits[i].code == code)
return asq_pbjs.adUnits[i];
return false;
},
checkVideoSize: function(code) {
var div = document.getElementById(code);
var video_height = div.scrollHeight;
is_spotx = div.querySelectorAll("[id^='spotx_content_container']")
if (is_spotx.length == 1)
video_height = is_spotx[0].scrollHeight
if (video_height == 0)
top.window.asq_resize(window, 0, 0);
else
setTimeout(function() {asq_prebid.checkVideoSize(code)}, 1000);
},
renderVideo: function(code, winner, tag_div) {
var div = document.createElement('div');
div.setAttribute('id', code+'_video');
adunit = asq_prebid.getAdUnitByCode(code+'_video');
if (adunit) {
sizes = adunit.mediaTypes.video.playerSize[0];
div.setAttribute('style', 'width: 300px; height: 250px');
tag_div.style.cssText += 'width: 300px; height: 250px; margin: 0 auto !important;';
tag_div.appendChild(div);
asq_pbjs.renderAd(document, winner.adId);
top.window.asq_resize(window, 300, 250);
setTimeout(function() {asq_prebid.checkVideoSize(code+'_video')}, 3000);
}
else {
adunit = asq_prebid.getAdUnitByCode(code);
sizes = adunit.mediaTypes.video.playerSize[0];
div.setAttribute('style', 'width: 100%px; height: '+winner.height+'px');
//tag_div.style.cssText += 'width: 420px; height: 320px; margin: 0 auto !important;';
top.window.asq_resize(window, '100%', winner.height);
setTimeout(function() {checkSize(code)}, 3000);
asq_pbjs.renderAd(document, winner.adId);
top.window.asq_resize(window, '100%', winner.height);
setTimeout(function() {asq_prebid.checkVideoSize(code)}, 3000);
}
},
renderNormal: function(code, winner, tag_div) {
if (winner.bidderCode != 'adyoulike' || (winner.bidderCode == 'adyoulike' && (winner.height == 250 || winner.height == 600))) {
if (winner.bidderCode == 'adyoulike')
winner.height == 250;
tag_div.appendChild(asq_prebid.getIframeElement(code));
var iframe = document.getElementById('post_'+code);
var iframeDoc = iframe.contentWindow.document;
asq_pbjs.renderAd(iframeDoc, winner.adId);
top.window.asq_resize(window, winner.width, winner.height);
}
else {
iframe = asq_prebid.getIframeElement(code);
iframe.setAttribute('style', 'width: 0; height: 0');
tag_div.appendChild(iframe);
iframe.contentDocument.open();
iframe.contentDocument.write(winner['ad']);
iframe.contentDocument.write('');
iframe.contentDocument.close();
try {
if (Pubstack)
Pubstack.cmd('prebid', 'bidWon', { adId: winner.adId });
}
catch(e) {}
}
},
renderPassback: function(asq_formats, tag_div) {
var current_document = tag_div.ownerDocument;
var code=asq_formats.code;
tag_div.appendChild(asq_prebid.getIframeElement(code));
var iframe = current_document.getElementById('post_'+code);
var iframeDoc = iframe.contentWindow.document;
asq_prebid.msqLog(code, 'passback');
if (asq_formats.sizes)
var passback_sizes = asq_formats.sizes[0];
else
passback_sizes = [0, 0];
var passback = (tag_div.hasAttribute('data-passback') ? tag_div.getAttribute('data-passback') : '');
var passback_tag = (tag_div.hasAttribute('data-passback-tag') ? tag_div.getAttribute('data-passback-tag') : '');
var passback_kw = (tag_div.hasAttribute('data-passback-keywords') ? tag_div.getAttribute('data-passback-keywords') : '');
var passback_sz = (tag_div.hasAttribute('data-passback-sizes') ? tag_div.getAttribute('data-passback-sizes') : '');
passback_kw = passback_kw.replace(/\\(.)/mg, "$1");
var passback_resize = (tag_div.hasAttribute('data-passback-resize') ? tag_div.getAttribute('data-passback-resize') : 'yes');
var passback_force_size = (tag_div.hasAttribute('data-passback-force-size') ? tag_div.getAttribute('data-passback-force-size') : '');
if (passback != '[INSERT_PASSBACK]' && passback != '' && passback_tag == '') {
iframe.style = 'width: 0; height: 0';
iframeDoc.open();
if (passback_force_size != '') {
sizes = passback_force_size.split('x');
iframe.style = 'width: '+sizes[0]+'px; height: '+sizes[1]+'px';
}
if (passback_sz != '') {
iframeDoc.write('');
if (passback_resize != 'no')
iframeDoc.write('googletag.pubads().addEventListener("slotRenderEnded", function(event) {var width = 1, height = 1; if(!event["isEmpty"]) { width = event["size"][0]; height = event["size"][1]; };if(top!=self) {console.log("call to asq_resize"),top.window.asq_resize(window, width, height)}});');
iframeDoc.write('googletag.pubads().definePassback("'+passback+'",'+passback_sz+')'+passback_kw+'.display();');
}
else {
iframeDoc.write('');
if (passback_resize != 'no') {
iframeDoc.write('function autoresize(a) {var resizeW = 0, resizeH = 0; try {if (document.compatMode == "CSS1Compat") var d = document.documentElement; else var d = document.body; resizeW = d.scrollWidth; resizeH = d.scrollHeight; if (resizeW == 300 && resizeH == 150) {resizeW = 0; resizeH = 0; } if (resizeH == 150 && resizeW < 300) resizeH = 90; if (resizeH == 150 && resizeW == 320) resizeH=50 ; top.window.asq_resize(window, resizeW, resizeH);} catch(e) {} if (a < 10 && resizeW == 0 && resizeH == 0) setTimeout(function() {autoresize(a+1);}, 1000)}');
iframeDoc.write('(function() {autoresize(0)})()');
}
}
iframeDoc.close();
} else {
if (passback_tag != '') {
iframeDoc.open();
iframeDoc.write(passback_tag);
if (passback_resize != 'no') {
iframe.style = 'width: 0; height: 0';
iframeDoc.write('function autoresize(a) {var resizeW = 0, resizeH = 0; try {if (document.compatMode == "CSS1Compat") var d = document.documentElement; else var d = document.body; resizeW = d.scrollWidth; resizeH = d.scrollHeight; if (resizeW == 300 && resizeH == 150) {resizeW = 0; resizeH = 0; } if (resizeH == 150 && resizeW < 300) resizeH = 90; if (resizeH == 150 && resizeW == 320) resizeH=50 ; top.window.asq_resize(window, resizeW, resizeH);} catch(e) {} if (a < 10 && resizeW == 0 && resizeH == 0) setTimeout(function() {autoresize(a+1);}, 1000)}');
iframeDoc.write('(function() {setTimeout(function() {autoresize(0)}, 1000)})()');
}
iframeDoc.close();
}
else {
iframe.style.display='none';
top.window.asq_resize(window, 0, 0);
}
}
},
checkVisibility: function(trigger) {
td=top.document;
if (td.compatMode == 'CSS1Compat') var d = td.documentElement;
else var d = td.body;
anyone_left = false;
for (i = 0; i < asq_prebid.lazy_loading.length; i++) {
t = asq_prebid.lazy_loading[i].tag_div;
if (!t.hasAttribute('data-visible') && t.getAttribute('data-visible') != 'yes') {
top_element = asq_prebid.getTopElement(t, window).getBoundingClientRect();
if (top_element.top+(asq_prebid.lazy_loading[i].winner.height/2) >= 0 && top_element.top+(asq_prebid.lazy_loading[i].winner.height/2) <= top.window.innerHeight) {
asq_prebid.renderNormal(asq_prebid.lazy_loading[i].code, asq_prebid.lazy_loading[i].winner, t);
t.setAttribute('data-visible', 'yes');
asq_prebid.msqLog(asq_prebid.lazy_loading[i].code, 'lazy loading ');
}
else
anyone_left = true;
}
}
if (anyone_left && trigger == 'auto')
setTimeout("asq_prebid.checkVisibility('auto')", 250);
},
doLazyLoad: function() {
try {
var save_onscroll = top.window.onscroll;
var save_onresize = top.window.onresize;
if (typeof top.window.onscroll != 'function')
top.window.onscroll = function () {asq_prebid.checkVisibility('event');};
else
top.window.onscroll = function () {
if (save_onscroll) save_onscroll();
asq_prebid.checkVisibility('event');
}
if (typeof top.window.onresize != 'function')
top.window.onresize = function () {asq_prebid.checkVisibility('event');};
else
top.window.onresize = function () {
if (save_onresize) save_onresize();
asq_prebid.checkVisibility('event');
}
asq_prebid.checkVisibility('auto');
}
catch(e) {
for (i = 0; i < asq_prebid.lazy_loading.length; i++)
asq_prebid.renderNormal(asq_prebid.lazy_loading[i].code, asq_prebid.lazy_loading[i].winner, asq_prebid.lazy_loading[i].tag_div);
asq_prebid.lazy_loading = [];
asq_prebid.run_lazy_load = false;
}
},
renderLazy: function(code, winner, tag_div) {
asq_prebid.lazy_loading.push({"code": code, "winner": winner, "tag_div": tag_div});
if (!asq_prebid.run_lazy_load) {
asq_prebid.run_lazy_load = true;
asq_prebid.doLazyLoad();
}
},
renderSafeFrame: function(code, winner, tag_div) {
var current_document = tag_div.ownerDocument;
sandbox = ['allow-popups', 'allow-popups-to-escape-sandbox', 'allow-scripts', 'allow-top-navigation-by-user-activation'];
safeframe_msq = asq_prebid.getIframeElement(code);
safeframe_msq.setAttribute('src', '//cdn.mediasquare.fr/prebid/msq_safeframe.html');
var width = winner['width']
var height = winner['height']
if (winner.bidderCode == 'adyoulike') {
width = '600px';
height = '325px';
}
safeframe_msq.setAttribute('width', width);
safeframe_msq.setAttribute('height', height);
//safeframe_msq.setAttribute('sandbox', sandbox.join(' '));
tag_div.appendChild(safeframe_msq);
current_document.getElementById('post_'+code).onload = function() {
message = JSON.stringify({
'type': 'msq_prebid',
'width': width,
'height': height,
'creative': winner['ad'],
});
this.contentWindow.postMessage(message, '*');
}
try {
if (Pubstack)
Pubstack.cmd('prebid', 'bidWon', { adId: winner.adId });
}
catch(e) {}
},
isZoom: function() {
var isZoom = true;
var test = document.createElement('div');
if (test.style.zoom === undefined)
isZoom = false;
delete test;
return isZoom;
},
getNativeDiv: function(code) {
if (typeof msq_native_conf != 'undefined' && msq_native_conf['type'] != 'free') {
var nat_div = false;
if (typeof msq_native_conf['num'] == 'undefined')
msq_native_conf['num'] = 0;
switch(msq_native_conf['type']) {
case 'class':
nat_div = top.document.getElementsByClassName(msq_native_conf['name'])[msq_native_conf['num']];
break;
case 'tag':
nat_div = top.document.getElementsByTagName(msq_native_conf['name'])[msq_native_conf['num']];
break;
default:
nat_div = top.document.getElementById(msq_native_conf['name']);
break;
}
var nat_final_div = top.document.createElement('div');
nat_final_div.id = 'native_'+code;
if (typeof msq_native_conf['pos'] != 'undefined') {
if (msq_native_conf['pos'] == 'paragraph') {
all_paragraph = nat_div.querySelectorAll('p');
if (all_paragraph.length >= msq_native_conf['num'] + 1)
all_paragraph[msq_native_conf['num']].parentNode.insertBefore(nat_final_div, all_paragraph[1].nextElementSibling);
}
}
else
nat_div.insertBefore(nat_final_div, nat_div.firstChild);
native_placeholder = top.document.getElementById('native_'+code);
nat_creative_div = document.createElement('div');
nat_creative_div.id = 'native_creative_'+code;
nat_creative_div.style.margin = 'auto';
nat_creative_div.style.width = native_placeholder.offsetWidth+'px';
native_placeholder.append(nat_creative_div);
return top.document.getElementById('native_creative_'+code);
}
else
asq_prebid.msqLog(code, 'no native conf found.');
return document.getElementById(code);
},
doPrebid: function() {
asq_pbjs.que.push(function() {
var categoryIds = [];
if (typeof sirdata != 'undefined') {
var categorizedPage = sirdata.Contextual.GetCategorizeFromCache(window.location.href);
if(categorizedPage)
categoryIds = categorizedPage.getCategoryIds();
}
for (i = 0; i < asq_formats.length; i++) {
// check if mediatypes are defined
if (typeof(asq_formats[i].mediaTypes) == 'undefined' && asq_formats[i].sizes) {
for (let [size_index, size_array] of Object.entries(asq_formats[i].sizes))
asq_formats[i].sizes[size_index] = asq_formats[i].sizes[size_index].map(function (x) { return parseInt(x, 10);})
asq_formats[i].mediaTypes = {banner: {sizes: asq_formats[i].sizes}}
}
// if bidder is "ix" and mediatype is not defined then set mediatype as banner
for (j = 0; j < asq_formats[i].bids.length; j++) {
try {
if (asq_formats[i].bids[j].bidder == 'spotx' && asq_formats[i].bids[j]['params']['outstream_options']['custom_override'] instanceof Array){
var custom_override = {}
asq_formats[i].bids[j]['params']['outstream_options']['custom_override'].forEach(function(e) {
if (e['name'] != 'ad_volume')
custom_override[e['name']] = e['value'];
});
asq_formats[i].bids[j]['params']['outstream_options']['custom_override'] = custom_override;
}
} catch(e) {}
try {
if (asq_prebid.appnexus_bidders.indexOf(asq_formats[i].bids[j].bidder) != -1 && typeof categoryIds != "undefined") {
if (asq_formats[i].bids[j].params.keywords == 'undefined')
asq_formats[i].bids[j].params.keywords = {}
asq_formats[i].bids[j].params.keywords.sirdata_contextual_id = categoryIds;
}
}
catch(e) {asq_prebid.msqLog(asq_formats[i].code, 'sirdata keywords insertion failed.');}
/*if (asq_formats[i].bids[j].bidder == 'adyoulike')
asq_formats[i].bids.splice(j, 1);*/
}
//asq_formats[i].bids.push({bidder:"mediasquare", params: {owner: "test", code: "123456"}});
}
asq_pbjs.addAdUnits(asq_formats);
asq_pbjs.requestBids({
timeout: asq_prebid.timeout,
bidsBackHandler: function() {
for (var i=0; i winner.cpm))
winner = winner_video;
if (!winner || winner_nat && (winner_nat.cpm > winner.cpm))
winner = winner_nat;
if ((tag_format && tag_format == 'native') || (winner && winner.mediaType == 'native'))
msq_where_to_insert_creative = asq_prebid.getNativeDiv(asq_formats[i].code);
if (winner && winner.adId) {
try {
log_message = 'winning adid is '+winner.adId
if (winner.creativeId)
log_message += ' ('+winner.creativeId+')'
log_message += ' from '+winner.bidder+' ('+winner.size+')'
asq_prebid.msqLog(asq_formats[i].code, log_message);
}
catch(e) {
asq_prebid.msqLog(asq_formats[i].code,'winning adid is '+winner.adId +' from '+winner.bidder+' ('+winner.size+')');
}
// inject iframe src to log winning creative in local storage
/*try {
logcreasrc = 'https://balance.mediasquare.fr/local.html?code='+asq_formats[i].code+'&bidder='+winner.bidder+'&cpm='+winner.cpm;
if (typeof winner.creativeId != 'undefined') {
asq_prebid.msqLog(asq_formats[i].code,'creative id is '+winner.creativeId);
logcreasrc += '&creative_id='+winner.creativeId;
}
var logcrea = document.createElement("iframe");
logcrea.setAttribute('style', 'display: none');
logcrea.setAttribute('src', logcreasrc);
tag_div.append(logcrea);
}
catch (e) {asq_prebid.msqLog(asq_formats[i].code,'an error while logging the winner ')}*/
// if native creative wins
if (winner.mediaType == 'native') {
asq_prebid.renderNative(asq_formats[i].code, winner, msq_where_to_insert_creative);
}
// if outsteam wins
else if (winner.mediaType == 'video') {
asq_prebid.renderVideo(asq_formats[i].code, winner, msq_where_to_insert_creative);
}
else {
var is_parallaxe = (tag_div.hasAttribute('data-parallax') ? true : false);
// if skin creative wins
if (winner.size == '1800x1000' && asq_skin_params)
asq_prebid.renderSkin(asq_formats[i].code, winner, msq_where_to_insert_creative);
// if parallax wins
else if (is_parallaxe && winner.width / winner.height <= 1)
if (asq_prebid.getTopElement(tag_div, window)) {
asq_prebid.msqLog(asq_formats[i].code,'rendered as parallax.');
asq_prebid.renderParallax(asq_formats[i].code, winner, msq_where_to_insert_creative);
}
else {
asq_prebid.msqLog(asq_formats[i].code, 'attempt for parallax but render normal as top document not accessible.');
asq_prebid.renderNormal(asq_formats[i].code, winner, msq_where_to_insert_creative);
}
// if interstitial wins
else if (winner.size == '320x480' || winner.size == '480x320' || winner.size == '1024x768' || winner.size == '768x1024')
asq_prebid.renderLayer(asq_formats[i].code, winner, msq_where_to_insert_creative);
// if footer wins
else if (asq_formats[i].code.match(/footer/))
asq_prebid.renderFooter(asq_formats[i].code, winner, msq_where_to_insert_creative);
// if max view wins (lazy loading
else if (winner.bidder == "asqMaxView")
asq_prebid.renderLazy(asq_formats[i].code, winner, msq_where_to_insert_creative);
// otherwise, render normal
else
asq_prebid.renderNormal(asq_formats[i].code, winner, msq_where_to_insert_creative);
if (typeof on_focus == "number" && winner.size != '1800x1000') {
asq_prebid.msqLog(asq_formats[i].code, 'onfocus refresh on id '+on_focus);
asq_prebid.setOnFocus(on_focus);
}
}
try {
if (top.window.__cmp) {
top.window.__cmp('getVendorConsents', [21, 25, 32, 40, 79, 115, 165, 264], function(result) {
var cons = result.vendorConsents;
if (cons[21] == true && cons[25] == true && cons[40] == true && cons[79] == true && cons[115] == true && cons[165] == true && cons[264] == true) {
(new Image()).src = "https://sync.search.spotxchange.com/partner?source=241646";
}
if (cons[32] == true) {
(new Image()).src = "https://ib.adnxs.com/getuid?https://sync.search.spotxchange.com/partner?adv_id=7715&uid=$UID";
}
});
}
}
catch (e) {asq_prebid.msqLog(asq_formats[i].code, 'error while sync with spotx ')}
}
else
asq_prebid.renderPassback(asq_formats[i], msq_where_to_insert_creative);
asq_prebid.postProcess(asq_formats[i].code, winner);
}
}
},
});
});
},
startIfReady: function () {
if ((document.readyState === "complete" || document.readyState === "interactive") && asq_prebid.is_prebid_loaded) {
asq_pbjs.aliasBidder("appnexus","msq");
asq_pbjs.aliasBidder("appnexus","msqBrand");
asq_pbjs.aliasBidder("appnexus","msqMaxView");
asq_pbjs.aliasBidder("appnexus","msqMax");
asq_pbjs.aliasBidder("rubicon", "msqRubicon");
asq_pbjs.aliasBidder("appnexus","msqQuantum");
asq_pbjs.aliasBidder("adyoulike","msqAdyoulike");
asq_pbjs.aliasBidder("appnexus","msqv");
asq_pbjs.aliasBidder("appnexus","msqvBrand");
asq_pbjs.aliasBidder("appnexus","asqBrand");
asq_pbjs.aliasBidder("appnexus","asq");
asq_pbjs.aliasBidder("appnexus","ExpressMatic");
asq_pbjs.aliasBidder("appnexus","asqMaxView");
asq_pbjs.aliasBidder("appnexus","asqMax");
asq_pbjs.aliasBidder("appnexus","asqv");
asq_pbjs.aliasBidder("appnexus","asqvBrand");
asq_pbjs.aliasBidder("rubicon","asqRubicon");
asq_pbjs.aliasBidder("ix","msqIx1");
asq_pbjs.aliasBidder("ix","msqIx2");
asq_pbjs.setBidderConfig({
"bidders": ["msq", "msqv", "asq", "asqv"],
"config": {
"schain": {
"validation": "relaxed",
"config": {
"ver":"1.0",
"complete": 1,
"nodes": [{
"asi":"appnexus.com",
"sid":"1608",
"hp": 1
}]
}
}
}
});
asq_pbjs.setBidderConfig({
"bidders": ["msqBrand", "msqvBrand", "asqBrand", "asqvBrand"],
"config": {
"schain": {
"validation": "relaxed",
"config": {
"ver":"1.0",
"complete": 1,
"nodes": [{
"asi":"appnexus.com",
"sid":"3500",
"hp": 1
}]
}
}
}
});
asq_pbjs.setBidderConfig({
"bidders": ["msqMaxView", "msqMax", "asqMaxView", "asqMax"],
"config": {
"schain": {
"validation": "relaxed",
"config": {
"ver":"1.0",
"complete": 1,
"nodes": [{
"asi":"appnexus.com",
"sid":"8494",
"hp": 1
}]
}
}
}
});
asq_pbjs.setBidderConfig({
"bidders": ["msqRubicon", "asqRubicon", "rubicon"],
"config": {
"schain": {
"validation": "relaxed",
"config": {
"ver":"1.0",
"complete": 1,
"nodes": [{
"asi":"rubiconproject.com",
"sid":"9585",
"hp": 1
}]
}
}
}
});
asq_pbjs.setBidderConfig({
"bidders": ["ix"],
"config": {
"schain": {
"validation": "relaxed",
"config": {
"ver":"1.0",
"complete": 1,
"nodes": [{
"asi":"indexexchange.com",
"sid":"187149",
"hp": 1
}]
}
}
}
});
asq_pbjs.setConfig({
rubicon: {singleRequest: true},
consentManagement: {
cmpApi: 'iab',
timeout: 1500,
allowAuctionWithoutConsent: true,
},
priceGranularity: asq_prebid.price_granularity,
"currency": {
"adServerCurrency": "USD",
"granularityMultiplier": 1,
"conversionRateFile": "https://cdn.mediasquare.fr/prebid/currency/rates.json",
"bidderCurrencyDefault": "USD"
}
});
asq_pbjs.bidderSettings = {
asqMaxView: {
bidCpmAdjustment: function(bidCpm, bid) {
if (bid.bidder == "asqMaxView")
if (typeof asq_viewability != "undefined" && typeof asq_viewability[bid.adUnitCode] == "number")
return bidCpm * asq_viewability[bid.adUnitCode] / 100;
else
return bidCpm * 0;
else
return bidCpm;
}
},
msqMaxView: {
bidCpmAdjustment: function(bidCpm, bid) {
if (bid.bidder == "msqMaxView")
if (typeof msq_viewability != "undefined" && typeof msq_viewability[bid.adUnitCode] == "number")
return bidCpm * msq_viewability[bid.adUnitCode] / 100;
else
return bidCpm * 0;
else
return bidCpm;
}
},
adyoulike: {
bidCpmAdjustment: function(bidCpm, bid) {
return bidCpm * 0.8;
}
},
ix: {
bidCpmAdjustment: function(bidCpm, bid) {
return bidCpm / 0.9;
}
}
};
if (typeof asq_formats == "object")
asq_prebid.doPrebid();
}
else
setTimeout("asq_prebid.startIfReady()", 500) ;
},
loadPrebid: function() {
var prebid_script = document.createElement("script");
prebid_script.onload = function() {asq_prebid.is_prebid_loaded=true;};
prebid_script.setAttribute("src", "https://cdn.mediasquare.fr/prebid/prebid_msq.js");
prebid_script.setAttribute("sync", "");
document.getElementsByTagName('head')[0].appendChild(prebid_script);
},
init: function() {
asq_prebid.createAsqResize();
asq_prebid.loadPrebid();
asq_prebid.startIfReady();
},
};
(function () {
//Options
var sirdataToken = "UAhiYyY0hlNiYqpzfbVsnJIj1Himkh"; //Paste your dedicated Token here
//end. Do not edit below except to add modules loaders
var prebidTag = document.createElement('script');
prebidTag.type = 'text/javascript';
prebidTag.src = 'https://contextual.sirdata.io/api/v1/public/script?token='+ sirdataToken;
var headPrebid = document.getElementsByTagName('head')[0];
headPrebid.insertBefore(prebidTag, headPrebid.firstChild);
prebidTag.onload = function(){
try {
var categorizedPage = sirdata.Contextual.GetCategorizeFromCache(window.location.href);
loadAppnexusBidder(asq_prebid.appnexus_bidders,(categorizedPage?categorizedPage.getCategoryIds():[])); //Launch modules from here. Appnexus example
}
catch(e) {console.log('could not find sirdata');}
};
})();
function loadAppnexusBidder(authorizedBidders,categoryIds){
for (var i in asq_pbjs.adUnits) {
for (var bidIndex in asq_pbjs.adUnits[i].bids) {
if (authorizedBidders.indexOf(asq_pbjs.adUnits[i].bids[bidIndex].bidder) != -1) {
var keywords = {};
if (asq_pbjs.adUnits[i].bids[bidIndex].params.keywords !== undefined) {
keywords = pbjs.adUnits[i].bids[bidIndex].params.keywords;
}
keywords.sirdata_contextual_id = categoryIds;
asq_pbjs.adUnits[i].bids[bidIndex].params.keywords = keywords;
}
}
}
}
asq_prebid.init();