From 746acc5558087cacc9aab9079957e65bfc375c77 Mon Sep 17 00:00:00 2001 From: Philip Watson Date: Fri, 26 Aug 2022 14:46:44 +1200 Subject: [PATCH] Use metatag position from YLHH api when available --- modules/stroeerCoreBidAdapter.js | 23 ++++++------ package.json | 2 +- .../modules/stroeerCoreBidAdapter_spec.js | 36 +++++++++++++++---- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/modules/stroeerCoreBidAdapter.js b/modules/stroeerCoreBidAdapter.js index 8fdf4b29fc3..fe9f99a0562 100644 --- a/modules/stroeerCoreBidAdapter.js +++ b/modules/stroeerCoreBidAdapter.js @@ -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)); }); @@ -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), } } } @@ -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; } diff --git a/package.json b/package.json index 0f9a420aac6..07814d782ee 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/spec/modules/stroeerCoreBidAdapter_spec.js b/test/spec/modules/stroeerCoreBidAdapter_spec.js index 06367d865d0..c77755c73a5 100644 --- a/test/spec/modules/stroeerCoreBidAdapter_spec.js +++ b/test/spec/modules/stroeerCoreBidAdapter_spec.js @@ -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'; @@ -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]] @@ -109,7 +109,7 @@ describe('stroeerCore bid adapter', function () { }, { bidId: 'bid2', bidder: 'stroeerCore', - adUnitCode: 'div-2', + adUnitCode: '248', mediaTypes: { banner: { sizes: [[728, 90]], @@ -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:'; @@ -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', () => { @@ -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]], @@ -324,7 +338,7 @@ describe('stroeerCore bid adapter', function () { }, { bidId: 'bid2', bidder: 'stroeerCore', - adUnitCode: 'div-2-alpha', + adUnitCode: '248', mediaTypes: { banner: { sizes: [[728, 90]], @@ -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(() => { @@ -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, { @@ -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'