Skip to content

Commit f502bd3

Browse files
SylviaFfangsimin@baidu.com方思敏
authored
MediaGo Bid Adapter: sends transactionId and Prebid.js version in the request payload, and optimizes deprecated navigator.platform (prebid#14538)
* notify server if the page is secure * remove undefined initial * MediaGo Bid Adapter: update adapter, test page and spec Made-with: Cursor * MediaGo: remove redundant debug-info, use Network tab for verification; remove Chinese comments Made-with: Cursor --------- Co-authored-by: fangsimin@baidu.com <fangsimin@baidu.com> Co-authored-by: 方思敏 <fangsimin@fangsimindeMacBook-Pro.local>
1 parent f096787 commit f502bd3

3 files changed

Lines changed: 46 additions & 125 deletions

File tree

integrationExamples/gpt/mediago_test.html

Lines changed: 3 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -121,116 +121,6 @@
121121
}]
122122
}
123123
];
124-
125-
var pbjs = pbjs || {};
126-
pbjs.que = pbjs.que || [];
127-
128-
// Store request information for debugging
129-
var requestLogs = [];
130-
131-
// Intercept AJAX requests to view sent data
132-
var originalOpen = XMLHttpRequest.prototype.open;
133-
var originalSend = XMLHttpRequest.prototype.send;
134-
135-
XMLHttpRequest.prototype.open = function(method, url, ...args) {
136-
this._url = url;
137-
this._method = method;
138-
return originalOpen.apply(this, [method, url, ...args]);
139-
};
140-
141-
XMLHttpRequest.prototype.send = function(data) {
142-
if (this._url && this._url.includes('mediago.io')) {
143-
try {
144-
var requestData = JSON.parse(data);
145-
requestLogs.push({
146-
url: this._url,
147-
method: this._method,
148-
data: requestData,
149-
timestamp: new Date().toISOString()
150-
});
151-
console.log('Mediago Request:', requestData);
152-
153-
// Check if IDs in imp array are unique
154-
if (requestData.imp && Array.isArray(requestData.imp)) {
155-
var ids = requestData.imp.map(imp => imp.id).filter(Boolean);
156-
var uniqueIds = [...new Set(ids)];
157-
var isUnique = ids.length === uniqueIds.length;
158-
159-
console.log('ID Uniqueness Check:');
160-
console.log(' Total IDs:', ids.length);
161-
console.log(' Unique IDs:', uniqueIds.length);
162-
console.log(' Is Unique:', isUnique ? '✓ Yes' : '✗ No');
163-
console.log(' ID List:', ids);
164-
165-
if (!isUnique) {
166-
console.warn('Warning: Duplicate IDs found!', ids);
167-
}
168-
169-
updateDebugInfo(requestData, isUnique, ids, uniqueIds);
170-
}
171-
} catch (e) {
172-
console.error('Failed to parse request data:', e);
173-
}
174-
}
175-
176-
// Listen for response
177-
this.addEventListener('load', function() {
178-
if (this._url && this._url.includes('mediago.io')) {
179-
try {
180-
var response = JSON.parse(this.responseText);
181-
console.log('Mediago Response:', response);
182-
updateResponseInfo(response);
183-
} catch (e) {
184-
console.error('Failed to parse response data:', e);
185-
}
186-
}
187-
});
188-
189-
return originalSend.apply(this, [data]);
190-
};
191-
192-
function updateDebugInfo(requestData, isUnique, ids, uniqueIds) {
193-
var debugDiv = document.getElementById('debug-info');
194-
if (!debugDiv) return;
195-
196-
var html = '<h4>Request Debug Info</h4>';
197-
html += '<p><strong>Time:</strong> ' + new Date().toLocaleString() + '</p>';
198-
html += '<p><strong>ID Uniqueness:</strong> <span style="color: ' + (isUnique ? 'green' : 'red') + '">' + (isUnique ? '✓ Pass' : '✗ Fail') + '</span></p>';
199-
html += '<p><strong>Total IDs:</strong> ' + ids.length + '</p>';
200-
html += '<p><strong>Unique IDs:</strong> ' + uniqueIds.length + '</p>';
201-
html += '<p><strong>ID List:</strong></p>';
202-
html += '<ul>';
203-
ids.forEach((id, index) => {
204-
var isDup = ids.indexOf(id) !== ids.lastIndexOf(id);
205-
html += '<li style="color: ' + (isDup ? 'red' : 'black') + '">';
206-
html += 'Ad Unit ' + (index + 1) + ': <code>' + id + '</code>';
207-
if (isDup) html += ' <strong>(Duplicate!)</strong>';
208-
html += '</li>';
209-
});
210-
html += '</ul>';
211-
212-
html += '<p><strong>Request Data (imp section):</strong></p>';
213-
html += '<pre>' + JSON.stringify(requestData.imp, null, 2) + '</pre>';
214-
215-
debugDiv.innerHTML = html;
216-
}
217-
218-
function updateResponseInfo(response) {
219-
var responseDiv = document.getElementById('response-info');
220-
if (!responseDiv) return;
221-
222-
var html = '<h4>Response Info</h4>';
223-
html += '<p><strong>Time:</strong> ' + new Date().toLocaleString() + '</p>';
224-
if (response.seatbid && response.seatbid.length > 0) {
225-
html += '<p><strong>Number of bids returned:</strong> ' + response.seatbid[0].bid.length + '</p>';
226-
html += '<pre>' + JSON.stringify(response, null, 2) + '</pre>';
227-
} else {
228-
html += '<p>No valid response received</p>';
229-
}
230-
231-
responseDiv.innerHTML = html;
232-
}
233-
234124
</script>
235125
</head>
236126

@@ -282,6 +172,9 @@ <h3>Ad Unit 3 (728x90)</h3>
282172
pbjs.que.push(function() {
283173
console.log('Prebid.js loaded');
284174

175+
// Enable TID (Transaction ID) transmission - required since Prebid 8 for ortb2Imp.ext.tid to reach bidders
176+
pbjs.setConfig({ enableTIDs: true });
177+
285178
// Set pageUrl and ortb2 site configuration to simulate other site
286179
// pageUrl will override Prebid's referrer detection
287180
// pbjs.setConfig({
@@ -420,7 +313,6 @@ <h3>Ad Unit 3 (728x90)</h3>
420313
function clearDebug() {
421314
document.getElementById('debug-info').innerHTML = '<h4>Debug info cleared</h4>';
422315
document.getElementById('response-info').innerHTML = '<h4>Response info cleared</h4>';
423-
requestLogs = [];
424316

425317
// Clear ad containers
426318
['mediago-ad-1', 'mediago-ad-2', 'mediago-ad-3'].forEach(function(id) {

modules/mediagoBidAdapter.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getDevice } from '../libraries/fpdUtils/deviceInfo.js';
1010
import { getBidFloor } from '../libraries/currencyUtils/floor.js';
1111
import { transformSizes, normalAdSize } from '../libraries/sizeUtils/tranformSize.js';
1212
import { getHLen } from '../libraries/navigatorData/navigatorData.js';
13+
import { getOsInfo } from '../libraries/nexverseUtils/index.js';
1314
import { cookieSync } from '../libraries/cookieSync/cookieSync.js';
1415

1516
// import { config } from '../src/config.js';
@@ -42,8 +43,7 @@ const COOKY_SYNC_IFRAME_URL = 'https://cdn.mediago.io/js/cookieSync.html';
4243
let reqTimes = 0;
4344

4445
/**
45-
* get pmg uid
46-
* 获取并生成用户的id
46+
* Get or generate pmg uid
4747
*
4848
* @return {string}
4949
*/
@@ -63,10 +63,10 @@ export const getPmgUID = () => {
6363
/* ----- pmguid:end ------ */
6464

6565
/**
66-
* 获取一个对象的某个值,如果没有则返回空字符串
66+
* Get a nested property value from object, return empty string if not found
6767
*
68-
* @param {Object} obj 对象
69-
* @param {...string} keys 键名
68+
* @param {Object} obj object
69+
* @param {...string} keys key path
7070
* @return {any}
7171
*/
7272
function getProperty(obj, ...keys) {
@@ -84,7 +84,21 @@ function getProperty(obj, ...keys) {
8484
}
8585

8686
/**
87-
* 获取底价
87+
* Retrieve device platform/OS, priority order: userAgentData.platform > navigator.platform > UA parsing
88+
* @returns {string}
89+
*/
90+
function getDeviceOs() {
91+
if (navigator.userAgentData?.platform) {
92+
return navigator.userAgentData.platform;
93+
}
94+
if (navigator.platform) {
95+
return navigator.platform;
96+
}
97+
return getOsInfo().os || '';
98+
}
99+
100+
/**
101+
* Get bid floor
88102
* @param {*} bid
89103
* @param {*} mediaType
90104
* @param {*} sizes
@@ -106,11 +120,11 @@ function getProperty(obj, ...keys) {
106120
// return floor;
107121
// }
108122

109-
// 支持的广告尺寸
123+
// Supported ad sizes
110124
const mediagoAdSize = normalAdSize;
111125

112126
/**
113-
* 获取广告位配置
127+
* Get ad slot config
114128
* @param {Array} validBidRequests an an array of bids
115129
* @param {Object} bidderRequest The master bidRequest object
116130
* @return {Object}
@@ -124,7 +138,7 @@ function getItems(validBidRequests, bidderRequest) {
124138
const sizes = transformSizes(getProperty(req, 'sizes'));
125139
let matchSize;
126140

127-
// 确认尺寸是否符合我们要求
141+
// Validate size meets requirements
128142
for (const size of sizes) {
129143
matchSize = mediagoAdSize.find(item => size.width === item.w && size.height === item.h);
130144
if (matchSize) {
@@ -153,7 +167,7 @@ function getItems(validBidRequests, bidderRequest) {
153167
}
154168

155169
// if (mediaTypes.native) {}
156-
// banner广告类型
170+
// Banner ad type
157171
if (mediaTypes.banner) {
158172
// fix id is not unique where there are multiple requests in the same page
159173
const id = getProperty(req, 'bidId') || ('' + (i + 1) + Math.random().toString(36).substring(2, 15));
@@ -169,10 +183,11 @@ function getItems(validBidRequests, bidderRequest) {
169183
ext: {
170184
adUnitCode: req.adUnitCode,
171185
referrer: getReferrer(req, bidderRequest),
172-
ortb2Imp: utils.deepAccess(req, 'ortb2Imp'), // 传入完整对象,分析日志数据
173-
gpid: gpid, // 加入后无法返回广告
186+
ortb2Imp: utils.deepAccess(req, 'ortb2Imp'),
187+
gpid: gpid,
174188
adslot: utils.deepAccess(req, 'ortb2Imp.ext.data.adserver.adslot', '', ''),
175189
publisher: req.params.publisher || '',
190+
transactionId: utils.deepAccess(req, 'ortb2Imp.ext.tid') || req.transactionId || '',
176191
...gdprConsent // gdpr
177192
},
178193
tagid: req.params && req.params.tagid
@@ -195,7 +210,7 @@ export function getCurrentTimeToUTCString() {
195210
}
196211

197212
/**
198-
* 获取rtb请求参数
213+
* Get RTB request params
199214
*
200215
* @param {Array} validBidRequests an an array of bids
201216
* @param {Object} bidderRequest The master bidRequest object
@@ -240,11 +255,12 @@ function getParam(validBidRequests, bidderRequest) {
240255
// language: 'en',
241256
// os: 'Microsoft Windows',
242257
// ua: 'Mozilla/5.0 (Linux; Android 12; SM-G970U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Mobile Safari/537.36',
243-
os: navigator.platform || '',
258+
os: getDeviceOs(),
244259
ua: navigator.userAgent,
245260
language: /en/.test(navigator.language) ? 'en' : navigator.language
246261
},
247262
ext: {
263+
pbjsversion: '$prebid.version$',
248264
eids,
249265
bidsUserIdAsEids,
250266
firstPartyData,

test/spec/modules/mediagoBidAdapter_spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ describe('mediago:BidAdapterTests', function () {
141141
expect(req_data.imp).to.have.lengthOf(1);
142142
});
143143

144+
it('mediago:validate_transactionId_in_request', function () {
145+
request = spec.buildRequests(bidRequestData.bids, bidRequestData);
146+
const req_data = JSON.parse(request.data);
147+
expect(req_data.imp[0].ext.transactionId).to.equal('7b26fdae-96e6-4c35-a18b-218dda11397d');
148+
});
149+
150+
it('mediago:validate_pbjs_source_and_version_in_request', function () {
151+
request = spec.buildRequests(bidRequestData.bids, bidRequestData);
152+
const req_data = JSON.parse(request.data);
153+
expect(req_data.ext.pbjsversion).to.be.a('string');
154+
expect(req_data.ext.pbjsversion.length).to.be.above(0);
155+
});
156+
144157
describe('mediago: buildRequests', function() {
145158
describe('getPmgUID function', function() {
146159
let sandbox;

0 commit comments

Comments
 (0)