Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.88 KB | None | 0 0
  1. /*globals JPIM, TBC, googletag, itag*/
  2.  
  3. import {
  4. maxLaptopBreakPoint,
  5. tabletBreakPoint,
  6. TOPBANNER,
  7. ARTICLEMPU1,
  8. ARTICLEMPU2,
  9. ARTICLEMPU3,
  10. ARTICLEMPU4,
  11. ARTICLEMPU5,
  12. BOTTOMBANNER,
  13. MPUD0,
  14. MPUD1,
  15. MPUS2,
  16. MPUS3,
  17. MPUS4,
  18. MPUS6,
  19. MPUS8,
  20. MPUS9,
  21. MPUS11,
  22. SIDEBARMPU1,
  23. SIDEBARMPU2,
  24. SIDEBARMPU3,
  25. TEADSIB,
  26. } from './gpt';
  27.  
  28. function appNexus(placementId, section, pagelevel) {
  29. return {
  30. 'bidder': 'appnexus',
  31. 'params': {
  32. 'placementId': placementId,
  33. 'query': {
  34. section,
  35. pagelevel,
  36. },
  37. },
  38. }
  39. }
  40.  
  41. function rubicon(siteId, zoneId, itag) {
  42. return {
  43. 'bidder': 'rubicon',
  44. 'params': {
  45. 'accountId': '11022',
  46. siteId,
  47. zoneId,
  48. 'visitor': {
  49. 'lotameAudiences': itag.getAudienceIds(),
  50. },
  51. 'inventory': {
  52. 'site': itag.setSite(),
  53. 'grapeshotChannels': itag.getGrapeshotChannels(),
  54. },
  55. },
  56. }
  57. }
  58.  
  59. function criteo(zoneId) {
  60. return {
  61. 'bidder': 'criteo',
  62. 'params': {
  63. zoneId,
  64. },
  65. }
  66. }
  67.  
  68. // GM/XAXIS
  69. function gm(placementId) {
  70. return {
  71. 'bidder': 'gm',
  72. 'params': {
  73. placementId,
  74. },
  75. }
  76. }
  77.  
  78. function pubmatic(placementId) {
  79. return {
  80. 'bidder': 'pubmatic',
  81. 'params': {
  82. placementId,
  83. publisherId: '157771',
  84. },
  85. }
  86. }
  87.  
  88. export default ([slots, windowWidth, topSection]) => {
  89. return new Promise(((resolve, reject) => {
  90. var PREBID_TIMEOUT = 2000;
  91. const rubiconSiteId = windowWidth > maxLaptopBreakPoint ? '29278' : '43620';
  92. const bidConfigMobile = [
  93. [TOPBANNER, 9768046, 548910, 759845, 16550501, 2508842], // domid, APPNEXUS, RUBICON, CRITEO, GM/XAXIS, PUBMATIC
  94. [ARTICLEMPU1, 9768048, 548912, 759855, 16550456, 2508843],
  95. [ARTICLEMPU2, 9865788, 548914, 759856, 17620007, 2508844],
  96. [ARTICLEMPU3, 9865789, 548918, 759857, 17620015, 2508813],
  97. [ARTICLEMPU4, 9865790, 548916, 759858, 17620016, 2508814],
  98. [ARTICLEMPU5, 9865791, 548920, 759859, 17620049, 2508815],
  99. [BOTTOMBANNER,9865792, 548924, 759860, 16550501, 2508816],
  100. [MPUD0, 9768048, 548912, 812372, null, 2508845],
  101. [MPUD1, 9768048, 548912, 812372, null, 2508846],
  102. [MPUS2, 9865788, 548914, 812375, 17620051, 2508847],
  103. [MPUS3, 9865788, 548914, 812375, 17620052, 2508848],
  104. [MPUS4, 9865788, 548914, 812375, 17620054, 2508849],
  105. [MPUS6, 9865789, 548918, 812377, null, 2508850],
  106. [MPUS8, 9865789, 548918, 812377, null, 2508851],
  107. [MPUS9, 9865790, 548916, 812378, null, 2508852],
  108. [MPUS11,9865791, 548920, 812389, null, 2508853],
  109. ];
  110.  
  111. const bidConfigTablet = bidConfigMobile.map((bidder) => {
  112. const [slot, appNexus, rubicon, criteo] = bidder;
  113. switch (slot) {
  114. case TOPBANNER:
  115. case BOTTOMBANNER:
  116. return [slot, appNexus, rubicon, criteo, 16550486];
  117. default:
  118. return bidder;
  119. }
  120. });
  121.  
  122. const bidConfigDesktop = [
  123. [TOPBANNER, 9395956, 548764, 759844, 16550440, 2508798], // domid, APPNEXUS, RUBICON, CRITEO, GM/XAXIS, PUBMATIC
  124. [ARTICLEMPU1, 9865760, 548766, 812372, 16550471, 2508799],
  125. [ARTICLEMPU2, 9865762, 548774, 759851, 17619828, 2508800],
  126. [SIDEBARMPU1, 9865762, 548766, 812377, 16550439, 2508801],
  127. [SIDEBARMPU2, 9865763, 548770, 812378, 17619838, 2508802],
  128. [SIDEBARMPU3, 9865787, 548772, 812389, 17619841, 2508803],
  129. [MPUD0, 9865760, 548766, 759849, 16550439, 2508804],
  130. [MPUD1, 9865760, 548766, 759849, 17619876, 2508805],
  131. [MPUS2, 9865761, 548770, 759850, 17620135, 2508806],
  132. [MPUS3, 9865761, 548770, 759850, 17620136, 2508807],
  133. [MPUS4, 9865761, 548770, 759850, 17620138, 2508808],
  134. [MPUS6, 9865762, 548772, 759851, 17620139, 2508809],
  135. [MPUS8, 9865762, 548772, 759851, null, 2508810],
  136. [MPUS9, 9865763, 548774, 759852, null, 2508811],
  137. [MPUS11,9865787, 548776, 759853, null, 2508812],
  138. ];
  139.  
  140. const bidder = [];
  141. let configBidder;
  142.  
  143. if (windowWidth > maxLaptopBreakPoint) {
  144. configBidder = bidConfigDesktop;
  145. } else if (windowWidth >= tabletBreakPoint) {
  146. configBidder = bidConfigTablet;
  147. } else {
  148. configBidder = bidConfigMobile;
  149. }
  150.  
  151. configBidder.push([TEADSIB, 11775136, null, null, null, null]);
  152.  
  153. slots.filter(x => !!x).forEach((slot) => {
  154. const id = slot.getTargeting('tile')[0];
  155. const foundSlot = configBidder
  156. .find(([slotId]) => slotId === id);
  157.  
  158. if (foundSlot) {
  159. // TODO remove this when xaxis prebid is rolled out for everyone
  160. if(JPIM.domain !== 'doncasterfreepress.co.uk') {
  161. foundSlot[foundSlot.length - 1] = null;
  162. }
  163. bidder.push({
  164. code: id,
  165. sizes: slot.getSizes().map(size => size.length === 1 ? Object.values(size)[0] : Object.values(size)),
  166. bids: foundSlot
  167. .map((placementId, i) => {
  168. if (!placementId) return null;
  169. switch (i) {
  170. case 1:
  171. return appNexus(placementId, topSection, JPIM.pageType);
  172. case 2:
  173. return rubicon(rubiconSiteId, placementId, window.itag);
  174. case 3:
  175. return criteo(placementId);
  176. case 4:
  177. return gm(placementId);
  178. case 5:
  179. return pubmatic(placementId);
  180. default:
  181. return null;
  182. }
  183. })
  184. .filter(x => !!x),
  185. })
  186. }
  187. });
  188.  
  189. const pbjs = window.pbjs || {};
  190. pbjs.que = pbjs.que || [];
  191.  
  192. pbjs.bidderSettings = {
  193. 'standard': {
  194. 'adserverTargeting': [{
  195. 'key': 'hb_pb',
  196. 'val': function(bidResponse) {
  197. var cpm = getPriceBucket(bidResponse.cpm);
  198. return (typeof cpm === 'number') ? cpm.toFixed(2) : cpm;
  199. },
  200. }, {
  201. 'key': 'hb_adid',
  202. 'val': function(bidResponse) {
  203. return bidResponse.adId;
  204. },
  205. }, {
  206. 'key': 'hb_size',
  207. 'val': function(bidResponse) {
  208. return bidResponse.size;
  209. },
  210. }, {
  211. 'key': 'hb_bidder',
  212. 'val': function(bidResponse) {
  213. return bidResponse.bidder;
  214. },
  215. }, {
  216. 'key': 'hb_deal',
  217. 'val': function(bidResponse) {
  218. return bidResponse.dealId;
  219. },
  220. }],
  221. },
  222. 'rubicon': {
  223. 'adserverTargeting': [{
  224. 'key': 'hb_deal_rubicon',
  225. 'val': function(bidResponse) {
  226. return bidResponse.dealId || 0;
  227. },
  228. }],
  229. },
  230. 'gm': {
  231. bidCpmAdjustment : function(bidCpm){
  232. return bidCpm * 1.10;
  233. },
  234. },
  235. };
  236.  
  237. pbjs.que.push(function() {
  238. pbjs.addAdUnits(bidder);
  239. pbjs.aliasBidder('appnexus', 'gm');
  240. pbjs.requestBids({
  241. 'bidsBackHandler': sendAdserverRequest,
  242. });
  243. });
  244.  
  245. function sendAdserverRequest() {
  246. if (pbjs.adserverRequestSent) return;
  247. pbjs.adserverRequestSent = true;
  248.  
  249. googletag.cmd.push(function() {
  250. pbjs.que.push(function() {
  251. pbjs.setTargetingForGPTAsync();
  252. resolve();
  253. });
  254. });
  255.  
  256. pbjs.priceBuckets = pbjs.priceBuckets || {};
  257. pbjs._bidsReceived = pbjs._bidsReceived || [];
  258. for (var i = 0; i < pbjs._bidsReceived.length; i++) {
  259. var currentBidReceived = pbjs._bidsReceived[i];
  260. pbjs.priceBuckets[currentBidReceived.adUnitCode] = getPriceBucket(currentBidReceived.cpm);
  261. }
  262. }
  263.  
  264. setTimeout(function() {
  265. sendAdserverRequest();
  266. }, PREBID_TIMEOUT);
  267.  
  268. /* Adomik randomizer for ad call key value targeting */
  269. const Adomik = window.Adomik || {};
  270. Adomik.randomAdGroup = function() {
  271. var rand = Math.random();
  272. switch (false) {
  273. case !(rand < 0.09):
  274. return 'ad_ex' + (Math.floor(100 * rand));
  275. case !(rand < 0.10):
  276. return 'ad_bc';
  277. default:
  278. return 'ad_opt';
  279. }
  280. };
  281.  
  282. function convertNumberToPrice(number) {
  283. return parseFloat(number.toFixed(2));
  284. }
  285.  
  286. function getPriceBucket(price) {
  287. var increment = 0;
  288. price = convertNumberToPrice(price);
  289.  
  290. if (price < 0.25) {
  291. increment = 0;
  292. } else if (price < 2.10) {
  293. increment = 0.05;
  294. } else if (price < 5.00) {
  295. increment = 0.10;
  296. } else if (price < 8.50) {
  297. increment = 0.20;
  298. } else if (price < 15.00) {
  299. increment = 0.50;
  300. } else if (price >= 15.00) {
  301. return 15.00;
  302. }
  303.  
  304. if (increment === 0) {
  305. return price;
  306. } else {
  307. var remainder = Math.round((price % increment) * 100) / 100;
  308. return (remainder >= increment) ? price : convertNumberToPrice(price - remainder);
  309. }
  310. }
  311. }));
  312.  
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement