From d34c542ea551aa46131ccaf71004300ee226b02f Mon Sep 17 00:00:00 2001 From: BaronYu Date: Wed, 17 Aug 2022 20:58:10 +0800 Subject: [PATCH 01/10] Mediago Bid Adapter:new adapter --- modules/mediagoBidAdapter.js | 458 ++++++++++++++++++++ modules/mediagoBidAdapter.md | 34 ++ test/spec/modules/mediagoBidAdapter_spec.js | 89 ++++ 3 files changed, 581 insertions(+) create mode 100644 modules/mediagoBidAdapter.js create mode 100644 modules/mediagoBidAdapter.md create mode 100644 test/spec/modules/mediagoBidAdapter_spec.js diff --git a/modules/mediagoBidAdapter.js b/modules/mediagoBidAdapter.js new file mode 100644 index 00000000000..c6ab6d6b28a --- /dev/null +++ b/modules/mediagoBidAdapter.js @@ -0,0 +1,458 @@ +/** + * gulp serve --modules=mediagoBidAdapter,pubCommonId --nolint --notest + */ + +import * as utils from '../src/utils.js'; +import { getStorageManager } from '../src/storageManager.js'; +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { config } from '../src/config.js'; +// import { isPubcidEnabled } from './pubCommonId.js'; + +const BIDDER_CODE = 'mediago'; +// const PROTOCOL = window.document.location.protocol; +const ENDPOINT_URL = + // ((PROTOCOL === 'https:') ? 'https' : 'http') + + 'https://rtb-us.mediago.io/api/bid?tn='; +const TIME_TO_LIVE = 500; +// const ENDPOINT_URL = '/api/bid?tn='; +const storage = getStorageManager(); +let globals = {}; +let itemMaps = {}; + +/** + * 获取随机id + * @param {number} a random number from 0 to 15 + * @return {string} random number or random string + */ +function getRandomId( + a // placeholder +) { + // if the placeholder was passed, return + // a random number from 0 to 15 + return a + ? ( + a ^ // unless b is 8, + ((Math.random() * // in which case + 16) >> // a random number from + (a / 4)) + ) // 8 to 11 + .toString(16) // in hexadecimal + : ( // or otherwise a concatenated string: + [1e7] + // 10000000 + + 1e3 + // -1000 + + 4e3 + // -4000 + + 8e3 + // -80000000 + + 1e11 + ) // -100000000000, + .replace( + // replacing + /[018]/g, // zeroes, ones, and eights with + getRandomId // random hex digits + ); +} + +/* ----- mguid:start ------ */ +const COOKIE_KEY_MGUID = '__mguid_'; + +/** + * 获取用户id + * @return {string} + */ +const getUserID = () => { + const i = storage.getCookie(COOKIE_KEY_MGUID); + + if (i === null) { + const uuid = utils.generateUUID(); + storage.setCookie(COOKIE_KEY_MGUID, uuid); + return uuid; + } + return i; +}; + +/* ----- mguid:end ------ */ + +/** + * 获取一个对象的某个值,如果没有则返回空字符串 + * @param {Object} obj 对象 + * @param {...string} keys 键名 + * @return {any} + */ +function getProperty(obj, ...keys) { + let o = obj; + + for (let key of keys) { + // console.log(key, o); + if (o && o[key]) { + o = o[key]; + } else { + return ''; + } + } + return o; +} + +/** + * 是不是移动设备或者平板 + * @return {boolean} + */ +function isMobileAndTablet() { + let check = false; + (function (a) { + let reg1 = new RegExp( + [ + '(android|bbd+|meego)', + '.+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)', + '|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone', + '|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap', + '|windows ce|xda|xiino|android|ipad|playbook|silk', + ].join(''), + 'i' + ); + let reg2 = new RegExp( + [ + '1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)', + '|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )', + '|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell', + '|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)', + '|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene', + '|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c', + '|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom', + '|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)', + '|le(no|xi)|lg( g|/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)', + '|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]', + '|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)', + '|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio', + '|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms', + '|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al', + '|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)', + '|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|', + 'v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)', + '|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-', + '|your|zeto|zte-', + ].join(''), + 'i' + ); + if (reg1.test(a) || reg2.test(a.substr(0, 4))) { + check = true; + } + })(navigator.userAgent || navigator.vendor || window.opera); + return check; +} + +/** + * 获取底价 + * @param {*} bid + * @param {*} mediaType + * @param {*} sizes + * @returns + */ +// function getBidFloor(bid, mediaType, sizes) { +// var floor; +// var size = sizes.length === 1 ? sizes[0] : "*"; +// if (typeof bid.getFloor === "function") { +// const floorInfo = bid.getFloor({ currency: "USD", mediaType, size }); +// if ( +// typeof floorInfo === "object" && +// floorInfo.currency === "USD" && +// !isNaN(parseFloat(floorInfo.floor)) +// ) { +// floor = parseFloat(floorInfo.floor); +// } +// } +// return floor; +// } +function getBidFloor(bid) { + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); + } + + try { + const bidFloor = bid.getFloor({ + currency: 'USD', + mediaType: '*', + size: '*', + }); + return bidFloor.floor; + } catch (_) { + return 0; + } +} + +/** + * 将尺寸转为RTB识别的尺寸 + * + * @param {Array|Object} requestSizes 配置尺寸 + * @return {Object} + */ +function transformSizes(requestSizes) { + let sizes = []; + let sizeObj = {}; + + if ( + utils.isArray(requestSizes) && + requestSizes.length === 2 && + !utils.isArray(requestSizes[0]) + ) { + sizeObj.width = parseInt(requestSizes[0], 10); + sizeObj.height = parseInt(requestSizes[1], 10); + sizes.push(sizeObj); + } else if (typeof requestSizes === 'object') { + for (let i = 0; i < requestSizes.length; i++) { + let size = requestSizes[i]; + sizeObj = {}; + sizeObj.width = parseInt(size[0], 10); + sizeObj.height = parseInt(size[1], 10); + sizes.push(sizeObj); + } + } + + return sizes; +} + +// 支持的广告尺寸 +const mediagoAdSize = [ + { w: 300, h: 250 }, + { w: 300, h: 600 }, + { w: 728, h: 90 }, + { w: 970, h: 250 }, + { w: 320, h: 50 }, + { w: 160, h: 600 }, + { w: 320, h: 180 }, + { w: 320, h: 100 }, + { w: 336, h: 280 }, +]; + +/** + * 获取广告位配置 + * @param {Array} validBidRequests an an array of bids + * @param {Object} bidderRequest The master bidRequest object + * @return {Object} + */ +function getItems(validBidRequests, bidderRequest) { + let items = []; + items = validBidRequests.map((req, i) => { + let ret = {}; + let mediaTypes = getProperty(req, 'mediaTypes'); + + let sizes = transformSizes(getProperty(req, 'sizes')); + let matchSize; + + // 确认尺寸是否符合我们要求 + for (let size of sizes) { + matchSize = mediagoAdSize.find( + (item) => size.width === item.w && size.height === item.h + ); + if (matchSize) { + break; + } + } + if (!matchSize) { + return {}; + } + + const bidFloor = getBidFloor(req); + // const gpid = + // utils.deepAccess(req, 'ortb2Imp.ext.gpid') || + // utils.deepAccess(req, 'ortb2Imp.ext.data.pbadslot') || + // utils.deepAccess(req, 'params.placementId', 0); + // console.log("wjh getItems:", req, bidFloor, gpid); + + // if (mediaTypes.native) {} + // banner广告类型 + if (mediaTypes.banner) { + let id = '' + (i + 1); + ret = { + id: id, + bidfloor: bidFloor, + banner: { + h: matchSize.h, + w: matchSize.w, + pos: 1, + }, + ext: { + // gpid: gpid, // 加入后无法返回广告 + }, + }; + itemMaps[id] = { + req, + ret, + }; + } + + return ret; + }); + return items; +} + +/** + * 获取rtb请求参数 + * + * @param {Array} validBidRequests an an array of bids + * @param {Object} bidderRequest The master bidRequest object + * @return {Object} + */ +function getParam(validBidRequests, bidderRequest) { + const pubcid = utils.deepAccess(validBidRequests[0], 'crumbs.pubcid'); + // console.log('wjh getParam', validBidRequests, bidderRequest); + let isMobile = isMobileAndTablet() ? 1 : 0; + let isTest = 0; + let auctionId = getProperty(bidderRequest, 'auctionId') || getRandomId(); + let items = getItems(validBidRequests, bidderRequest); + + const domain = document.domain; + const location = utils.deepAccess(bidderRequest, 'refererInfo.referer'); + + const timeout = bidderRequest.timeout || 2000; + + if (items && items.length) { + let c = { + id: 'mgprebidjs_' + auctionId, + test: +isTest, + at: 1, + cur: ['USD'], + device: { + connectiontype: 0, + // ip: '64.188.178.115', + js: 1, + // language: "en", + // os: "Microsoft Windows", + // ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19043", + os: navigator.platform || '', + ua: navigator.userAgent, + language: /en/.test(navigator.language) ? 'en' : navigator.language, + }, + ext: {}, + user: { + buyeruid: getUserID(), + id: pubcid, + }, + site: { + name: domain, + domain: domain, + page: location, + ref: location, + mobile: isMobile, + cat: [], // todo + publisher: { + // todo + id: domain, + name: domain, + }, + }, + imp: items, + tmax: timeout, + }; + return c; + } else { + return null; + } +} + +export const spec = { + code: BIDDER_CODE, + // aliases: ['ex'], // short code + /** + * Determines whether or not the given bid request is valid. + * + * @param {BidRequest} bid The bid params to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: function (bid) { + // console.log('mediago', { + // bid + // }); + if (bid.params.token) { + globals['token'] = bid.params.token; + } + return !!bid.params.token; + }, + + /** + * Make a server request from the list of BidRequests. + * + * @param {Array} validBidRequests an an array of bids + * @param {Object} bidderRequest The master bidRequest object + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: function (validBidRequests, bidderRequest) { + let payload = getParam(validBidRequests, bidderRequest); + + const payloadString = JSON.stringify(payload); + return { + method: 'POST', + url: ENDPOINT_URL + globals['token'], + data: payloadString, + }; + }, + + /** + * Unpack the response from the server into a list of bids. + * + * @param {ServerResponse} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: function (serverResponse, bidRequest) { + const bids = getProperty(serverResponse, 'body', 'seatbid', 0, 'bid'); + const cur = getProperty(serverResponse, 'body', 'cur'); + + const bidResponses = []; + for (let bid of bids) { + let impid = getProperty(bid, 'impid'); + if (itemMaps[impid]) { + let bidId = getProperty(itemMaps[impid], 'req', 'bidId'); + const bidResponse = { + requestId: bidId, + cpm: getProperty(bid, 'price'), + width: getProperty(bid, 'w'), + height: getProperty(bid, 'h'), + creativeId: getProperty(bid, 'crid'), + dealId: '', + currency: cur, + netRevenue: true, + ttl: TIME_TO_LIVE, + // referrer: REFERER, + ad: getProperty(bid, 'adm'), + // adserverTargeting: { + // granularityMultiplier: 0.1, + // priceGranularity: "pbHg", + // pbMg: "0.01", + // }, + // pbMg: "0.01", + // granularityMultiplier: 0.1, + // priceGranularity: "pbHg", + }; + bidResponses.push(bidResponse); + } + } + + return bidResponses; + }, + + /** + * Register bidder specific code, which will execute if bidder timed out after an auction + * @param {data} Containing timeout specific data + */ + onTimeout: function (data) { + // console.log('onTimeout', data); + // Bidder specifc code + }, + + /** + * Register bidder specific code, which will execute if a bid from this bidder won the auction + * @param {Bid} The bid that won the auction + */ + onBidWon: function (bid) { + console.log('onBidWon', bid, config.getConfig('priceGranularity')); + // Bidder specific code + }, + + /** + * Register bidder specific code, which will execute when the adserver targeting has been set for a bid from this bidder + * @param {Bid} The bid of which the targeting has been set + */ + onSetTargeting: function (bid) { + // console.log('onSetTargeting', bid); + // Bidder specific code + }, +}; +registerBidder(spec); diff --git a/modules/mediagoBidAdapter.md b/modules/mediagoBidAdapter.md new file mode 100644 index 00000000000..464ea59f11c --- /dev/null +++ b/modules/mediagoBidAdapter.md @@ -0,0 +1,34 @@ +# Overview + +``` +Module Name: MediaGo Bidder Adapter +Module Type: Bidder Adapter +Maintainer: fangsimin@baidu.com +``` + +# Description + +Module that connects to MediaGo's demand sources + +# Test Parameters + +``` + var adUnits = [ + { + code: 'test-div', + mediaTypes: { + banner: { + sizes: [[300, 250]], + } + }, + bids: [ + { + bidder: "mediago", + params: { + token: '' // required, send email to ext_mediago_am@baidu.com to get the corresponding token + } + } + ] + } + ]; +``` diff --git a/test/spec/modules/mediagoBidAdapter_spec.js b/test/spec/modules/mediagoBidAdapter_spec.js new file mode 100644 index 00000000000..c6cb236c1af --- /dev/null +++ b/test/spec/modules/mediagoBidAdapter_spec.js @@ -0,0 +1,89 @@ +import { expect } from 'chai'; +import { spec } from 'modules/mediagoBidAdapter.js'; + +describe('mediago:BidAdapterTests', function () { + let bidRequestData = { + bidderCode: 'mediago', + auctionId: '7fae02a9-0195-472f-ba94-708d3bc2c0d9', + bidderRequestId: '4fec04e87ad785', + bids: [ + { + bidder: 'mediago', + params: { + token: '85a6b01e41ac36d49744fad726e3655d', + }, + mediaTypes: { + banner: { + sizes: [[300, 250]], + }, + }, + adUnitCode: 'div-gpt-ad-1460505748561-0', + transactionId: '5e24a2ce-db03-4565-a8a3-75dbddca9377', + sizes: [[300, 250]], + bidId: '54d73f19c9d47a', + bidderRequestId: '4fec04e87ad785', + auctionId: '7fae02a9-0195-472f-ba94-708d3bc2c0d9', + src: 'client', + bidRequestsCount: 1, + bidderRequestsCount: 1, + bidderWinsCount: 0, + }, + ], + }; + let request = []; + + it('mediago:validate_pub_params', function () { + expect( + spec.isBidRequestValid({ + bidder: 'mediago', + params: { + token: ['85a6b01e41ac36d49744fad726e3655d'], + }, + }) + ).to.equal(true); + }); + + it('mediago:validate_generated_params', function () { + request = spec.buildRequests(bidRequestData.bids, bidRequestData); + let req_data = JSON.parse(request.data); + expect(req_data.imp).to.have.lengthOf(1); + }); + + it('mediago:validate_response_params', function () { + let serverResponse = { + body: { + id: 'mgprebidjs_0b6572fc-ceba-418f-b6fd-33b41ad0ac8a', + seatbid: [ + { + bid: [ + { + id: '6706352e29016b27da84dd422e879369', + impid: '1', + price: 0.2, + adm: "\u003clink rel='stylesheet' href='//cdn.mediago.io/js/style/style_banner_300*250.css'\u003e\u003cdiv id='mgcontainer-50a1cceed7dcd3c99859e20a1d0a66ae' class='mediago-placement imgTopTitleBottom' style='position:relative;width:298px;height:248px;overflow:hidden'\u003e\u003ca href='http://msn.gbudev.com/api/bidder/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=ZQc-I4Br8_FTGtNXgAwbVteddoPtwJDcZdJPhEKrZQ8\u0026evt=102\u0026rid=6706352e29016b27da84dd422e879369\u0026campaignid=1001465\u0026impid=27-300x175-1\u0026offerid=1023545\u0026test=0\u0026time=1597646714\u0026cp=65zLqtxPkYHaZbMC9f8kvas6S6nFO8mGkTyb5LFppSc\u0026clickid=27_6706352e29016b27da84dd422e879369_27-300x175-1\u0026acid=1\u0026trackingid=50a1cceed7dcd3c99859e20a1d0a66ae\u0026uid=6dda6c6b70eb4e2d9ab3469d921f2c74\u0026jt=2\u0026url=vMENpLl3Ssfi5PyFJaLiifsd8Gd5IVxcoii1evTTiL5C3PvP27nLeCEESzIf4noyPKskwHpQIoejGPD5J0SEX6SPP55F94l7jcVPT_1vRxu2Zk43M8P4njPyzaXmASSVamprYOurCP3cCZzNOc-fSg' target='_blank'\u003e\u003cimg alt='platform_mobile_test' src='https://d2cli4kgl5uxre.cloudfront.net/ML/3f21c1cc11eb691b6c3d99f7a1daf815__300x175.png' style='height:70%;width:100%;border-width:0;border:none;'\u003e\u003ch3 class='title' style='font-size:16px;'\u003eplatform_mobile_test\u003c/h3\u003e\u003c/a\u003e\u003cspan class='source'\u003e\u003ca class='sourcename' href='//www.mediago.io' target='_blank'\u003e\u003cspan\u003eAd\u003c/span\u003e \u003c/a\u003e\u003ca class='srcnameadslabelurl' href='//www.mediago.io/privacy' target='_blank'\u003e\u003cspan\u003eAce\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/div\u003e\u003cscript\u003e!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){'undefined'!=typeof Symbol\u0026\u0026Symbol.toStringTag\u0026\u0026Object.defineProperty(e,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(e,'__esModule',{value:!0})},n.t=function(e,t){if(1\u0026t\u0026\u0026(e=n(e)),8\u0026t)return e;if(4\u0026t\u0026\u0026'object'==typeof e\u0026\u0026e\u0026\u0026e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,'default',{enumerable:!0,value:e}),2\u0026t\u0026\u0026'string'!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e\u0026\u0026e.__esModule?function(){return e.default}:function(){return e};return n.d(t,'a',t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p='',n(n.s=24)}({24:function(e,t,n){'use strict';function o(e){var t=new Image;t.src=e,t.style='display:none;visibility:hidden',t.width=0,t.height=0,document.body.appendChild(t)}o('http://msn.gbudev.com/api/bidder/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=ZQc-I4Br8_FTGtNXgAwbVteddoPtwJDcZdJPhEKrZQ8\u0026evt=101\u0026rid=6706352e29016b27da84dd422e879369\u0026campaignid=1001465\u0026impid=27-300x175-1\u0026offerid=1023545\u0026test=0\u0026time=1597646714\u0026cp=65zLqtxPkYHaZbMC9f8kvas6S6nFO8mGkTyb5LFppSc\u0026acid=1\u0026trackingid=50a1cceed7dcd3c99859e20a1d0a66ae\u0026uid=6dda6c6b70eb4e2d9ab3469d921f2c74');var r=document.getElementById('mgcontainer-50a1cceed7dcd3c99859e20a1d0a66ae'),i=!1;!function e(){setTimeout((function(){var t,n;!i\u0026\u0026(t=r,n=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,(t.getBoundingClientRect()\u0026\u0026t.getBoundingClientRect().top)\u003c=n-.75*(t.offsetHeight||t.clientHeight))?(i=!0,o('http://msn.gbudev.com/api/bidder/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=ZQc-I4Br8_FTGtNXgAwbVteddoPtwJDcZdJPhEKrZQ8\u0026evt=104\u0026rid=6706352e29016b27da84dd422e879369\u0026campaignid=1001465\u0026impid=27-300x175-1\u0026offerid=1023545\u0026test=0\u0026time=1597646714\u0026cp=65zLqtxPkYHaZbMC9f8kvas6S6nFO8mGkTyb5LFppSc\u0026acid=1\u0026trackingid=50a1cceed7dcd3c99859e20a1d0a66ae\u0026uid=6dda6c6b70eb4e2d9ab3469d921f2c74\u0026sid=4__11__12__13\u0026format=\u0026crid=3f21c1cc11eb691b6c3d99f7a1daf815')):e()}),500)}()}});\u003c/script\u003e\u003cscript type='text/javascript' src='http://msn.gbudev.com/api/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=${AUCTION_PRICE}\u0026evt=5\u0026rid=6706352e29016b27da84dd422e879369\u0026impid=1\u0026offerid=\u0026tagid=\u0026test=0\u0026time=1597646714\u0026adp=g3tznPzjr9gfd3aQ0Sio53Dk4_QZkg1XuEWXR_Gw-CY\u0026dsp_id=23\u0026cp=${cp}\u0026url=\u0026type=script'\u003e\u003c/script\u003e\u003cscript\u003edocument.addEventListener\u0026\u0026document.addEventListener('click',function(){var a=document.createElement('script');a.src='http://msn.gbudev.com/api/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=${AUCTION_PRICE}\u0026evt=6\u0026rid=6706352e29016b27da84dd422e879369\u0026impid=1\u0026offerid=\u0026tagid=\u0026test=0\u0026time=1597646714\u0026adp=g3tznPzjr9gfd3aQ0Sio53Dk4_QZkg1XuEWXR_Gw-CY\u0026dsp_id=23\u0026cp=${cp}\u0026url=\u0026clickid=27_6706352e29016b27da84dd422e879369_1';document.body.appendChild(a)});\u003c/script\u003e", + cid: '1001465', + crid: '3f21c1cc11eb691b6c3d99f7a1daf815', + w: 300, + h: 250, + }, + ], + }, + ], + cur: 'USD', + }, + }; + + let bids = spec.interpretResponse(serverResponse); + // console.log({ + // bids + // }); + expect(bids).to.have.lengthOf(1); + + let bid = bids[0]; + + expect(bid.creativeId).to.equal('3f21c1cc11eb691b6c3d99f7a1daf815'); + expect(bid.width).to.equal(300); + expect(bid.height).to.equal(250); + expect(bid.currency).to.equal('USD'); + }); +}); From dfea76667b702326a854aae1f90519ebcaf478a5 Mon Sep 17 00:00:00 2001 From: BaronYu Date: Thu, 18 Aug 2022 10:00:05 +0800 Subject: [PATCH 02/10] remove console --- modules/mediagoBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/mediagoBidAdapter.js b/modules/mediagoBidAdapter.js index c6ab6d6b28a..d038378a1f7 100644 --- a/modules/mediagoBidAdapter.js +++ b/modules/mediagoBidAdapter.js @@ -5,7 +5,7 @@ import * as utils from '../src/utils.js'; import { getStorageManager } from '../src/storageManager.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { config } from '../src/config.js'; +// import { config } from '../src/config.js'; // import { isPubcidEnabled } from './pubCommonId.js'; const BIDDER_CODE = 'mediago'; @@ -442,7 +442,7 @@ export const spec = { * @param {Bid} The bid that won the auction */ onBidWon: function (bid) { - console.log('onBidWon', bid, config.getConfig('priceGranularity')); + // console.log('onBidWon', bid, config.getConfig('priceGranularity')); // Bidder specific code }, From ba97c8ac59436ec32a68adddbc82df5edf8c56a1 Mon Sep 17 00:00:00 2001 From: BaronYu Date: Thu, 18 Aug 2022 11:14:29 +0800 Subject: [PATCH 03/10] change spec file to fix CircleCI --- test/spec/modules/mediagoBidAdapter_spec.js | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/spec/modules/mediagoBidAdapter_spec.js b/test/spec/modules/mediagoBidAdapter_spec.js index c6cb236c1af..2ce04ceb801 100644 --- a/test/spec/modules/mediagoBidAdapter_spec.js +++ b/test/spec/modules/mediagoBidAdapter_spec.js @@ -11,18 +11,19 @@ describe('mediago:BidAdapterTests', function () { bidder: 'mediago', params: { token: '85a6b01e41ac36d49744fad726e3655d', + bidfloor: 0.01, }, mediaTypes: { banner: { sizes: [[300, 250]], }, }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '5e24a2ce-db03-4565-a8a3-75dbddca9377', + adUnitCode: 'regular_iframe', + transactionId: '7b26fdae-96e6-4c35-a18b-218dda11397d', sizes: [[300, 250]], - bidId: '54d73f19c9d47a', - bidderRequestId: '4fec04e87ad785', - auctionId: '7fae02a9-0195-472f-ba94-708d3bc2c0d9', + bidId: '54d73f19c9d47a', // todo + bidderRequestId: '4fec04e87ad785', // todo + auctionId: '883a346a-6d62-4adb-a600-0f3a869061d1', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, @@ -57,12 +58,12 @@ describe('mediago:BidAdapterTests', function () { { bid: [ { - id: '6706352e29016b27da84dd422e879369', + id: '6e28cfaf115a354ea1ad8e1304d6d7b8', impid: '1', - price: 0.2, - adm: "\u003clink rel='stylesheet' href='//cdn.mediago.io/js/style/style_banner_300*250.css'\u003e\u003cdiv id='mgcontainer-50a1cceed7dcd3c99859e20a1d0a66ae' class='mediago-placement imgTopTitleBottom' style='position:relative;width:298px;height:248px;overflow:hidden'\u003e\u003ca href='http://msn.gbudev.com/api/bidder/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=ZQc-I4Br8_FTGtNXgAwbVteddoPtwJDcZdJPhEKrZQ8\u0026evt=102\u0026rid=6706352e29016b27da84dd422e879369\u0026campaignid=1001465\u0026impid=27-300x175-1\u0026offerid=1023545\u0026test=0\u0026time=1597646714\u0026cp=65zLqtxPkYHaZbMC9f8kvas6S6nFO8mGkTyb5LFppSc\u0026clickid=27_6706352e29016b27da84dd422e879369_27-300x175-1\u0026acid=1\u0026trackingid=50a1cceed7dcd3c99859e20a1d0a66ae\u0026uid=6dda6c6b70eb4e2d9ab3469d921f2c74\u0026jt=2\u0026url=vMENpLl3Ssfi5PyFJaLiifsd8Gd5IVxcoii1evTTiL5C3PvP27nLeCEESzIf4noyPKskwHpQIoejGPD5J0SEX6SPP55F94l7jcVPT_1vRxu2Zk43M8P4njPyzaXmASSVamprYOurCP3cCZzNOc-fSg' target='_blank'\u003e\u003cimg alt='platform_mobile_test' src='https://d2cli4kgl5uxre.cloudfront.net/ML/3f21c1cc11eb691b6c3d99f7a1daf815__300x175.png' style='height:70%;width:100%;border-width:0;border:none;'\u003e\u003ch3 class='title' style='font-size:16px;'\u003eplatform_mobile_test\u003c/h3\u003e\u003c/a\u003e\u003cspan class='source'\u003e\u003ca class='sourcename' href='//www.mediago.io' target='_blank'\u003e\u003cspan\u003eAd\u003c/span\u003e \u003c/a\u003e\u003ca class='srcnameadslabelurl' href='//www.mediago.io/privacy' target='_blank'\u003e\u003cspan\u003eAce\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/div\u003e\u003cscript\u003e!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){'undefined'!=typeof Symbol\u0026\u0026Symbol.toStringTag\u0026\u0026Object.defineProperty(e,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(e,'__esModule',{value:!0})},n.t=function(e,t){if(1\u0026t\u0026\u0026(e=n(e)),8\u0026t)return e;if(4\u0026t\u0026\u0026'object'==typeof e\u0026\u0026e\u0026\u0026e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,'default',{enumerable:!0,value:e}),2\u0026t\u0026\u0026'string'!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e\u0026\u0026e.__esModule?function(){return e.default}:function(){return e};return n.d(t,'a',t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p='',n(n.s=24)}({24:function(e,t,n){'use strict';function o(e){var t=new Image;t.src=e,t.style='display:none;visibility:hidden',t.width=0,t.height=0,document.body.appendChild(t)}o('http://msn.gbudev.com/api/bidder/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=ZQc-I4Br8_FTGtNXgAwbVteddoPtwJDcZdJPhEKrZQ8\u0026evt=101\u0026rid=6706352e29016b27da84dd422e879369\u0026campaignid=1001465\u0026impid=27-300x175-1\u0026offerid=1023545\u0026test=0\u0026time=1597646714\u0026cp=65zLqtxPkYHaZbMC9f8kvas6S6nFO8mGkTyb5LFppSc\u0026acid=1\u0026trackingid=50a1cceed7dcd3c99859e20a1d0a66ae\u0026uid=6dda6c6b70eb4e2d9ab3469d921f2c74');var r=document.getElementById('mgcontainer-50a1cceed7dcd3c99859e20a1d0a66ae'),i=!1;!function e(){setTimeout((function(){var t,n;!i\u0026\u0026(t=r,n=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,(t.getBoundingClientRect()\u0026\u0026t.getBoundingClientRect().top)\u003c=n-.75*(t.offsetHeight||t.clientHeight))?(i=!0,o('http://msn.gbudev.com/api/bidder/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=ZQc-I4Br8_FTGtNXgAwbVteddoPtwJDcZdJPhEKrZQ8\u0026evt=104\u0026rid=6706352e29016b27da84dd422e879369\u0026campaignid=1001465\u0026impid=27-300x175-1\u0026offerid=1023545\u0026test=0\u0026time=1597646714\u0026cp=65zLqtxPkYHaZbMC9f8kvas6S6nFO8mGkTyb5LFppSc\u0026acid=1\u0026trackingid=50a1cceed7dcd3c99859e20a1d0a66ae\u0026uid=6dda6c6b70eb4e2d9ab3469d921f2c74\u0026sid=4__11__12__13\u0026format=\u0026crid=3f21c1cc11eb691b6c3d99f7a1daf815')):e()}),500)}()}});\u003c/script\u003e\u003cscript type='text/javascript' src='http://msn.gbudev.com/api/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=${AUCTION_PRICE}\u0026evt=5\u0026rid=6706352e29016b27da84dd422e879369\u0026impid=1\u0026offerid=\u0026tagid=\u0026test=0\u0026time=1597646714\u0026adp=g3tznPzjr9gfd3aQ0Sio53Dk4_QZkg1XuEWXR_Gw-CY\u0026dsp_id=23\u0026cp=${cp}\u0026url=\u0026type=script'\u003e\u003c/script\u003e\u003cscript\u003edocument.addEventListener\u0026\u0026document.addEventListener('click',function(){var a=document.createElement('script');a.src='http://msn.gbudev.com/api/track?tn=85a6b01e41ac36d49744fad726e3655d\u0026price=${AUCTION_PRICE}\u0026evt=6\u0026rid=6706352e29016b27da84dd422e879369\u0026impid=1\u0026offerid=\u0026tagid=\u0026test=0\u0026time=1597646714\u0026adp=g3tznPzjr9gfd3aQ0Sio53Dk4_QZkg1XuEWXR_Gw-CY\u0026dsp_id=23\u0026cp=${cp}\u0026url=\u0026clickid=27_6706352e29016b27da84dd422e879369_1';document.body.appendChild(a)});\u003c/script\u003e", - cid: '1001465', - crid: '3f21c1cc11eb691b6c3d99f7a1daf815', + price: 0.087581, + adm: "", + cid: '1339145', + crid: 'ff32b6f9b3bbc45c00b78b6674a2952e', w: 300, h: 250, }, @@ -81,7 +82,7 @@ describe('mediago:BidAdapterTests', function () { let bid = bids[0]; - expect(bid.creativeId).to.equal('3f21c1cc11eb691b6c3d99f7a1daf815'); + expect(bid.creativeId).to.equal('ff32b6f9b3bbc45c00b78b6674a2952e'); expect(bid.width).to.equal(300); expect(bid.height).to.equal(250); expect(bid.currency).to.equal('USD'); From d96c1fc445a02c308d90ef12876c78f2c6d26496 Mon Sep 17 00:00:00 2001 From: BaronYu Date: Thu, 18 Aug 2022 19:34:37 +0800 Subject: [PATCH 04/10] change spec file to fix CircleCI --- test/spec/modules/mediagoBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/mediagoBidAdapter_spec.js b/test/spec/modules/mediagoBidAdapter_spec.js index 2ce04ceb801..e55e27d4be7 100644 --- a/test/spec/modules/mediagoBidAdapter_spec.js +++ b/test/spec/modules/mediagoBidAdapter_spec.js @@ -61,7 +61,7 @@ describe('mediago:BidAdapterTests', function () { id: '6e28cfaf115a354ea1ad8e1304d6d7b8', impid: '1', price: 0.087581, - adm: "", + adm: "", cid: '1339145', crid: 'ff32b6f9b3bbc45c00b78b6674a2952e', w: 300, From 66bf6a09eeccc38d6ba301a171bf68fef9e04a28 Mon Sep 17 00:00:00 2001 From: BaronYu Date: Thu, 18 Aug 2022 20:37:17 +0800 Subject: [PATCH 05/10] change spec file --- test/spec/modules/mediagoBidAdapter_spec.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/mediagoBidAdapter_spec.js b/test/spec/modules/mediagoBidAdapter_spec.js index e55e27d4be7..e77af544429 100644 --- a/test/spec/modules/mediagoBidAdapter_spec.js +++ b/test/spec/modules/mediagoBidAdapter_spec.js @@ -11,7 +11,7 @@ describe('mediago:BidAdapterTests', function () { bidder: 'mediago', params: { token: '85a6b01e41ac36d49744fad726e3655d', - bidfloor: 0.01, + bidfloor: 0.01, }, mediaTypes: { banner: { @@ -51,6 +51,13 @@ describe('mediago:BidAdapterTests', function () { }); it('mediago:validate_response_params', function () { + let adm = ""; + let temp = '%3Cscr'; + temp += 'ipt%3E'; + temp += '!function()%7B%22use%20strict%22%3Bfunction%20f(t)%7Breturn(f%3D%22function%22%3D%3Dtypeof%20Symbol%26%26%22symbol%22%3D%3Dtypeof%20Symbol.iterator%3Ffunction(t)%7Breturn%20typeof%20t%7D%3Afunction(t)%7Breturn%20t%26%26%22function%22%3D%3Dtypeof%20Symbol%26%26t.constructor%3D%3D%3DSymbol%26%26t!%3D%3DSymbol.prototype%3F%22symbol%22%3Atypeof%20t%7D)(t)%7Dfunction%20l(t)%7Bvar%20e%3D0%3Carguments.length%26%26void%200!%3D%3Dt%3Ft%3A%7B%7D%3Btry%7Be.random_t%3D(new%20Date).getTime()%2Cg(function(t)%7Bvar%20e%3D1%3Carguments.length%26%26void%200!%3D%3Darguments%5B1%5D%3Farguments%5B1%5D%3A%22%22%3Bif(%22object%22!%3D%3Df(t))return%20e%3Bvar%20n%3Dfunction(t)%7Bfor(var%20e%2Cn%3D%5B%5D%2Co%3D0%2Ci%3DObject.keys(t)%3Bo%3Ci.length%3Bo%2B%2B)e%3Di%5Bo%5D%2Cn.push(%22%22.concat(e%2C%22%3D%22).concat(t%5Be%5D))%3Breturn%20n%7D(t).join(%22%26%22)%2Co%3De.indexOf(%22%23%22)%2Ci%3De%2Ct%3D%22%22%3Breturn-1!%3D%3Do%26%26(i%3De.slice(0%2Co)%2Ct%3De.slice(o))%2Cn%26%26(i%26%26-1!%3D%3Di.indexOf(%22%3F%22)%3Fi%2B%3D%22%26%22%2Bn%3Ai%2B%3D%22%3F%22%2Bn)%2Ci%2Bt%7D(e%2C%22https%3A%2F%2Ftrace.mediago.io%2Fapi%2Flog%2Ftrack%22))%7Dcatch(t)%7B%7D%7Dfunction%20g(t%2Ce%2Cn)%7B(t%3Dt%3Ft.split(%22%3B%3B%3B%22)%3A%5B%5D).map(function(t)%7Btry%7B0%3C%3Dt.indexOf(%22%2Fapi%2Fbidder%2Ftrack%22)%26%26n%26%26(t%2B%3D%22%26inIframe%3D%22.concat(!(!self.frameElement%7C%7C%22IFRAME%22!%3Dself.frameElement.tagName)%7C%7Cwindow.frames.length!%3Dparent.frames.length%7C%7Cself!%3Dtop)%2Ct%2B%3D%22%26pos_x%3D%22.concat(n.left%2C%22%26pos_y%3D%22).concat(n.top%2C%22%26page_w%3D%22).concat(n.page_width%2C%22%26page_h%3D%22).concat(n.page_height))%7Dcatch(t)%7Bl(%7Btn%3As%2Cwinloss%3A1%2Cfe%3A2%2Cpos_err_c%3A1002%2Cpos_err_m%3At.toString()%7D)%7Dvar%20e%3Dnew%20Image%3Be.src%3Dt%2Ce.style.display%3D%22none%22%2Ce.style.visibility%3D%22hidden%22%2Ce.width%3D0%2Ce.height%3D0%2Cdocument.body.appendChild(e)%7D)%7Dvar%20d%3D%5B%22https%3A%2F%2Ftrace.mediago.io%2Fapi%2Fbidder%2Ftrack%3Ftn%3D39934c2bda4debbe4c680be1dd02f5d3%26price%3DdjUJcggeuWWfbm28q4WXHdgMFkO28DrGw49FnubQ0Bk%26evt%3D101%26rid%3D6e28cfaf115a354ea1ad8e1304d6d7b8%26campaignid%3D1339145%26impid%3D44-300x250-1%26offerid%3D24054386%26test%3D0%26time%3D1660789795%26cp%3DjZDh1xu6_QqJLlKVtCkiHIP_TER6gL9jeTrlHCBoxOM%26acid%3D599%26trackingid%3D99afea272c2b0e8626489674ddb7a0bb%26uid%3Da865b9ae-fa9e-4c09-8204-2db99ac7c8f7%26bm%3D2%26la%3Den%26cn%3Dus%26cid%3D3998296%26info%3DSi3oM-qfCbw2iZRYs01BkUWyH6c5CQWHrA8CQLE0VHcXAcf4ljY9dyLzQ4vAlTWd6-j_ou4ySor3e70Ll7wlKiiauQKaUkZqNoTizHm73C4FK8DYJSTP3VkhJV8RzrYk%26sid%3D128__110__1__12__28__38__163__96__58__24__47__99%26sp%3DdjUJcggeuWWfbm28q4WXHdgMFkO28DrGw49FnubQ0Bk%26scp%3DzK0DRYY1UV-syqSpmcMYBpOebtoQJV9ZEJT0JFqbTQg%26acu%3DUSD%26scu%3DUSD%26sgcp%3DzK0DRYY1UV-syqSpmcMYBpOebtoQJV9ZEJT0JFqbTQg%26gprice%3DdjUJcggeuWWfbm28q4WXHdgMFkO28DrGw49FnubQ0Bk%26gcp%3DzK0DRYY1UV-syqSpmcMYBpOebtoQJV9ZEJT0JFqbTQg%26ah%3D%26de%3Dwjh.popin.cc%26iv%3D0%22%2C%22%24%7BITRACKER2%7D%22%2C%22%24%7BITRACKER3%7D%22%2C%22%24%7BITRACKER4%7D%22%2C%22%24%7BITRACKER5%7D%22%2C%22%24%7BITRACKER6%7D%22%5D%2Cp%3D%5B%22https%3A%2F%2Ftrace.mediago.io%2Fapi%2Fbidder%2Ftrack%3Ftn%3D39934c2bda4debbe4c680be1dd02f5d3%26price%3DdjUJcggeuWWfbm28q4WXHdgMFkO28DrGw49FnubQ0Bk%26evt%3D104%26rid%3D6e28cfaf115a354ea1ad8e1304d6d7b8%26campaignid%3D1339145%26impid%3D44-300x250-1%26offerid%3D24054386%26test%3D0%26time%3D1660789795%26cp%3DjZDh1xu6_QqJLlKVtCkiHIP_TER6gL9jeTrlHCBoxOM%26acid%3D599%26trackingid%3D99afea272c2b0e8626489674ddb7a0bb%26uid%3Da865b9ae-fa9e-4c09-8204-2db99ac7c8f7%26sid%3D128__110__1__12__28__38__163__96__58__24__47__99%26format%3D%26crid%3Dff32b6f9b3bbc45c00b78b6674a2952e%26bm%3D2%26la%3Den%26cn%3Dus%26cid%3D3998296%26info%3DSi3oM-qfCbw2iZRYs01BkUWyH6c5CQWHrA8CQLE0VHcXAcf4ljY9dyLzQ4vAlTWd6-j_ou4ySor3e70Ll7wlKiiauQKaUkZqNoTizHm73C4FK8DYJSTP3VkhJV8RzrYk%26sp%3DdjUJcggeuWWfbm28q4WXHdgMFkO28DrGw49FnubQ0Bk%26scp%3DzK0DRYY1UV-syqSpmcMYBpOebtoQJV9ZEJT0JFqbTQg%26acu%3DUSD%26scu%3DUSD%26sgcp%3DzK0DRYY1UV-syqSpmcMYBpOebtoQJV9ZEJT0JFqbTQg%26gprice%3DdjUJcggeuWWfbm28q4WXHdgMFkO28DrGw49FnubQ0Bk%26gcp%3DzK0DRYY1UV-syqSpmcMYBpOebtoQJV9ZEJT0JFqbTQg%26ah%3D%26de%3Dwjh.popin.cc%26iv%3D0%22%2C%22%24%7BVTRACKER2%7D%22%2C%22%24%7BVTRACKER3%7D%22%2C%22%24%7BVTRACKER4%7D%22%2C%22%24%7BVTRACKER5%7D%22%2C%22%24%7BVTRACKER6%7D%22%5D%2Cs%3D%22f9f2b1ef23fe2759c2cad0953029a94b%22%2Cn%3Ddocument.getElementById(%22mgcontainer-99afea272c2b0e8626489674ddb7a0bb%22)%3Bn%26%26function()%7Bvar%20a%3Dn.getElementsByClassName(%22mediago-placement-track%22)%3Bif(a%26%26a.length)%7Bvar%20t%2Ce%3Dfunction(t)%7Bvar%20e%2Cn%2Co%2Ci%2Cc%2Cr%3B%22object%22%3D%3D%3Df(r%3Da%5Bt%5D)%26%26(e%3Dfunction(t)%7Btry%7Bvar%20e%3Dt.getBoundingClientRect()%2Cn%3De%26%26e.top%7C%7C-1%2Co%3De%26%26e.left%7C%7C-1%2Ci%3Ddocument.body.scrollWidth%7C%7C-1%2Ce%3Ddocument.body.scrollHeight%7C%7C-1%3Breturn%7Btop%3An.toFixed(0)%2Cleft%3Ao.toFixed(0)%2Cpage_width%3Ai%2Cpage_height%3Ae%7D%7Dcatch(o)%7Breturn%20l(%7Btn%3As%2Cwinloss%3A1%2Cfe%3A2%2Cpos_err_c%3A1001%2Cpos_err_m%3Ao.toString()%7D)%2C%7Btop%3A%22-1%22%2Cleft%3A%22-1%22%2Cpage_width%3A%22-1%22%2Cpage_height%3A%22-1%22%7D%7D%7D(r)%2C(n%3Dd%5Bt%5D)%26%26g(n%2C0%2Ce)%2Co%3Dp%5Bt%5D%2Ci%3D!1%2C(c%3Dfunction()%7BsetTimeout(function()%7Bvar%20t%2Ce%3B!i%26%26(t%3Dr%2Ce%3Dwindow.innerHeight%7C%7Cdocument.documentElement.clientHeight%7C%7Cdocument.body.clientHeight%2C(t.getBoundingClientRect()%26%26t.getBoundingClientRect().top)%3C%3De-.75*(t.offsetHeight%7C%7Ct.clientHeight))%3F(i%3D!0%2Co%26%26g(o))%3Ac()%7D%2C500)%7D)())%7D%3Bfor(t%20in%20a)e(t)%7D%7D()%7D()'; + temp += '%3B%3C%2Fscri'; + temp += 'pt%3E'; + adm += decodeURIComponent(temp); let serverResponse = { body: { id: 'mgprebidjs_0b6572fc-ceba-418f-b6fd-33b41ad0ac8a', @@ -61,7 +68,7 @@ describe('mediago:BidAdapterTests', function () { id: '6e28cfaf115a354ea1ad8e1304d6d7b8', impid: '1', price: 0.087581, - adm: "", + adm: adm, cid: '1339145', crid: 'ff32b6f9b3bbc45c00b78b6674a2952e', w: 300, From 461cf79612ceb8a3fee83d847db0d4aee387e960 Mon Sep 17 00:00:00 2001 From: BaronJHYu <254878848@qq.com> Date: Wed, 24 Aug 2022 11:10:56 +0800 Subject: [PATCH 06/10] Update mediagoBidAdapter.js --- modules/mediagoBidAdapter.js | 74 +++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/modules/mediagoBidAdapter.js b/modules/mediagoBidAdapter.js index d038378a1f7..0b75699cef9 100644 --- a/modules/mediagoBidAdapter.js +++ b/modules/mediagoBidAdapter.js @@ -24,32 +24,32 @@ let itemMaps = {}; * @param {number} a random number from 0 to 15 * @return {string} random number or random string */ -function getRandomId( - a // placeholder -) { - // if the placeholder was passed, return - // a random number from 0 to 15 - return a - ? ( - a ^ // unless b is 8, - ((Math.random() * // in which case - 16) >> // a random number from - (a / 4)) - ) // 8 to 11 - .toString(16) // in hexadecimal - : ( // or otherwise a concatenated string: - [1e7] + // 10000000 + - 1e3 + // -1000 + - 4e3 + // -4000 + - 8e3 + // -80000000 + - 1e11 - ) // -100000000000, - .replace( - // replacing - /[018]/g, // zeroes, ones, and eights with - getRandomId // random hex digits - ); -} +// function getRandomId( +// a // placeholder +// ) { +// // if the placeholder was passed, return +// // a random number from 0 to 15 +// return a +// ? ( +// a ^ // unless b is 8, +// ((Math.random() * // in which case +// 16) >> // a random number from +// (a / 4)) +// ) // 8 to 11 +// .toString(16) // in hexadecimal +// : ( // or otherwise a concatenated string: +// [1e7] + // 10000000 + +// 1e3 + // -1000 + +// 4e3 + // -4000 + +// 8e3 + // -80000000 + +// 1e11 +// ) // -100000000000, +// .replace( +// // replacing +// /[018]/g, // zeroes, ones, and eights with +// getRandomId // random hex digits +// ); +// } /* ----- mguid:start ------ */ const COOKIE_KEY_MGUID = '__mguid_'; @@ -296,7 +296,7 @@ function getParam(validBidRequests, bidderRequest) { // console.log('wjh getParam', validBidRequests, bidderRequest); let isMobile = isMobileAndTablet() ? 1 : 0; let isTest = 0; - let auctionId = getProperty(bidderRequest, 'auctionId') || getRandomId(); + let auctionId = getProperty(bidderRequest, 'auctionId'); let items = getItems(validBidRequests, bidderRequest); const domain = document.domain; @@ -412,6 +412,7 @@ export const spec = { ttl: TIME_TO_LIVE, // referrer: REFERER, ad: getProperty(bid, 'adm'), + nurl: getProperty(bid, 'nurl'), // adserverTargeting: { // granularityMultiplier: 0.1, // priceGranularity: "pbHg", @@ -432,10 +433,10 @@ export const spec = { * Register bidder specific code, which will execute if bidder timed out after an auction * @param {data} Containing timeout specific data */ - onTimeout: function (data) { - // console.log('onTimeout', data); - // Bidder specifc code - }, +// onTimeout: function (data) { +// // console.log('onTimeout', data); +// // Bidder specifc code +// }, /** * Register bidder specific code, which will execute if a bid from this bidder won the auction @@ -444,15 +445,18 @@ export const spec = { onBidWon: function (bid) { // console.log('onBidWon', bid, config.getConfig('priceGranularity')); // Bidder specific code + if (bid['nurl']) { + utils.triggerPixel(bid['nurl']); + } }, /** * Register bidder specific code, which will execute when the adserver targeting has been set for a bid from this bidder * @param {Bid} The bid of which the targeting has been set */ - onSetTargeting: function (bid) { - // console.log('onSetTargeting', bid); - // Bidder specific code - }, +// onSetTargeting: function (bid) { +// // console.log('onSetTargeting', bid); +// // Bidder specific code +// }, }; registerBidder(spec); From 618809e98a0ad2d6fdbca13c5169dfeae65311a6 Mon Sep 17 00:00:00 2001 From: BaronYu Date: Wed, 24 Aug 2022 11:16:19 +0800 Subject: [PATCH 07/10] Update mediagoBidAdapter.js --- modules/mediagoBidAdapter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/mediagoBidAdapter.js b/modules/mediagoBidAdapter.js index 0b75699cef9..3d32d645a2e 100644 --- a/modules/mediagoBidAdapter.js +++ b/modules/mediagoBidAdapter.js @@ -433,10 +433,10 @@ export const spec = { * Register bidder specific code, which will execute if bidder timed out after an auction * @param {data} Containing timeout specific data */ -// onTimeout: function (data) { -// // console.log('onTimeout', data); -// // Bidder specifc code -// }, + // onTimeout: function (data) { + // // console.log('onTimeout', data); + // // Bidder specifc code + // }, /** * Register bidder specific code, which will execute if a bid from this bidder won the auction From d4e14f7957c91269d66439afe6ccf90d6e068031 Mon Sep 17 00:00:00 2001 From: BaronJHYu <254878848@qq.com> Date: Wed, 24 Aug 2022 11:37:46 +0800 Subject: [PATCH 08/10] rerun CurcleCi --- modules/mediagoBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mediagoBidAdapter.js b/modules/mediagoBidAdapter.js index 3d32d645a2e..28ca4e0bc50 100644 --- a/modules/mediagoBidAdapter.js +++ b/modules/mediagoBidAdapter.js @@ -443,7 +443,7 @@ export const spec = { * @param {Bid} The bid that won the auction */ onBidWon: function (bid) { - // console.log('onBidWon', bid, config.getConfig('priceGranularity')); + // console.log('onBidWon: ', bid, config.getConfig('priceGranularity')); // Bidder specific code if (bid['nurl']) { utils.triggerPixel(bid['nurl']); From da7477907133c72a5dbff94a392546834329a887 Mon Sep 17 00:00:00 2001 From: BaronYu Date: Fri, 16 Sep 2022 19:42:31 +0800 Subject: [PATCH 09/10] update mediagoBidAdapter --- modules/mediagoBidAdapter.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/mediagoBidAdapter.js b/modules/mediagoBidAdapter.js index 3d32d645a2e..c4c9bd73fb0 100644 --- a/modules/mediagoBidAdapter.js +++ b/modules/mediagoBidAdapter.js @@ -270,7 +270,7 @@ function getItems(validBidRequests, bidderRequest) { pos: 1, }, ext: { - // gpid: gpid, // 加入后无法返回广告 + // gpid: gpid, // 加入后无法返回广告 }, }; itemMaps[id] = { @@ -293,14 +293,19 @@ function getItems(validBidRequests, bidderRequest) { */ function getParam(validBidRequests, bidderRequest) { const pubcid = utils.deepAccess(validBidRequests[0], 'crumbs.pubcid'); - // console.log('wjh getParam', validBidRequests, bidderRequest); + const sharedid = + utils.deepAccess(validBidRequests[0], 'userId.sharedid.id') || + utils.deepAccess(validBidRequests[0], 'userId.pubcid'); let isMobile = isMobileAndTablet() ? 1 : 0; let isTest = 0; let auctionId = getProperty(bidderRequest, 'auctionId'); let items = getItems(validBidRequests, bidderRequest); - const domain = document.domain; - const location = utils.deepAccess(bidderRequest, 'refererInfo.referer'); + const domain = + utils.deepAccess(bidderRequest, 'refererInfo.domain') || document.domain; + const location = utils.deepAccess(bidderRequest, 'refererInfo.location'); + const page = utils.deepAccess(bidderRequest, 'refererInfo.page'); + const referer = utils.deepAccess(bidderRequest, 'refererInfo.ref'); const timeout = bidderRequest.timeout || 2000; @@ -323,14 +328,13 @@ function getParam(validBidRequests, bidderRequest) { }, ext: {}, user: { - buyeruid: getUserID(), - id: pubcid, + id: sharedid || pubcid || getUserID(), }, site: { name: domain, domain: domain, - page: location, - ref: location, + page: page || location, + ref: referer, mobile: isMobile, cat: [], // todo publisher: { @@ -454,9 +458,9 @@ export const spec = { * Register bidder specific code, which will execute when the adserver targeting has been set for a bid from this bidder * @param {Bid} The bid of which the targeting has been set */ -// onSetTargeting: function (bid) { -// // console.log('onSetTargeting', bid); -// // Bidder specific code -// }, + // onSetTargeting: function (bid) { + // // console.log('onSetTargeting', bid); + // // Bidder specific code + // }, }; registerBidder(spec); From b52fd79c576930d9eab796fe4ce7b95d2acd2bc4 Mon Sep 17 00:00:00 2001 From: BaronYu Date: Wed, 16 Nov 2022 19:03:35 +0800 Subject: [PATCH 10/10] update discoveryBidAdapter --- modules/discoveryBidAdapter.js | 55 +++++++++++++------ modules/discoveryBidAdapter.md | 13 +++-- test/spec/modules/discoveryBidAdapter_spec.js | 17 +++--- 3 files changed, 54 insertions(+), 31 deletions(-) diff --git a/modules/discoveryBidAdapter.js b/modules/discoveryBidAdapter.js index 4f22a41cf9f..fab3920efcc 100644 --- a/modules/discoveryBidAdapter.js +++ b/modules/discoveryBidAdapter.js @@ -12,7 +12,8 @@ let itemMaps = {}; const MEDIATYPE = [BANNER, NATIVE]; /* ----- _ss_pp_id:start ------ */ -const COOKIE_KEY_MGUID = '_ss_pp_id'; +const COOKIE_KEY_SSPPID = '_ss_pp_id'; +const COOKIE_KEY_MGUID = '__mguid_'; const NATIVERET = { id: 'id', @@ -58,14 +59,20 @@ const NATIVERET = { * @return {string} */ const getUserID = () => { - const i = storage.getCookie(COOKIE_KEY_MGUID); + let idd = storage.getCookie(COOKIE_KEY_SSPPID); + let idm = storage.getCookie(COOKIE_KEY_MGUID); - if (i === null) { + if (idd && !idm) { + idm = idd + } else if (idm && !idd) { + idd = idm + } else if (!idd && !idm) { const uuid = utils.generateUUID(); storage.setCookie(COOKIE_KEY_MGUID, uuid); + storage.setCookie(COOKIE_KEY_SSPPID, uuid); return uuid; } - return i; + return idd; }; /* ----- _ss_pp_id:end ------ */ @@ -80,7 +87,6 @@ function getKv(obj, ...keys) { let o = obj; for (let key of keys) { - // console.log(key, o); if (o && o[key]) { o = o[key]; } else { @@ -222,7 +228,7 @@ function getItems(validBidRequests, bidderRequest) { let id = '' + (i + 1); if (mediaTypes.native) { - ret = {...NATIVERET, ...{id, bidFloor}} + ret = { ...NATIVERET, ...{ id, bidFloor } } } // banner if (mediaTypes.banner) { @@ -249,6 +255,7 @@ function getItems(validBidRequests, bidderRequest) { pos: 1, }, ext: {}, + tagid: globals['tagid'], }; } itemMaps[id] = { @@ -273,14 +280,19 @@ function getParam(validBidRequests, bidderRequest) { let auctionId = getKv(bidderRequest, 'auctionId'); let items = getItems(validBidRequests, bidderRequest); - const location = utils.deepAccess(bidderRequest, 'refererInfo.referer'); - const timeout = bidderRequest.timeout || 2000; + const domain = utils.deepAccess(bidderRequest, 'refererInfo.domain') || document.domain; + const location = utils.deepAccess(bidderRequest, 'refererInfo.referer'); + const page = utils.deepAccess(bidderRequest, 'refererInfo.page'); + const referer = utils.deepAccess(bidderRequest, 'refererInfo.ref'); + if (items && items.length) { let c = { id: 'pp_hbjs_' + auctionId, at: 1, + bcat: globals['bcat'], + badv: globals['adv'], cur: ['USD'], device: { connectiontype: 0, @@ -295,16 +307,16 @@ function getParam(validBidRequests, bidderRequest) { }, tmax: timeout, site: { - name: globals['media'], - domain: globals['media'], - page: location, - ref: location, + name: domain, + domain: domain, + page: page || location, + ref: referer, mobile: isMobile, cat: [], // todo publisher: { + id: globals['publisher'] // todo - id: globals['media'], - name: globals['media'], + // name: xxx }, }, imp: items, @@ -329,10 +341,19 @@ export const spec = { if (bid.params.token) { globals['token'] = bid.params.token; } - if (bid.params.media) { - globals['media'] = bid.params.media; + if (bid.params.publisher) { + globals['publisher'] = bid.params.publisher; + } + if (bid.params.tagid) { + globals['tagid'] = bid.params.tagid; + } + if (bid.params.bcat) { + globals['bcat'] = Array.isArray(bid.params.bcat) ? bid.params.bcat : []; + } + if (bid.params.badv) { + globals['badv'] = Array.isArray(bid.params.badv) ? bid.params.badv : []; } - return !!(bid.params.token && bid.params.media); + return !!(bid.params.token && bid.params.publisher && bid.params.tagid); }, /** diff --git a/modules/discoveryBidAdapter.md b/modules/discoveryBidAdapter.md index 6e7197863a5..e951b0b7448 100644 --- a/modules/discoveryBidAdapter.md +++ b/modules/discoveryBidAdapter.md @@ -1,15 +1,15 @@ # Overview ``` -Module Name: DiscoveryDSP Bid Adapter +Module Name: discovery Bid Adapter Module Type: Bidder Adapter ``` # Description -Module that connects to popIn's demand sources +Module that connects to popIn's demand sources. -The DiscoveryDSP Bidding adapter requires setup before beginning. Please contact us at +The discovery Bidding adapter requires setup before beginning. Please contact us at # Test Parameters ``` @@ -32,7 +32,8 @@ The DiscoveryDSP Bidding adapter requires setup before beginning. Please contact bidder: "discovery", params: { token: "a1b067897e4ae093d1f94261e0ddc6c9", - media: 'test_media' // your media host + tagid: 'test_tagid', + publisher: 'test_publisher' }, }, ], @@ -45,13 +46,13 @@ The DiscoveryDSP Bidding adapter requires setup before beginning. Please contact sizes: [[300, 250]], }, }, - // Replace this object to test a new adapter! bids: [ { bidder: "discovery", params: { token: "d0f4902b616cc5c38cbe0a08676d0ed9", - media: 'test_media' // your media host + tagid: 'test_tagid', + publisher: 'test_publisher' }, }, ], diff --git a/test/spec/modules/discoveryBidAdapter_spec.js b/test/spec/modules/discoveryBidAdapter_spec.js index a30afd96ad1..078add73046 100644 --- a/test/spec/modules/discoveryBidAdapter_spec.js +++ b/test/spec/modules/discoveryBidAdapter_spec.js @@ -1,14 +1,14 @@ import { expect } from 'chai'; import { spec } from 'modules/discoveryBidAdapter.js'; -describe('DiscoveryDSP:BidAdapterTests', function () { +describe('discovery:BidAdapterTests', function () { let bidRequestData = { - bidderCode: 'DiscoveryDSP', + bidderCode: 'discovery', auctionId: 'ff66e39e-4075-4d18-9854-56fde9b879ac', bidderRequestId: '4fec04e87ad785', bids: [ { - bidder: 'DiscoveryDSP', + bidder: 'discovery', params: { token: 'd0f4902b616cc5c38cbe0a08676d0ed9', }, @@ -32,25 +32,26 @@ describe('DiscoveryDSP:BidAdapterTests', function () { }; let request = []; - it('DiscoveryDSP:validate_pub_params', function () { + it('discovery:validate_pub_params', function () { expect( spec.isBidRequestValid({ - bidder: 'DiscoveryDSP', + bidder: 'discovery', params: { token: ['d0f4902b616cc5c38cbe0a08676d0ed9'], - media: ['test_media'] + tagid: ['test_tagid'], + publisher: ['test_publisher'] }, }) ).to.equal(true); }); - it('DiscoveryDSP:validate_generated_params', function () { + it('discovery:validate_generated_params', function () { request = spec.buildRequests(bidRequestData.bids, bidRequestData); let req_data = JSON.parse(request.data); expect(req_data.imp).to.have.lengthOf(1); }); - it('DiscoveryDSP:validate_response_params', function () { + it('discovery:validate_response_params', function () { let tempAdm = '' tempAdm += '%3Cscr'; tempAdm += 'ipt%3E';