Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*globals JPIM, TBC, googletag, itag*/
- import {
- maxLaptopBreakPoint,
- tabletBreakPoint,
- TOPBANNER,
- ARTICLEMPU1,
- ARTICLEMPU2,
- ARTICLEMPU3,
- ARTICLEMPU4,
- ARTICLEMPU5,
- BOTTOMBANNER,
- MPUD0,
- MPUD1,
- MPUS2,
- MPUS3,
- MPUS4,
- MPUS6,
- MPUS8,
- MPUS9,
- MPUS11,
- SIDEBARMPU1,
- SIDEBARMPU2,
- SIDEBARMPU3,
- TEADSIB,
- } from './gpt';
- function appNexus(placementId, section, pagelevel) {
- return {
- 'bidder': 'appnexus',
- 'params': {
- 'placementId': placementId,
- 'query': {
- section,
- pagelevel,
- },
- },
- }
- }
- function rubicon(siteId, zoneId, itag) {
- return {
- 'bidder': 'rubicon',
- 'params': {
- 'accountId': '11022',
- siteId,
- zoneId,
- 'visitor': {
- 'lotameAudiences': itag.getAudienceIds(),
- },
- 'inventory': {
- 'site': itag.setSite(),
- 'grapeshotChannels': itag.getGrapeshotChannels(),
- },
- },
- }
- }
- function criteo(zoneId) {
- return {
- 'bidder': 'criteo',
- 'params': {
- zoneId,
- },
- }
- }
- // GM/XAXIS
- function gm(placementId) {
- return {
- 'bidder': 'gm',
- 'params': {
- placementId,
- },
- }
- }
- function pubmatic(placementId) {
- return {
- 'bidder': 'pubmatic',
- 'params': {
- placementId,
- publisherId: '157771',
- },
- }
- }
- export default ([slots, windowWidth, topSection]) => {
- return new Promise(((resolve, reject) => {
- var PREBID_TIMEOUT = 2000;
- const rubiconSiteId = windowWidth > maxLaptopBreakPoint ? '29278' : '43620';
- const bidConfigMobile = [
- [TOPBANNER, 9768046, 548910, 759845, 16550501, 2508842], // domid, APPNEXUS, RUBICON, CRITEO, GM/XAXIS, PUBMATIC
- [ARTICLEMPU1, 9768048, 548912, 759855, 16550456, 2508843],
- [ARTICLEMPU2, 9865788, 548914, 759856, 17620007, 2508844],
- [ARTICLEMPU3, 9865789, 548918, 759857, 17620015, 2508813],
- [ARTICLEMPU4, 9865790, 548916, 759858, 17620016, 2508814],
- [ARTICLEMPU5, 9865791, 548920, 759859, 17620049, 2508815],
- [BOTTOMBANNER,9865792, 548924, 759860, 16550501, 2508816],
- [MPUD0, 9768048, 548912, 812372, null, 2508845],
- [MPUD1, 9768048, 548912, 812372, null, 2508846],
- [MPUS2, 9865788, 548914, 812375, 17620051, 2508847],
- [MPUS3, 9865788, 548914, 812375, 17620052, 2508848],
- [MPUS4, 9865788, 548914, 812375, 17620054, 2508849],
- [MPUS6, 9865789, 548918, 812377, null, 2508850],
- [MPUS8, 9865789, 548918, 812377, null, 2508851],
- [MPUS9, 9865790, 548916, 812378, null, 2508852],
- [MPUS11,9865791, 548920, 812389, null, 2508853],
- ];
- const bidConfigTablet = bidConfigMobile.map((bidder) => {
- const [slot, appNexus, rubicon, criteo] = bidder;
- switch (slot) {
- case TOPBANNER:
- case BOTTOMBANNER:
- return [slot, appNexus, rubicon, criteo, 16550486];
- default:
- return bidder;
- }
- });
- const bidConfigDesktop = [
- [TOPBANNER, 9395956, 548764, 759844, 16550440, 2508798], // domid, APPNEXUS, RUBICON, CRITEO, GM/XAXIS, PUBMATIC
- [ARTICLEMPU1, 9865760, 548766, 812372, 16550471, 2508799],
- [ARTICLEMPU2, 9865762, 548774, 759851, 17619828, 2508800],
- [SIDEBARMPU1, 9865762, 548766, 812377, 16550439, 2508801],
- [SIDEBARMPU2, 9865763, 548770, 812378, 17619838, 2508802],
- [SIDEBARMPU3, 9865787, 548772, 812389, 17619841, 2508803],
- [MPUD0, 9865760, 548766, 759849, 16550439, 2508804],
- [MPUD1, 9865760, 548766, 759849, 17619876, 2508805],
- [MPUS2, 9865761, 548770, 759850, 17620135, 2508806],
- [MPUS3, 9865761, 548770, 759850, 17620136, 2508807],
- [MPUS4, 9865761, 548770, 759850, 17620138, 2508808],
- [MPUS6, 9865762, 548772, 759851, 17620139, 2508809],
- [MPUS8, 9865762, 548772, 759851, null, 2508810],
- [MPUS9, 9865763, 548774, 759852, null, 2508811],
- [MPUS11,9865787, 548776, 759853, null, 2508812],
- ];
- const bidder = [];
- let configBidder;
- if (windowWidth > maxLaptopBreakPoint) {
- configBidder = bidConfigDesktop;
- } else if (windowWidth >= tabletBreakPoint) {
- configBidder = bidConfigTablet;
- } else {
- configBidder = bidConfigMobile;
- }
- configBidder.push([TEADSIB, 11775136, null, null, null, null]);
- slots.filter(x => !!x).forEach((slot) => {
- const id = slot.getTargeting('tile')[0];
- const foundSlot = configBidder
- .find(([slotId]) => slotId === id);
- if (foundSlot) {
- // TODO remove this when xaxis prebid is rolled out for everyone
- if(JPIM.domain !== 'doncasterfreepress.co.uk') {
- foundSlot[foundSlot.length - 1] = null;
- }
- bidder.push({
- code: id,
- sizes: slot.getSizes().map(size => size.length === 1 ? Object.values(size)[0] : Object.values(size)),
- bids: foundSlot
- .map((placementId, i) => {
- if (!placementId) return null;
- switch (i) {
- case 1:
- return appNexus(placementId, topSection, JPIM.pageType);
- case 2:
- return rubicon(rubiconSiteId, placementId, window.itag);
- case 3:
- return criteo(placementId);
- case 4:
- return gm(placementId);
- case 5:
- return pubmatic(placementId);
- default:
- return null;
- }
- })
- .filter(x => !!x),
- })
- }
- });
- const pbjs = window.pbjs || {};
- pbjs.que = pbjs.que || [];
- pbjs.bidderSettings = {
- 'standard': {
- 'adserverTargeting': [{
- 'key': 'hb_pb',
- 'val': function(bidResponse) {
- var cpm = getPriceBucket(bidResponse.cpm);
- return (typeof cpm === 'number') ? cpm.toFixed(2) : cpm;
- },
- }, {
- 'key': 'hb_adid',
- 'val': function(bidResponse) {
- return bidResponse.adId;
- },
- }, {
- 'key': 'hb_size',
- 'val': function(bidResponse) {
- return bidResponse.size;
- },
- }, {
- 'key': 'hb_bidder',
- 'val': function(bidResponse) {
- return bidResponse.bidder;
- },
- }, {
- 'key': 'hb_deal',
- 'val': function(bidResponse) {
- return bidResponse.dealId;
- },
- }],
- },
- 'rubicon': {
- 'adserverTargeting': [{
- 'key': 'hb_deal_rubicon',
- 'val': function(bidResponse) {
- return bidResponse.dealId || 0;
- },
- }],
- },
- 'gm': {
- bidCpmAdjustment : function(bidCpm){
- return bidCpm * 1.10;
- },
- },
- };
- pbjs.que.push(function() {
- pbjs.addAdUnits(bidder);
- pbjs.aliasBidder('appnexus', 'gm');
- pbjs.requestBids({
- 'bidsBackHandler': sendAdserverRequest,
- });
- });
- function sendAdserverRequest() {
- if (pbjs.adserverRequestSent) return;
- pbjs.adserverRequestSent = true;
- googletag.cmd.push(function() {
- pbjs.que.push(function() {
- pbjs.setTargetingForGPTAsync();
- resolve();
- });
- });
- pbjs.priceBuckets = pbjs.priceBuckets || {};
- pbjs._bidsReceived = pbjs._bidsReceived || [];
- for (var i = 0; i < pbjs._bidsReceived.length; i++) {
- var currentBidReceived = pbjs._bidsReceived[i];
- pbjs.priceBuckets[currentBidReceived.adUnitCode] = getPriceBucket(currentBidReceived.cpm);
- }
- }
- setTimeout(function() {
- sendAdserverRequest();
- }, PREBID_TIMEOUT);
- /* Adomik randomizer for ad call key value targeting */
- const Adomik = window.Adomik || {};
- Adomik.randomAdGroup = function() {
- var rand = Math.random();
- switch (false) {
- case !(rand < 0.09):
- return 'ad_ex' + (Math.floor(100 * rand));
- case !(rand < 0.10):
- return 'ad_bc';
- default:
- return 'ad_opt';
- }
- };
- function convertNumberToPrice(number) {
- return parseFloat(number.toFixed(2));
- }
- function getPriceBucket(price) {
- var increment = 0;
- price = convertNumberToPrice(price);
- if (price < 0.25) {
- increment = 0;
- } else if (price < 2.10) {
- increment = 0.05;
- } else if (price < 5.00) {
- increment = 0.10;
- } else if (price < 8.50) {
- increment = 0.20;
- } else if (price < 15.00) {
- increment = 0.50;
- } else if (price >= 15.00) {
- return 15.00;
- }
- if (increment === 0) {
- return price;
- } else {
- var remainder = Math.round((price % increment) * 100) / 100;
- return (remainder >= increment) ? price : convertNumberToPrice(price - remainder);
- }
- }
- }));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement