Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify mediago bidder adapter to compatible with version 2.0 and version 3.0 #5680

Closed
wants to merge 15 commits into from
48 changes: 44 additions & 4 deletions modules/mediagoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*/

import * as utils from '../src/utils.js';
import { getStorageManager } from '../src/storageManager.js';
// import { getStorageManager } from '../src/storageManager.js'; // compatible to v3.0
//
import {
registerBidder
} from '../src/adapters/bidderFactory.js';
Expand All @@ -15,7 +16,7 @@ const ENDPOINT_URL =
'https://rtb-us.mediago.io/api/bid?tn=';
const TIME_TO_LIVE = 500;
// const ENDPOINT_URL = '/api/bid?tn=';
const storage = getStorageManager();
// const storage = getStorageManager(); // compatible to v3.0
let globals = {};
let itemMaps = {};

Expand Down Expand Up @@ -46,6 +47,38 @@ function getRandomId(
);
}

/**
* @param {string} key
* @param {string} value
* @param {string} [expires='']
* @param {string} [sameSite='/']
* @param {string} [domain] domain (e.g., 'example.com' or 'subdomain.example.com').
* If not specified, defaults to the host portion of the current document location.
* If a domain is specified, subdomains are always included.
* Domain must match the domain of the JavaScript origin. Setting cookies to foreign domains will be silently ignored.
*/
const setCookie = function(key, value, expires, sameSite, domain) {
if (getProperty(window, 'document', 'cookie')) {
const domainPortion = (domain && domain !== '') ? ` ;domain=${encodeURIComponent(domain)}` : '';
const expiresPortion = (expires && expires !== '') ? ` ;expires=${expires}` : '';
const isNone = (sameSite != null && sameSite.toLowerCase() == 'none')
const secure = (isNone) ? '; Secure' : '';
document.cookie = `${key}=${encodeURIComponent(value)}${expiresPortion}; path=/${domainPortion}${sameSite ? `; SameSite=${sameSite}` : ''}${secure}`;
}
};

/**
* @param {string} name
* @returns {(string|null)}
*/
const getCookie = function(name) {
if (getProperty(window, 'document', 'cookie')) {
let m = window.document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]*)\\s*(;|$)');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you comment out and bypass storage manager?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to compatible with Prebid v2.0 and v3.0.
And the storage manager dosen't be added in v2.0 and v3.0.

return m ? decodeURIComponent(m[2]) : null;
}
return null;
};

/* ----- mguid:start ------ */
const COOKIE_KEY_MGUID = '__mguid_';

Expand All @@ -54,11 +87,11 @@ const COOKIE_KEY_MGUID = '__mguid_';
* @return {string}
*/
const getUserID = () => {
const i = storage.getCookie(COOKIE_KEY_MGUID);
const i = getCookie(COOKIE_KEY_MGUID);

if (i === null) {
const uuid = utils.generateUUID();
storage.setCookie(COOKIE_KEY_MGUID, uuid);
setCookie(COOKIE_KEY_MGUID, uuid);
return uuid;
}
return i;
Expand Down Expand Up @@ -215,6 +248,7 @@ function getParam(validBidRequests, bidderRequest) {
let isTest = 0;
let auctionId = getProperty(bidderRequest, 'auctionId') || getRandomId();
let items = getItems(validBidRequests, bidderRequest);
// console.log(items);

const domain = document.domain;
const location = utils.deepAccess(bidderRequest, 'refererInfo.referer');
Expand Down Expand Up @@ -286,7 +320,13 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {
// console.log('mediago', {
// validBidRequests, bidderRequest
// });
let payload = getParam(validBidRequests, bidderRequest);
// console.log('mediago', {
// payload
// });

const payloadString = JSON.stringify(payload);
return {
Expand Down