Skip to content

Commit

Permalink
Use metatag position from YLHH api when available
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwatson committed Aug 26, 2022
1 parent b1e9cb5 commit 746acc5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
23 changes: 13 additions & 10 deletions modules/stroeerCoreBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,17 @@ export const spec = {
}, commonPayload);

payload.bids = bidRequests.map(bidRequest => {
const metaTagPosition = win.YLHH?.bidder?.tag?.getMetaTagPositionBy(bidRequest.adUnitCode) ?? bidRequest.adUnitCode;

const bid = {
// siz: [] - Still supported on the backend for backwards compatibility (size of banner bid)
bid: bidRequest.bidId,
sid: bidRequest.params.sid,
viz: elementInView(bidRequest.adUnitCode),
ctx: getContextFromSDG(bidRequest),
kvl: getLocalKeyValues(bidRequest.adUnitCode),
viz: elementInView(metaTagPosition),
ctx: getContextFromSDG(metaTagPosition),
kvl: getLocalKeyValues(metaTagPosition),
};

return Object.assign(bid, customAttrsFn(bidRequest));
});

Expand All @@ -277,13 +280,13 @@ export const spec = {
return result;
}

function getContextFromSDG(bidRequest) {
function getContextFromSDG(metaTagPosition) {
if (win.SDG) {
return {
position: bidRequest.adUnitCode,
adUnits: getAdUnits(bidRequest.adUnitCode),
zone: getZone(bidRequest.adUnitCode),
pageType: getPageType(bidRequest.adUnitCode),
position: metaTagPosition,
adUnits: getAdUnits(metaTagPosition),
zone: getZone(metaTagPosition),
pageType: getPageType(metaTagPosition),
}
}
}
Expand Down Expand Up @@ -339,9 +342,9 @@ export const spec = {
}
}

function getLocalKeyValues(position) {
function getLocalKeyValues(metaTagPosition) {
try {
return getValidKeyValues(win.SDG.getCN().getSlotByPosition(position).getFilteredKeyValues());
return getValidKeyValues(win.SDG.getCN().getSlotByPosition(metaTagPosition).getFilteredKeyValues());
} catch (e) {
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"execa": "^1.0.0",
"faker": "^5.5.3",
"fs.extra": "^1.3.2",
"gulp": "^4.0.2",
"gulp": "^4.0.0",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0",
"gulp-connect": "^5.7.0",
Expand Down
36 changes: 30 additions & 6 deletions test/spec/modules/stroeerCoreBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert, expect} from 'chai';
import {assert} from 'chai';
import {spec} from 'modules/stroeerCoreBidAdapter.js';
import * as utils from 'src/utils.js';
import {BANNER, VIDEO} from '../../../src/mediaTypes.js';
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('stroeerCore bid adapter', function () {
bids: [{
bidId: 'bid1',
bidder: 'stroeerCore',
adUnitCode: 'div-1',
adUnitCode: '137',
mediaTypes: {
banner: {
sizes: [[300, 600], [160, 60]]
Expand All @@ -109,7 +109,7 @@ describe('stroeerCore bid adapter', function () {
}, {
bidId: 'bid2',
bidder: 'stroeerCore',
adUnitCode: 'div-2',
adUnitCode: '248',
mediaTypes: {
banner: {
sizes: [[728, 90]],
Expand Down Expand Up @@ -204,6 +204,16 @@ describe('stroeerCore bid adapter', function () {
return response;
};

const buildFakeYLHH = (positionByAdUnitCode) => ({
bidder: {
tag: {
getMetaTagPositionBy(adUnitCode) {
return positionByAdUnitCode[adUnitCode];
}
}
}
});

const createWindow = (href, params = {}) => {
let {parent, referrer, top, frameElement, placementElements = []} = params;
const protocol = href.startsWith('https') ? 'https:' : 'http:';
Expand Down Expand Up @@ -299,7 +309,11 @@ describe('stroeerCore bid adapter', function () {
}
}
}
}
};
win.YLHH = buildFakeYLHH({
'137': 'div-1-alpha',
'248': 'div-2-alpha'
});
});

it('visibility of both slots should be determined based on SDG ad unit codes', () => {
Expand All @@ -312,7 +326,7 @@ describe('stroeerCore bid adapter', function () {
bids: [{
bidId: 'bid1',
bidder: 'stroeerCore',
adUnitCode: 'div-1-alpha',
adUnitCode: '137',
mediaTypes: {
banner: {
sizes: [[300, 600], [160, 60]],
Expand All @@ -324,7 +338,7 @@ describe('stroeerCore bid adapter', function () {
}, {
bidId: 'bid2',
bidder: 'stroeerCore',
adUnitCode: 'div-2-alpha',
adUnitCode: '248',
mediaTypes: {
banner: {
sizes: [[728, 90]],
Expand Down Expand Up @@ -549,6 +563,10 @@ describe('stroeerCore bid adapter', function () {
beforeEach(() => {
placementElements = [createElement('div-1', 17), createElement('div-2', 54)];
({topWin, win} = setupNestedWindows(sandbox, placementElements));
win.YLHH = buildFakeYLHH({
'137': 'div-1',
'248': 'div-2'
})
});

afterEach(() => {
Expand Down Expand Up @@ -742,6 +760,11 @@ describe('stroeerCore bid adapter', function () {
});
const bidReq = buildBidderRequest();

win.YLHH = buildFakeYLHH({
'137': 'div-1',
'248': 'div-2'
});

const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0];

assert.deepEqual(serverRequestInfo.data.bids[0].ctx, {
Expand All @@ -753,6 +776,7 @@ describe('stroeerCore bid adapter', function () {

assert.deepEqual(serverRequestInfo.data.bids[1].ctx, {
'position': 'div-2',

'adUnits': ['adUnit-3', 'adUnit-4', 'adUnit-5'],
'zone': 'zone-2',
'pageType': 'pageType-2'
Expand Down

0 comments on commit 746acc5

Please sign in to comment.