Skip to content

Commit af5703d

Browse files
authored
Mediago Bid Adapter : add param publisherid (prebid#12753)
* Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid * Mediago Bid Adapter : add param publisherid
1 parent 7a66733 commit af5703d

File tree

4 files changed

+57
-78
lines changed

4 files changed

+57
-78
lines changed

libraries/cookieSync/cookieSync.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { getStorageManager } from '../../src/storageManager.js';
2+
const COOKIE_KEY_MGUID = '__mguid_';
3+
4+
export function cookieSync(syncOptions, gdprConsent, uspConsent, bidderCode, cookieOrigin, ckIframeUrl, cookieTime) {
5+
const storage = getStorageManager({bidderCode: bidderCode});
6+
const origin = encodeURIComponent(location.origin || `https://${location.host}`);
7+
let syncParamUrl = `dm=${origin}`;
8+
9+
if (gdprConsent && gdprConsent.consentString) {
10+
if (typeof gdprConsent.gdprApplies === 'boolean') {
11+
syncParamUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
12+
} else {
13+
syncParamUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
14+
}
15+
}
16+
if (uspConsent && uspConsent.consentString) {
17+
syncParamUrl += `&ccpa_consent=${uspConsent.consentString}`;
18+
}
19+
20+
if (syncOptions.iframeEnabled) {
21+
window.addEventListener('message', function handler(event) {
22+
if (!event.data || event.origin != cookieOrigin) {
23+
return;
24+
}
25+
26+
this.removeEventListener('message', handler);
27+
28+
event.stopImmediatePropagation();
29+
30+
const response = event.data;
31+
if (!response.optout && response.mguid) {
32+
storage.setCookie(COOKIE_KEY_MGUID, response.mguid, cookieTime);
33+
}
34+
}, true);
35+
return [
36+
{
37+
type: 'iframe',
38+
url: `${ckIframeUrl}?${syncParamUrl}`
39+
}
40+
];
41+
}
42+
}

modules/discoveryBidAdapter.js

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getDevice, getScreenSize } from '../libraries/fpdUtils/deviceInfo.js';
77
import { getBidFloor } from '../libraries/currencyUtils/floor.js';
88
import { transformSizes, normalAdSize } from '../libraries/sizeUtils/tranformSize.js';
99
import { getHLen } from '../libraries/navigatorData/navigatorData.js';
10+
import { cookieSync } from '../libraries/cookieSync/cookieSync.js';
1011

1112
/**
1213
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
@@ -484,42 +485,7 @@ export const spec = {
484485
},
485486

486487
getUserSyncs: function (syncOptions, serverResponse, gdprConsent, uspConsent, gppConsent) {
487-
const origin = encodeURIComponent(location.origin || `https://${location.host}`);
488-
let syncParamUrl = `dm=${origin}`;
489-
490-
if (gdprConsent && gdprConsent.consentString) {
491-
if (typeof gdprConsent.gdprApplies === 'boolean') {
492-
syncParamUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
493-
} else {
494-
syncParamUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
495-
}
496-
}
497-
if (uspConsent && uspConsent.consentString) {
498-
syncParamUrl += `&ccpa_consent=${uspConsent.consentString}`;
499-
}
500-
501-
if (syncOptions.iframeEnabled) {
502-
window.addEventListener('message', function handler(event) {
503-
if (!event.data || event.origin != THIRD_PARTY_COOKIE_ORIGIN) {
504-
return;
505-
}
506-
507-
this.removeEventListener('message', handler);
508-
509-
event.stopImmediatePropagation();
510-
511-
const response = event.data;
512-
if (!response.optout && response.mguid) {
513-
storage.setCookie(COOKIE_KEY_MGUID, response.mguid, getCookieTimeToUTCString());
514-
}
515-
}, true);
516-
return [
517-
{
518-
type: 'iframe',
519-
url: `${COOKY_SYNC_IFRAME_URL}?${syncParamUrl}`
520-
}
521-
];
522-
}
488+
return cookieSync(syncOptions, gdprConsent, uspConsent, BIDDER_CODE, THIRD_PARTY_COOKIE_ORIGIN, COOKY_SYNC_IFRAME_URL, getCookieTimeToUTCString());
523489
},
524490

525491
/**

modules/mediagoBidAdapter.js

Lines changed: 8 additions & 40 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 { cookieSync } from '../libraries/cookieSync/cookieSync.js';
1314

1415
// import { config } from '../src/config.js';
1516
// import { isPubcidEnabled } from './pubCommonId.js';
@@ -25,7 +26,6 @@ const BIDDER_CODE = 'mediago';
2526
// const PROTOCOL = window.document.location.protocol;
2627
const ENDPOINT_URL = 'https://gbid.mediago.io/api/bid?tn=';
2728
// const COOKY_SYNC_URL = 'https://gtrace.mediago.io/ju/cs/eplist';
28-
const COOKY_SYNC_IFRAME_URL = 'https://cdn.mediago.io/js/cookieSync.html';
2929
export const THIRD_PARTY_COOKIE_ORIGIN = 'https://cdn.mediago.io';
3030

3131
const TIME_TO_LIVE = 500;
@@ -39,6 +39,7 @@ let itemMaps = {};
3939
export const COOKIE_KEY_MGUID = '__mguid_';
4040
const COOKIE_KEY_PMGUID = '__pmguid_';
4141
const COOKIE_RETENTION_TIME = 365 * 24 * 60 * 60 * 1000; // 1 year
42+
const COOKY_SYNC_IFRAME_URL = 'https://cdn.mediago.io/js/cookieSync.html';
4243
let reqTimes = 0;
4344

4445
/**
@@ -172,6 +173,7 @@ function getItems(validBidRequests, bidderRequest) {
172173
ortb2Imp: utils.deepAccess(req, 'ortb2Imp'), // 传入完整对象,分析日志数据
173174
gpid: gpid, // 加入后无法返回广告
174175
adslot: utils.deepAccess(req, 'ortb2Imp.ext.data.adserver.adslot', '', ''),
176+
publisher: req.params.publisher || '',
175177
...gdprConsent // gdpr
176178
},
177179
tagid: req.params && req.params.tagid
@@ -286,9 +288,7 @@ function getParam(validBidRequests, bidderRequest) {
286288
mobile: isMobile,
287289
cat: [], // todo
288290
publisher: {
289-
// todo
290-
id: domain,
291-
name: domain
291+
id: globals['publisher']
292292
}
293293
},
294294
imp: items,
@@ -317,6 +317,9 @@ export const spec = {
317317
if (bid.params.token) {
318318
globals['token'] = bid.params.token;
319319
}
320+
if (bid.params.publisher) {
321+
globals['publisher'] = bid.params.publisher;
322+
}
320323
return !!bid.params.token;
321324
},
322325

@@ -382,42 +385,7 @@ export const spec = {
382385
},
383386

384387
getUserSyncs: function (syncOptions, serverResponse, gdprConsent, uspConsent, gppConsent) {
385-
const origin = encodeURIComponent(location.origin || `https://${location.host}`);
386-
let syncParamUrl = `dm=${origin}`;
387-
388-
if (gdprConsent && gdprConsent.consentString) {
389-
if (typeof gdprConsent.gdprApplies === 'boolean') {
390-
syncParamUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
391-
} else {
392-
syncParamUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
393-
}
394-
}
395-
if (uspConsent && uspConsent.consentString) {
396-
syncParamUrl += `&ccpa_consent=${uspConsent.consentString}`;
397-
}
398-
399-
if (syncOptions.iframeEnabled) {
400-
window.addEventListener('message', function handler(event) {
401-
if (!event.data || event.origin != THIRD_PARTY_COOKIE_ORIGIN) {
402-
return;
403-
}
404-
405-
this.removeEventListener('message', handler);
406-
407-
event.stopImmediatePropagation();
408-
409-
const response = event.data;
410-
if (!response.optout && response.mguid) {
411-
storage.setCookie(COOKIE_KEY_MGUID, response.mguid, getCurrentTimeToUTCString());
412-
}
413-
}, true);
414-
return [
415-
{
416-
type: 'iframe',
417-
url: `${COOKY_SYNC_IFRAME_URL}?${syncParamUrl}`
418-
}
419-
];
420-
}
388+
return cookieSync(syncOptions, gdprConsent, uspConsent, BIDDER_CODE, THIRD_PARTY_COOKIE_ORIGIN, COOKY_SYNC_IFRAME_URL, getCurrentTimeToUTCString());
421389
},
422390

423391
/**

test/spec/modules/mediagoBidAdapter_spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ describe('mediago:BidAdapterTests', function () {
5656
content: {
5757
keywords: 'video, source=streaming'
5858
},
59-
59+
publisher: {
60+
domain: 'mediago.io'
61+
},
6062
},
6163
user: {
6264
ext: {
@@ -158,7 +160,8 @@ describe('mediago:BidAdapterTests', function () {
158160
spec.isBidRequestValid({
159161
bidder: 'mediago',
160162
params: {
161-
token: ['85a6b01e41ac36d49744fad726e3655d']
163+
token: ['85a6b01e41ac36d49744fad726e3655d'],
164+
publisher: ['test_publisher']
162165
}
163166
})
164167
).to.equal(true);

0 commit comments

Comments
 (0)