// Prebid-header JS generator v5.2.0 - prebid 8 - PPID support (with timeout)
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
var googletag_ref;
var PREBID_TIMEOUT = 2000;
var FAILSAFE_TIMEOUT = 3000;
var N14_TIMEOUT = 600;
// UAM vars
// load the apstag.js library
!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(){},targetingKeys:function(){return[]},_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");
// initialize the apstag.js library on the page to allow bidding
apstag.init({
pubID: '4d82ee98-0c5b-4c96-a74c-68b0a5395433', //enter your pub ID here as shown above, it must within quotes
adServer: 'googletag'
,schain: {
complete: 1,
ver: '1.0',
nodes: [
{
"asi":"next14.com",
"sid":"38052",
"hp":1
}
]
}
});
var adsSlots;
function printSlots() {
var slots = googletag.pubads().getSlots()
for (s in slots) {
var slot = slots[s];
var sizes = new Array();
for (z in slot.getSizes()) {
var size = slot.getSizes()[z];
sizes.push(new Array(size.l,size.j));
}
console.log("Slot '" + slot.getAdUnitPath() + "' -> div '" + slot.getSlotElementId() + "' -> sizes: " + JSON.stringify(sizes));
}
}
function zdk_isMobile() {
return (screen.width <= 1024);
}
// <@@@>
function findContextForFunction(functionName) {
var curr = null;
var i=0;
do {
try {
i++;
if (curr == null) curr = window;
else curr = curr.parent;
if (typeof curr[functionName] === 'function') return curr;
} catch(err) {
console.log("fcff_e", err);
}
} while (curr !== window.top && i<20); //avoid infinite loop
return false;
}
function disableOldFunctions() {
console.log("DISABLE oz_enable_gpt() if exists");
var ctx = findContextForFunction('oz_enable_gpt');
if (ctx) {
console.log("got oz_enable_gpt!", ctx.oz_enable_gpt);
ctx.oz_enable_gpt = function () { console.log("@@@ oz_enable_gpt(). do nothing"); }
console.log("oz_enable_gpt disabled");
} else {
console.log("oz_enable_gpt not found");
}
}
//
function zdkFindCMP() {
// <@@@>
return findContextForFunction('__tcfapi');
}
/* returns [adUnits, adsSlots] */
function aplus_buildAdUnits(googletag) {
var slots = new Array();
// parse google slots definition
var g_slots = googletag.pubads().getSlots()
for (s in g_slots) {
var slot = g_slots[s];
var sizes = new Array();
for (z in slot.getSizes()) {
var size = slot.getSizes()[z];
sizes.push(new Array(size.l,size.j));
}
slots.push({"slot":slot.getAdUnitPath(),"div":slot.getSlotElementId(),"sizes":sizes});
}
// generate the adunits & adsSlots
var adUnits = new Array();
var adsSlots = new Array();
for (s in slots) {
var googleSlot = slots[s];
var aplus_slot_found = aplus_slots.filter(function(el){
return (el.slot==googleSlot.slot);
});
if (!aplus_slot_found || aplus_slot_found.length<1) {
console.log("slot: "+googleSlot.slot+" not matched");
continue;
}
var pl_id = (zdk_isMobile())?aplus_slot_found[0].plm:aplus_slot_found[0].pld;
var aplus_placement_found = aplus_placements.filter(function(el){
return (el.pl==pl_id);
});
if (!aplus_placement_found || aplus_placement_found.length<1) {
console.log("placement: "+pl_id+" not found");
continue;
}
//console.log("found ["+JSON.stringify(aplus_slot_found[0])+"] -> "+JSON.stringify(aplus_placement_found[0]));
// add to adUnits
var adUnitObj = {
code: googleSlot.slot,
mediaTypes: {
banner: {
sizes: aplus_placement_found[0].sizes
}
},
bids: aplus_placement_found[0].bids
};
// if interstitial is enabled, i'll have renderer declared on z_interstitial var
if (aplus_slot_found[0].interstitial) {
if (typeof z_interstitial !== "undefined") {
adUnitObj.renderer = z_interstitial.renderer;
} else {
console.log("WARN - z_interstitial not defined");
}
}
adUnits.push(adUnitObj);
console.log("slot: "+googleSlot.slot+" - adUnitObj: ",adUnitObj);
// add to adsSlots
adsSlots.push({
slotID: googleSlot.div,
slotName: googleSlot.slot,
sizes: aplus_placement_found[0].sizes
});
}
//console.log("--- slots recreated:");
//console.log(adUnits);
//console.log(adsSlots);
return [adUnits,adsSlots];
}
const zCallback = (tcData, success) => {
//console.log("__tcfapi ST: "+tcData.eventStatus);
if (success && (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {
console.log("__tcfapi ok");
// <@@@>
console.log("@@@ cmp done. call engine start");
cmp_done = true;
zEngineStart();
// remove the ourself to not get called more than once
var cmp_layer = zdkFindCMP(); // @LLY-IF
if (cmp_layer) { // @LLY-IF
console.log("__tcfapi - removeEventListener");
cmp_layer.__tcfapi('removeEventListener', 2, (success) => {}, tcData.listenerId); // @LLY-IF
} // @LLY-IF
} else {
// useless events
}
}
// ***** parallel UAM+criteo+pbjs *****
// config/sync object
function cleanADStatus() { // @LLY-CL
console.log("cleanADStatus - init");
window.hb_status = {
n_adserver_callback: [],
adserverRequestSent: false, // true once everything has been completed
prebidTargetingSet: false
};
//if i don't have criteo / uam integration, just set them already done
window.hb_status.n_adserver_callback.push("criteo");
// <@@@> - if PPID is not required, set n14_done=true
oz_cfg_done = false;
// if i've already found a cmp, i shouldn't be waiting for it another time
// cmp_done = false;
n14_done = (individual_id != null ) || false;
zEngineStarted = false;
} // @LLY-CL
function zEngineStart() {
// PPID - if CMP done, i can set the timeout for the n14 PPID script
if (cmp_done && !n14_done) {
setTimeout(_n14callback,N14_TIMEOUT,{detail:null, timeout: true});
}
// <@@@>
// check if every call back has been completed
if (!oz_cfg_done || !n14_done || !cmp_done) {
console.log("@@@ skip engine start as i've to wait for someone. already done: CFG="+oz_cfg_done+", PPID="+n14_done+", CMP="+cmp_done);
return;
}
if (zEngineStarted) {
//avoid to do it twice
console.log("@@@ engine already started before");
return;
}
zEngineStarted = true;
console.log("@@@ all callbacks ok! start the engine!");
googletag.cmd.push(function() {
// Passing of PPID to GPT tag
if (individual_id)
googletag.pubads().setPublisherProvidedId(individual_id);
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
console.log("@@@ engine started. (ppid = "+individual_id+")");
pbjs.que.push(function() {
console.log("on pbjs PUSH request bids");
//
// ===== APS request
console.log("===== set aps(UAM) callback");
apstag.fetchBids({
slots: adsSlots,
timeout: PREBID_TIMEOUT
},function(bids) {
console.log("aps handler");
adServerCallback('aps');
});
// ===== Prebid callback
console.log("===== set Prebid callback");
pbjs.requestBids({
bidsBackHandler: function() {
console.log("prebid handler");
adServerCallback('prebid');
},
timeout: PREBID_TIMEOUT
});
// ===== Safety timeout
console.log("===== set Safety timeout ");
setTimeout(function() {
adServerCallback('timeout');
}, FAILSAFE_TIMEOUT);
//
});
}
// ===== Combined callback (this callback will be called by Prebid, Criteo, or timeout)
function adServerCallback(source) {
console.log("ON adServerCallback ",source);
if (window.hb_status.adserverRequestSent) return;
// add source to the processed list
window.hb_status.n_adserver_callback.push(source); // add this source as "bidderDone"
if (source == 'aps') {
googletag.cmd.push(function() {
console.log("aps SET TARGETING");
apstag.setDisplayBids();
});
} else if (source == 'prebid') {
// got prebid config request
googletag.cmd.push(function() {
pbjs.que.push(function() {
console.log("pbjs SET TARGETING");
pbjs.setTargetingForGPTAsync(); // configure targeting for prebid
window.hb_status.prebidTargetingSet = true;
});
});
} else if (source == 'criteo') {
// got criteo config request
googletag.cmd.push(function() {
console.log("criteo SET TARGETING");
Criteo.SetDFPKeyValueTargeting(); // This will append Criteo keywords to the adserver call
});
}
// check if i've completed
if (window.hb_status.n_adserver_callback.length >= 3) {
// if all bids have been completed googletag.pubads().refresh();
window.hb_status.adserverRequestSent = true;
googletag.cmd.push(function() {
console.log("REFRESH for bidders done");
googletag.pubads().refresh(); // this will will trigger the adserver calls
});
} else if ("timeout" == source) {
// got timeout (one of prebid or criteo or aps didn't finish in time)
window.hb_status.adserverRequestSent = true;
googletag.cmd.push(function() {
// pbjs.setTargetingForGPTAsync(); MUST be done ANYWAY before googletag.pubads().refresh();
if (!window.hb_status.prebidTargetingSet) {
pbjs.que.push(function() {
console.log("setTargetingForGPTAsync on timeout");
pbjs.setTargetingForGPTAsync(); // configure targeting for prebid
});
}
console.log("REFRESH for timeout");
googletag.pubads().refresh(); // this will will trigger the adserver calls
});
};
}
//called by the html page just before "googletag.enableServices()" and after googletag.defineSlot(...)s
function oz_config(googletag) {
cleanADStatus(); // @LLY-CL
// <@@@>
disableOldFunctions();
googletag_ref = googletag;
googletag_ref.pubads().disableInitialLoad();
googletag_ref.pubads().enableSingleRequest();
adUnits_adsSlots = aplus_buildAdUnits(googletag_ref);
adUnits = adUnits_adsSlots[0];
adsSlots = adUnits_adsSlots[1];
console.log("adUnits & adsSlots:");
console.log(adUnits_adsSlots);
pbjs.que.push(function() { // pbjs 1/2 (cfg)
configurePBJS();
bidderSettingsPBJS();
// pbjs.destroyAdUnits(); - may be needed for single page applications
console.log("cleanADStatus - removing adUnits before adding them");
pbjs.removeAdUnit(); // @LLY-CL
pbjs.addAdUnits(adUnits);
console.log("addAdUnits done");
});
// check whether start the engine or wait for CMP approval/refuse
var cmp_layer = zdkFindCMP(); // @LLY-IF
if (cmp_layer) { // @LLY-IF
console.log("__tcfapi - set listener");
cmp_layer.__tcfapi('addEventListener', 2, zCallback); // @LLY-IF
//zEngineStart() will be called after CMP approval/refusal
} else {
// CMP not found
console.log("__tcfapi not found - load normally");
cmp_done = true;
// <@@@>
// zEngineStart();
}
//googletag.enableServices() MUST be done in publisher's page. if PPID is integrated, a custom code should be used
//googletag_ref.enableServices();
// <@@@>
oz_cfg_done = true;
console.log("@@@ config done. call engine start");
// <@@@>
zEngineStart();
}
// <@@@> - if PPID is not required, set n14_done=true
var individual_id = individual_id || null;
var oz_cfg_done = false;
var cmp_done = false;
var n14_done = (individual_id != null ) || false; /*PPID required*/
var zEngineStarted = false;
function _n14callback(event) {
console.log("@@@ _n14callback.", event);
// Access the parameter passed to the event
if (event.detail)
individual_id = event.detail;
// Process the parameter
console.log("@@@ _n14 done. call engine start", individual_id);
n14_done = true;
zEngineStart();
}
// only if PPID is integrated, add the event listener to the document or any specific element
document.removeEventListener('next_id_event_x2a', _n14callback);
document.addEventListener('next_id_event_x2a', _n14callback);
//
// try to find firstPartyData hints from browser's ua
var listOfEntropyValues = null;
try {
navigator.userAgentData.getHighEntropyValues([
"architecture",
"model",
"platformVersion",
"fullVersionList",
]).then((values) => {
listOfEntropyValues = Object.keys(values);
console.log("got ua entropy values: "+listOfEntropyValues);
});
} catch (error) {
console.log("cannot get ua entropy values. leave it blank");
}
// NOCMP based on CMP in page detection + userSync iframe enabled with filters
function configurePBJS() {
/* pbjsConfig */
if (listOfEntropyValues!=null) {
console.log("setting ua entropy values: "+listOfEntropyValues);
pbjs.setConfig({
firstPartyData: {
uaHints: listOfEntropyValues
}
});
}
pbjs.setConfig({
userSync: {
filterSettings: {
iframe: {
bidders: '*', // '*' means all bidders
filter: 'include'
}
}
},
gptPreAuction: {
enabled: true, // enabled by default
},
useBidCache: true,
eventHistoryTTL: 60, // maximum time (in seconds) that events should be kept in memory
priceGranularity: "dense",
firstPartyData: {
uaHints: [
"architecture",
"model",
"platform",
"platformVersion",
"fullVersionList"
]
},
enableTIDs: true,
currency: {
// enables currency feature
"adServerCurrency": "EUR",
//"granularityMultiplier": 1, // 0.50 increment up to 5 is fine for GBP... what is that?!?!
// until bidder adapters are updated to define the bid currency
// the system assumes bids are in USD. This can be overridden, for instance:
"bidderCurrencyDefault": { "openx": "EUR" },
"conversionRateFile": "//currency.prebid.org/latest.json" // prebid's lib bug fix - this way allows both http and https
},
consentManagement: {
gdpr: {
cmpApi: 'iab',
timeout: 8000,
// allowAuctionWithoutConsent: true,
defaultGdprScope: true
}
},
improvedigital: {
usePrebidSizes: true
},
//rubicon new config: Single-Request optimization
rubicon: {singleRequest: true}
});
pbjs.setConfig({
"schain": {
"validation": "strict",
"config": {
"ver":"1.0",
"complete": 1,
"nodes": [
{
"asi":"next14.com",
"sid":"38052",
"hp":1
}
]
}
}
});
// specific adasta stuff)
pbjs.setBidderConfig({
"bidders": ['adasta'],
"config": {
"schain": {
"config": {
"ver":"1.0",
"complete": 1,
"nodes" : [
{
"asi":"next14.com",
"sid":"38052",
"hp":1
}
].concat([{"asi":"adasta.it","sid":"13","hp":1}])
}
}
}
}, true); // = merge existing (add to global config)
if (!zdkFindCMP()) {
// no CMP inside the publiser's page. set "NOCMP" parameters overriding consentManagement
console.log("znocmp");
pbjs.setConfig({
consentManagement: {
gdpr: {
cmpApi: 'static',
consentData: {
getConsentData: {
'gdprApplies': false
}
}
}
}
});
} else {
console.log("zcmp");
}
/* /pbjsConfig */
}
function bidderSettingsPBJS() {
//console.log("bidderSettings pbjs");
//ssps price adjustment
pbjs.bidderSettings = {
standard: {
storageAllowed: true
},
adf: {
bidCpmAdjustment : function(bidCpm){
bidCpm = bidCpm * 0.90;
return bidCpm;
}
},
pubmatic: {
bidCpmAdjustment : function(bidCpm){
bidCpm = bidCpm * 0.92;
return bidCpm;
}
},
adasta: {
bidCpmAdjustment : function(bidCpm){
bidCpm = bidCpm * 0.7;
return bidCpm;
}
}
};
pbjs.aliasBidder('appnexus', 'turbo');
pbjs.aliasBidder('appnexus', 'adasta');
pbjs.aliasBidder('ix', 'ix1');
}
/* interstitial default properties */
var z_interstitial = {
renderer: {
url: 'https://secure-assets.rubiconproject.com/utils/prebidInter/prebidInter.min.js',
render: function(prebidBid) {
this.push(() => {
window.interstitial.renderAd({
fullBids: prebidBid, // required, please don't edit or change!
overlayColor: "black", // optional, color of the overlay.
overlayOpacity: 0.5, // optional, value between 0 and 1 defining the opacity of the overlay.
// closeTime: "10", // optional, time in second before the user can close the interstitial.
showCloseButtonAfterSeconds: 0 // optional. Time in seconds before the close button appears.
});
});
}
}
};
/* this will be different for each publisher/site */
var aplus_slots = [
{slot:"/57491254/tuttomercatoweb.com/FirenzeViola/ros/MaxTicker",plm:96615,pld:96610},
{slot:"/57491254/tuttomercatoweb.com/FirenzeViola/ros/MaxTicker_Bottom",plm:96615,pld:96610},
{slot:"/57491254/tuttomercatoweb.com/FirenzeViola/ros/MaxTicker_Middle",plm:96615,pld:96610},
{slot:"/57491254/tuttomercatoweb.com/FirenzeViola/ros/MPU_Bottom",plm:96616,pld:96611},
{slot:"/57491254/tuttomercatoweb.com/FirenzeViola/ros/MPU_Middle",plm:96616,pld:96611},
{slot:"/57491254/tuttomercatoweb.com/FirenzeViola/ros/MPU_Top",plm:96616,pld:96611},
{slot:"/57491254/tuttomercatoweb.com/FirenzeViola/ros/Overlay",plm:96617,pld:96612,interstitial:true}
];
var aplus_placements = [
{pl:96615,sizes:[[320, 50],[320, 100]],bids:[{bidder:'appnexus', params:{placementId:'33761025'}},{bidder:'criteo', params:{networkId:6093}},{bidder:'rubicon', params:{accountId:'13258',siteId:'70942',zoneId:'3500986',sizes:[43,117]}}]},
{pl:96610,sizes:[[728, 90],[970, 250]],bids:[{bidder:'appnexus', params:{placementId:'33761007'}},{bidder:'criteo', params:{networkId:6093}},{bidder:'rubicon', params:{accountId:'13258',siteId:'70942',zoneId:'3500908',sizes:[2,57]}}]},
{pl:96616,sizes:[[300, 250]],bids:[{bidder:'appnexus', params:{placementId:'33761030'}},{bidder:'criteo', params:{networkId:6093}},{bidder:'rubicon', params:{accountId:'13258',siteId:'70942',zoneId:'3500918',sizes:[15]}}]},
{pl:96611,sizes:[[300, 250]],bids:[{bidder:'appnexus', params:{placementId:'33761010'}},{bidder:'criteo', params:{networkId:6093}},{bidder:'rubicon', params:{accountId:'13258',siteId:'70942',zoneId:'3500916',sizes:[15]}}]},
{pl:96617,sizes:[[320, 480]],bids:[{bidder:'appnexus', params:{placementId:'33761034'}},{bidder:'rubicon', params:{accountId:'13258',siteId:'70942',zoneId:'3500942',sizes:[67]}}]},
{pl:96612,sizes:[[320, 480]],bids:[{bidder:'appnexus', params:{placementId:'33761011'}},{bidder:'rubicon', params:{accountId:'13258',siteId:'70942',zoneId:'3500940',sizes:[67]}}]}
];