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

Gumgum Bid Adapter: support multiple GG params #7932

Merged
merged 1 commit into from
Jan 14, 2022
Merged
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
90 changes: 52 additions & 38 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 @@ -291,9 +309,9 @@ function buildRequests(validBidRequests, bidderRequest) {
} = bidRequest;
const { currency, floor } = _getFloor(mediaTypes, params.bidfloor, bidRequest);
const eids = getEids(userId);
const gpid = deepAccess(ortb2Imp, 'ext.data.pbadslot') || deepAccess(ortb2Imp, 'ext.data.adserver.adslot');
let sizes = [1, 1];
let data = {};
let gpid = '';

const date = new Date();
const lt = date.getTime();
Expand All @@ -309,12 +327,8 @@ function buildRequests(validBidRequests, bidderRequest) {
// ADTS-134 Retrieve ID envelopes
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
}
// ADJS-1024 & ADSS-1297 & ADTS-175
gpid && (data.gpid = gpid);

if (mediaTypes.banner) {
sizes = mediaTypes.banner.sizes;
Expand Down Expand Up @@ -384,7 +398,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