Skip to content

Commit

Permalink
Update ucfunnelBidAdapter (prebid#6157)
Browse files Browse the repository at this point in the history
* support TCFv2.0
* support coppa
* support Publisher Domain
* support meta.mediaType and meta.advertiserDomains
* test parameters for validating bids

Co-authored-by: root <root@ubuntu.members.linode.com>
Co-authored-by: Ryan Chou <ryanchou0210@gmail.com>
Co-authored-by: jack.hsieh <moonnight8520@gmail.com>
  • Loading branch information
4 people authored and GeneGenie committed Jan 13, 2021
1 parent 9a4dbd1 commit 1eb20a9
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 19 deletions.
104 changes: 91 additions & 13 deletions modules/ucfunnelBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
ENDPOINT: 'https://hb.aralego.com/header',
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
/**
Expand Down Expand Up @@ -65,18 +67,23 @@ 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) {
bid.cpm = 0;
}
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) {
Expand Down Expand Up @@ -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)
}];
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
31 changes: 25 additions & 6 deletions test/spec/modules/ucfunnelBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
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';

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: {
Expand All @@ -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,
Expand Down Expand Up @@ -50,7 +61,8 @@ const validBannerBidRes = {
adm: '<html style="height:100%"><body style="width:300px;height: 100%;padding:0;margin:0 auto;"><div style="width:100%;height:100%;display:table;"><div style="width:100%;height:100%;display:table-cell;text-align:center;vertical-align:middle;"><a href="//www.ucfunnel.com/" target="_blank"><img src="//cdn.aralego.net/ucfad/house/ucf/AdGent-300x250.jpg" width="300px" height="250px" align="middle" style="border:none"></a></div></div></body></html>',
cpm: 1.01,
height: 250,
width: 300
width: 300,
crid: 'test-crid'
};

const invalidBannerBidRes = '';
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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&');
});
});
});
Expand Down

0 comments on commit 1eb20a9

Please sign in to comment.