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

GMOSSP Bid Adapte:Add user module, meta_url. #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions modules/gmosspBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { getDNT, getBidIdParameter, tryAppendQueryString, isEmpty, createTrackPixelHtml, logError, deepSetValue } from '../src/utils.js';
import { deepAccess, getDNT, getBidIdParameter, tryAppendQueryString, isEmpty, createTrackPixelHtml, logError, deepSetValue, getWindowTop, getWindowLocation, getWindowSelf } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'gmossp';
const ENDPOINT = 'https://sp.gmossp-sp.jp/hb/prebid/query.ad';
const storage = getStorageManager();

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -34,14 +31,16 @@ export const spec = {
const urlInfo = getUrlInfo(bidderRequest.refererInfo);
const cur = getCurrencyType();
const dnt = getDNT() ? '1' : '0';
const imuid = storage.getCookie('_im_uid.1000283') || '';

for (let i = 0; i < validBidRequests.length; i++) {
let queryString = '';

const request = validBidRequests[i];
const tid = request.transactionId;
const bid = request.bidId;
const imuid = deepAccess(request, 'userId.imuid');
const sharedId = deepAccess(request, 'userId.pubcid');
const idlEnv = deepAccess(request, 'userId.idl_env');
const ver = '$prebid.version$';
const sid = getBidIdParameter('sid', request.params);

Expand All @@ -50,7 +49,10 @@ export const spec = {
queryString = tryAppendQueryString(queryString, 'ver', ver);
queryString = tryAppendQueryString(queryString, 'sid', sid);
queryString = tryAppendQueryString(queryString, 'im_uid', imuid);
queryString = tryAppendQueryString(queryString, 'shared_id', sharedId);
queryString = tryAppendQueryString(queryString, 'idl_env', idlEnv);
queryString = tryAppendQueryString(queryString, 'url', urlInfo.url);
queryString = tryAppendQueryString(queryString, 'meta_url', urlInfo.canonicalLink);
queryString = tryAppendQueryString(queryString, 'ref', urlInfo.ref);
queryString = tryAppendQueryString(queryString, 'cur', cur);
queryString = tryAppendQueryString(queryString, 'dnt', dnt);
Expand Down Expand Up @@ -112,7 +114,7 @@ export const spec = {
* @param {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function(syncOptions, serverResponses) {
getUserSyncs: function (syncOptions, serverResponses) {
const syncs = [];
if (!serverResponses.length) {
return syncs;
Expand Down Expand Up @@ -141,27 +143,47 @@ function getCurrencyType() {
}

function getUrlInfo(refererInfo) {
let canonicalLink = refererInfo.canonicalUrl;

if (!canonicalLink) {
let metaElements = getMetaElements();
for (let i = 0; i < metaElements.length && !canonicalLink; i++) {
if (metaElements[i].getAttribute('property') == 'og:url') {
canonicalLink = metaElements[i].content;
}
}
}

return {
url: getUrl(refererInfo),
canonicalLink: canonicalLink,
ref: getReferrer(),
};
}

function getMetaElements() {
try {
return getWindowTop.document.getElementsByTagName('meta');
} catch (e) {
return document.getElementsByTagName('meta');
}
}

function getUrl(refererInfo) {
if (refererInfo && refererInfo.referer) {
return refererInfo.referer;
}

try {
return window.top.location.href;
return getWindowTop.location.href;
} catch (e) {
return window.location.href;
return getWindowLocation.href;
}
}

function getReferrer() {
try {
return window.top.document.referrer;
return getWindowTop.document.referrer;
} catch (e) {
return document.referrer;
}
Expand Down
23 changes: 15 additions & 8 deletions test/spec/modules/gmosspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('GmosspAdapter', function () {

describe('buildRequests', function () {
const storage = getStorageManager();
const bidRequests = [
let bidRequests = [
{
bidder: 'gmossp',
params: {
Expand All @@ -52,7 +52,14 @@ describe('GmosspAdapter', function () {
bidId: '2b84475b5b636e',
bidderRequestId: '1f4001782ac16c',
auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff',
transactionId: '791e9d84-af92-4903-94da-24c7426d9d0c'
transactionId: '791e9d84-af92-4903-94da-24c7426d9d0c',
userId: {
imuid: 'h.0a4749e7ffe09fa6',
sharedid: {
id: '1111'
},
idl_env: '1111',
}
}
];

Expand All @@ -62,21 +69,21 @@ describe('GmosspAdapter', function () {
referer: 'https://hoge.com'
}
};
storage.setCookie('_im_uid.1000283', 'h.0a4749e7ffe09fa6');

const requests = spec.buildRequests(bidRequests, bidderRequest);
expect(requests[0].url).to.equal(ENDPOINT);
expect(requests[0].method).to.equal('GET');
expect(requests[0].data).to.equal('tid=791e9d84-af92-4903-94da-24c7426d9d0c&bid=2b84475b5b636e&ver=$prebid.version$&sid=123456&im_uid=h.0a4749e7ffe09fa6&url=https%3A%2F%2Fhoge.com&cur=JPY&dnt=0&');
expect(requests[0].data).to.equal('tid=791e9d84-af92-4903-94da-24c7426d9d0c&bid=2b84475b5b636e&ver=$prebid.version$&sid=123456&im_uid=h.0a4749e7ffe09fa6&shared_id=1111&idl_env=1111&url=https%3A%2F%2Fhoge.com&cur=JPY&dnt=0&');
});

it('should use fallback if refererInfo.referer in bid request is empty and _im_uid.1000283 cookie is empty', function () {
it('should use fallback if refererInfo.referer in bid request is empty and im_uid ,shared_id, idl_env cookie is empty', function () {
const bidderRequest = {
refererInfo: {
referer: ''
}
},
};
storage.setCookie('_im_uid.1000283', '');
bidRequests[0].userId.imuid = '';
bidRequests[0].userId.sharedid.id = '';
bidRequests[0].userId.idl_env = '';

const requests = spec.buildRequests(bidRequests, bidderRequest);
const result = 'tid=791e9d84-af92-4903-94da-24c7426d9d0c&bid=2b84475b5b636e&ver=$prebid.version$&sid=123456&url=' + encodeURIComponent(window.top.location.href) + '&cur=JPY&dnt=0&';
Expand Down