Skip to content

Commit

Permalink
Gumgum - ADTS-175 Support multiple GG params
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenmore committed Jan 11, 2022
1 parent eb57e90 commit 049cbeb
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 36 deletions.
90 changes: 54 additions & 36 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,48 @@ const TIME_TO_LIVE = 60
const DELAY_REQUEST_TIME = 1800000; // setting to 30 mins

let invalidRequestIds = {};
let browserParams = {};
let pageViewId = null;

// TODO: potential 0 values for browserParams sent to ad server
function _getBrowserParams(topWindowUrl) {
let topWindow
let topScreen
let topUrl
let ggad
let ns
function getNetworkSpeed() {
const connection = window.navigator && (window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection)
const Mbps = connection && (connection.downlink || connection.bandwidth)
return Mbps ? Math.round(Mbps * 1024) : null
const paramRegex = paramName => new RegExp(`[?#&](${paramName}=(.*?))($|&)`, 'i');

let browserParams = {};
let topWindow;
let topScreen;
let topUrl;
let ggad;
let ggdeal;
let ns;

function getNetworkSpeed () {
const connection = window.navigator && (window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection);
const Mbps = connection && (connection.downlink || connection.bandwidth);
return Mbps ? Math.round(Mbps * 1024) : null;
}
function getOgURL() {
let ogURL = ''
const ogURLSelector = "meta[property='og:url']"
const head = document && document.getElementsByTagName('head')[0]
const ogURLElement = head.querySelector(ogURLSelector)
ogURL = ogURLElement ? ogURLElement.content : null
return ogURL

function getOgURL () {
let ogURL = '';
const ogURLSelector = "meta[property='og:url']";
const head = document && document.getElementsByTagName('head')[0];
const ogURLElement = head.querySelector(ogURLSelector);
ogURL = ogURLElement ? ogURLElement.content : null;
return ogURL;
}
if (browserParams.vw) {
// we've already initialized browserParams, just return it.
return browserParams

function stripGGParams (url) {
const params = [
'ggad',
'ggdeal'
];

return params.reduce((result, param) => {
const matches = url.match(paramRegex(param));
if (!matches) return result;
matches[1] && (result = result.replace(matches[1], ''));
matches[3] && (result = result.replace(matches[3], ''));
return result;
}, url);
}

try {
Expand All @@ -51,31 +67,33 @@ function _getBrowserParams(topWindowUrl) {
topUrl = topWindowUrl || '';
} catch (error) {
logError(error);
return browserParams
return browserParams;
}

browserParams = {
vw: topWindow.innerWidth,
vh: topWindow.innerHeight,
sw: topScreen.width,
sh: topScreen.height,
pu: topUrl,
pu: stripGGParams(topUrl),
ce: storage.cookiesAreEnabled(),
dpr: topWindow.devicePixelRatio || 1,
jcsi: JSON.stringify(JCSI),
ogu: getOgURL()
}
};

ns = getNetworkSpeed()
ns = getNetworkSpeed();
if (ns) {
browserParams.ns = ns
browserParams.ns = ns;
}

ggad = (topUrl.match(/#ggad=(\w+)$/) || [0, 0])[1]
if (ggad) {
browserParams[isNaN(ggad) ? 'eAdBuyId' : 'adBuyId'] = ggad
}
return browserParams
ggad = (topUrl.match(paramRegex('ggad')) || [0, 0, 0])[2];
if (ggad) browserParams[isNaN(ggad) ? 'eAdBuyId' : 'adBuyId'] = ggad;

ggdeal = (topUrl.match(paramRegex('ggdeal')) || [0, 0, 0])[2];
if (ggdeal) browserParams.ggdeal = ggdeal;

return browserParams;
}

function getWrapperCode(wrapper, data) {
Expand Down Expand Up @@ -293,7 +311,7 @@ function buildRequests(validBidRequests, bidderRequest) {
const eids = getEids(userId);
let sizes = [1, 1];
let data = {};
let gpid = '';
let gpid;

const date = new Date();
const lt = date.getTime();
Expand All @@ -310,10 +328,10 @@ function buildRequests(validBidRequests, bidderRequest) {
for (const eid in eids) data[eid] = eids[eid];

// ADJS-1024 & ADSS-1297
if (deepAccess(ortb2Imp, 'ext.data.pbadslot')) {
gpid = deepAccess(ortb2Imp, 'ext.data.pbadslot')
} else if (deepAccess(ortb2Imp, 'ext.data.adserver.name')) {
gpid = ortb2Imp.ext.data.adserver.adslot
if (gpid = deepAccess(ortb2Imp, 'ext.data.pbadslot')) {
data.gpid = gpid;
} else if (gpid = deepAccess(ortb2Imp, 'ext.data.adserver.adslot')) {
data.gpid = gpid;
}

if (mediaTypes.banner) {
Expand Down Expand Up @@ -384,7 +402,7 @@ function buildRequests(validBidRequests, bidderRequest) {
sizes,
url: BID_ENDPOINT,
method: 'GET',
data: Object.assign(data, _getBrowserParams(topWindowUrl), _getDigiTrustQueryParams(userId), { gpid })
data: Object.assign(data, _getBrowserParams(topWindowUrl), _getDigiTrustQueryParams(userId))
})
});
return bids;
Expand Down
46 changes: 46 additions & 0 deletions test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,52 @@ describe('gumgumAdapter', function () {
const bidRequest = spec.buildRequests(bidRequests)[0];
expect(!!bidRequest.data.lt).to.be.true;
});

it('should handle no gg params', function () {
const bidRequest = spec.buildRequests(bidRequests, { refererInfo: { referer: 'https://www.prebid.org/?param1=foo&param2=bar&param3=baz' } })[0];

// no params are in object
expect(bidRequest.data.hasOwnProperty('eAdBuyId')).to.be.false;
expect(bidRequest.data.hasOwnProperty('adBuyId')).to.be.false;
expect(bidRequest.data.hasOwnProperty('ggdeal')).to.be.false;
});

it('should handle encrypted ad buy id', function () {
const bidRequest = spec.buildRequests(bidRequests, { refererInfo: { referer: 'https://www.prebid.org/?param1=foo&ggad=bar&param3=baz' } })[0];

// correct params are in object
expect(bidRequest.data.hasOwnProperty('eAdBuyId')).to.be.true;
expect(bidRequest.data.hasOwnProperty('adBuyId')).to.be.false;
expect(bidRequest.data.hasOwnProperty('ggdeal')).to.be.false;

// params are stripped from pu property
expect(bidRequest.data.pu.includes('ggad')).to.be.false;
});

it('should handle unencrypted ad buy id', function () {
const bidRequest = spec.buildRequests(bidRequests, { refererInfo: { referer: 'https://www.prebid.org/?param1=foo&ggad=123&param3=baz' } })[0];

// correct params are in object
expect(bidRequest.data.hasOwnProperty('eAdBuyId')).to.be.false;
expect(bidRequest.data.hasOwnProperty('adBuyId')).to.be.true;
expect(bidRequest.data.hasOwnProperty('ggdeal')).to.be.false;

// params are stripped from pu property
expect(bidRequest.data.pu.includes('ggad')).to.be.false;
});

it('should handle multiple gg params', function () {
const bidRequest = spec.buildRequests(bidRequests, { refererInfo: { referer: 'https://www.prebid.org/?ggdeal=foo&ggad=bar&param3=baz' } })[0];

// correct params are in object
expect(bidRequest.data.hasOwnProperty('eAdBuyId')).to.be.true;
expect(bidRequest.data.hasOwnProperty('adBuyId')).to.be.false;
expect(bidRequest.data.hasOwnProperty('ggdeal')).to.be.true;

// params are stripped from pu property
expect(bidRequest.data.pu.includes('ggad')).to.be.false;
expect(bidRequest.data.pu.includes('ggdeal')).to.be.false;
});
})

describe('interpretResponse', function () {
Expand Down

0 comments on commit 049cbeb

Please sign in to comment.