From 1eb20a9885ed947a0a9da33015a70730d8d5534a Mon Sep 17 00:00:00 2001 From: ucfunnel <39581136+ucfunnel@users.noreply.github.com> Date: Fri, 8 Jan 2021 23:39:34 +0800 Subject: [PATCH] Update ucfunnelBidAdapter (#6157) * support TCFv2.0 * support coppa * support Publisher Domain * support meta.mediaType and meta.advertiserDomains * test parameters for validating bids Co-authored-by: root Co-authored-by: Ryan Chou Co-authored-by: jack.hsieh --- modules/ucfunnelBidAdapter.js | 104 ++++++++++++++++--- test/spec/modules/ucfunnelBidAdapter_spec.js | 31 ++++-- 2 files changed, 116 insertions(+), 19 deletions(-) diff --git a/modules/ucfunnelBidAdapter.js b/modules/ucfunnelBidAdapter.js index f9982edef36d..d54ad7fb0ee3 100644 --- a/modules/ucfunnelBidAdapter.js +++ b/modules/ucfunnelBidAdapter.js @@ -1,12 +1,13 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js'; import { getStorageManager } from '../src/storageManager.js'; +import { config } from '../src/config.js'; import * as utils from '../src/utils.js'; const storage = getStorageManager(); const COOKIE_NAME = 'ucf_uid'; const VER = 'ADGENT_PREBID-2018011501'; const BIDDER_CODE = 'ucfunnel'; - +const GVLID = 607; const VIDEO_CONTEXT = { INSTREAM: 0, OUSTREAM: 2 @@ -14,6 +15,7 @@ const VIDEO_CONTEXT = { export const spec = { code: BIDDER_CODE, + gvlid: GVLID, ENDPOINT: 'https://hb.aralego.com/header', supportedMediaTypes: [BANNER, VIDEO, NATIVE], /** @@ -65,11 +67,12 @@ export const spec = { let bid = { requestId: bidRequest.bidId, cpm: ad.cpm || 0, - creativeId: ad.ad_id || bidRequest.params.adid, + creativeId: ad.crid || ad.ad_id || bidRequest.params.adid, dealId: ad.deal || null, currency: 'USD', netRevenue: true, - ttl: 1800 + ttl: 1800, + meta: {} }; if (bidRequest.params && bidRequest.params.bidfloor && ad.cpm && ad.cpm < bidRequest.params.bidfloor) { @@ -77,6 +80,10 @@ export const spec = { } if (ad.creative_type) { bid.mediaType = ad.creative_type; + bid.meta.mediaType = ad.creative_type; + } + if (ad.adomain) { + bid.meta.advertiserDomains = ad.adomain; } switch (ad.creative_type) { @@ -124,16 +131,19 @@ export const spec = { return [bid]; }, - getUserSyncs: function(syncOptions) { + getUserSyncs: function(syncOptions, serverResponses, gdprConsent = {}, uspConsent) { + let gdprApplies = (gdprConsent && gdprConsent.gdprApplies) ? '1' : ''; + let apiVersion = (gdprConsent) ? gdprConsent.apiVersion : ''; + let consentString = (gdprConsent) ? gdprConsent.consentString : ''; if (syncOptions.iframeEnabled) { return [{ type: 'iframe', - url: 'https://cdn.aralego.net/ucfad/cookie/sync.html' + url: 'https://cdn.aralego.net/ucfad/cookie/sync.html' + getCookieSyncParameter(gdprApplies, apiVersion, consentString, uspConsent) }]; } else if (syncOptions.pixelEnabled) { return [{ type: 'image', - url: 'https://sync.aralego.com/idSync' + url: 'https://sync.aralego.com/idSync' + getCookieSyncParameter(gdprApplies, apiVersion, consentString, uspConsent) }]; } } @@ -146,6 +156,22 @@ function transformSizes(requestSizes) { } } +function getCookieSyncParameter(gdprApplies, apiVersion, consentString, uspConsent) { + let param = '?'; + if (gdprApplies == '1') { + param = param + 'gdpr=1&'; + } + if (apiVersion == 1) { + param = param + 'euconsent=' + consentString + '&'; + } else if (apiVersion == 2) { + param = param + 'euconsent-v2=' + consentString + '&'; + } + if (uspConsent) { + param = param + 'usprivacy=' + uspConsent; + } + return (param == '?') ? '' : param; +} + function parseSizes(bid) { let params = bid.params; if (bid.mediaType === VIDEO) { @@ -202,14 +228,14 @@ function getRequestData(bid, bidderRequest) { schain: supplyChain, fp: bid.params.bidfloor }; - + addUserId(bidData, bid.userId); try { bidData.host = window.top.location.hostname; - bidData.u = window.top.location.href; + bidData.u = config.getConfig('publisherDomain') || window.top.location.href; bidData.xr = 0; } catch (e) { bidData.host = window.location.hostname; - bidData.u = document.referrer || window.location.href; + bidData.u = config.getConfig('publisherDomain') || bidderRequest.refererInfo.referrer || document.referrer || window.location.href; bidData.xr = 1; } @@ -253,11 +279,63 @@ function getRequestData(bid, bidderRequest) { } if (bidderRequest && bidderRequest.gdprConsent) { - Object.assign(bidData, { - gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0, - euconsent: bidderRequest.gdprConsent.consentString - }); + if (bidderRequest.gdprConsent.apiVersion == 1) { + Object.assign(bidData, { + gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0, + euconsent: bidderRequest.gdprConsent.consentString + }); + } else if (bidderRequest.gdprConsent.apiVersion == 2) { + Object.assign(bidData, { + gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0, + 'euconsent-v2': bidderRequest.gdprConsent.consentString + }); + } + } + + if (config.getConfig('coppa')) { + bidData.coppa = true; } return bidData; } + +function addUserId(bidData, userId) { + utils._each(userId, (userIdObjectOrValue, userIdProviderKey) => { + switch (userIdProviderKey) { + case 'sharedid': + if (userIdObjectOrValue.id) { + bidData[userIdProviderKey + '_id'] = userIdObjectOrValue.id; + } + if (userIdObjectOrValue.third) { + bidData[userIdProviderKey + '_third'] = userIdObjectOrValue.third; + } + break; + case 'haloId': + if (userIdObjectOrValue.haloId) { + bidData[userIdProviderKey + 'haloId'] = userIdObjectOrValue.haloId; + } + if (userIdObjectOrValue.auSeg) { + bidData[userIdProviderKey + '_auSeg'] = userIdObjectOrValue.auSeg; + } + break; + case 'parrableId': + if (userIdObjectOrValue.eid) { + bidData[userIdProviderKey + '_eid'] = userIdObjectOrValue.eid; + } + break; + case 'id5id': + if (userIdObjectOrValue.uid) { + bidData[userIdProviderKey + '_uid'] = userIdObjectOrValue.uid; + } + if (userIdObjectOrValue.ext && userIdObjectOrValue.ext.linkType) { + bidData[userIdProviderKey + '_linkType'] = userIdObjectOrValue.ext.linkType; + } + break; + default: + bidData[userIdProviderKey] = userIdObjectOrValue; + break; + } + }); + + return bidData; +} diff --git a/test/spec/modules/ucfunnelBidAdapter_spec.js b/test/spec/modules/ucfunnelBidAdapter_spec.js index b5f29287f818..a2939eb95c31 100644 --- a/test/spec/modules/ucfunnelBidAdapter_spec.js +++ b/test/spec/modules/ucfunnelBidAdapter_spec.js @@ -1,7 +1,6 @@ import { expect } from 'chai'; import { spec } from 'modules/ucfunnelBidAdapter.js'; import {BANNER, VIDEO, NATIVE} from 'src/mediaTypes.js'; - const URL = 'https://hb.aralego.com/header'; const BIDDER_CODE = 'ucfunnel'; @@ -9,6 +8,17 @@ const bidderRequest = { uspConsent: '1YNN' }; +const userId = { + 'criteoId': 'vYlICF9oREZlTHBGRVdrJTJCUUJnc3U2ckNVaXhrV1JWVUZVSUxzZmJlcnJZR0ZxbVhFRnU5bDAlMkJaUWwxWTlNcmdEeHFrJTJGajBWVlV4T3lFQ0FyRVcxNyUyQlIxa0lLSlFhcWJpTm9PSkdPVkx0JTJCbzlQRTQlM0Q', + 'id5id': {'uid': 'ID5-8ekgswyBTQqnkEKy0ErmeQ1GN5wV4pSmA-RE4eRedA'}, + 'netId': 'fH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg', + 'parrableId': {'eid': '01.1608624401.fe44bca9b96873084a0d4e9d0ac5729f13790ba8f8e58fa4707b6b3c096df91c6b5f254992bdad4ab1dd4a89919081e9b877d7a039ac3183709277665bac124f28e277d109f0ff965058'}, + 'pubcid': 'd8aa10fa-d86c-451d-aad8-5f16162a9e64', + 'sharedid': {'id': '01ESHXW4HD29KMF387T63JQ9H5', 'third': '01ESHXW4HD29KMF387T63JQ9H5'}, + 'tdid': 'D6885E90-2A7A-4E0F-87CB-7734ED1B99A3', + 'haloId': {} +} + const validBannerBidReq = { bidder: BIDDER_CODE, params: { @@ -18,6 +28,7 @@ const validBannerBidReq = { sizes: [[300, 250]], bidId: '263be71e91dd9d', auctionId: '9ad1fa8d-2297-4660-a018-b39945054746', + userId: userId, 'schain': { 'ver': '1.0', 'complete': 1, @@ -50,7 +61,8 @@ const validBannerBidRes = { adm: '
', cpm: 1.01, height: 250, - width: 300 + width: 300, + crid: 'test-crid' }; const invalidBannerBidRes = ''; @@ -112,6 +124,13 @@ const validNativeBidRes = { width: 1 }; +const gdprConsent = { + consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', + vendorData: {}, + gdprApplies: true, + apiVersion: 2 +}; + describe('ucfunnel Adapter', function () { describe('request', function () { it('should validate bid request', function () { @@ -253,18 +272,18 @@ describe('ucfunnel Adapter', function () { describe('cookie sync', function () { describe('cookie sync iframe', function () { - const result = spec.getUserSyncs({'iframeEnabled': true}); + const result = spec.getUserSyncs({'iframeEnabled': true}, null, gdprConsent); it('should return cookie sync iframe info', function () { expect(result[0].type).to.equal('iframe'); - expect(result[0].url).to.equal('https://cdn.aralego.net/ucfad/cookie/sync.html'); + expect(result[0].url).to.equal('https://cdn.aralego.net/ucfad/cookie/sync.html?gdpr=1&euconsent-v2=CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA&'); }); }); describe('cookie sync image', function () { - const result = spec.getUserSyncs({'pixelEnabled': true}); + const result = spec.getUserSyncs({'pixelEnabled': true}, null, gdprConsent); it('should return cookie sync image info', function () { expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://sync.aralego.com/idSync'); + expect(result[0].url).to.equal('https://sync.aralego.com/idSync?gdpr=1&euconsent-v2=CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA&'); }); }); });