diff --git a/modules/gmosspBidAdapter.js b/modules/gmosspBidAdapter.js index fac19896177..2d11a1eec57 100644 --- a/modules/gmosspBidAdapter.js +++ b/modules/gmosspBidAdapter.js @@ -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, @@ -34,7 +31,6 @@ 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 = ''; @@ -42,6 +38,9 @@ export const spec = { 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); @@ -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); @@ -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; @@ -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; } diff --git a/test/spec/modules/gmosspBidAdapter_spec.js b/test/spec/modules/gmosspBidAdapter_spec.js index c22badb9b4c..df617b62ba6 100644 --- a/test/spec/modules/gmosspBidAdapter_spec.js +++ b/test/spec/modules/gmosspBidAdapter_spec.js @@ -37,7 +37,7 @@ describe('GmosspAdapter', function () { describe('buildRequests', function () { const storage = getStorageManager(); - const bidRequests = [ + let bidRequests = [ { bidder: 'gmossp', params: { @@ -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', + } } ]; @@ -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&';