From 45389f040f35b40032658a9603f4589faa617d15 Mon Sep 17 00:00:00 2001 From: Ryan Chou Date: Fri, 25 May 2018 23:34:54 +0800 Subject: [PATCH] Add GDPR support for ucfunnel adapter (#2619) * Add a new ucfunnel Adapter and test page * Add a new ucfunnel Adapter and test page * 1. Use prebid lib in the repo to keep updated 2. Replace var with let 3. Put JSON.parse(JSON.stringify()) into try catch block * utils.getTopWindowLocation is a function * Change to modules from adapters * Migrate to module design * [Dev Fix] Remove width and height which can be got from ad unit id * Update ucfunnelBidAdapter to fit into new spec * Correct the endpoint. Fix the error of query string * Add test case for ucfunnelBidAdapter * Fix lint error * Update version number * Combine all checks on bid request * Add GDPR support for ucfunnel adapter --- modules/ucfunnelBidAdapter.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/ucfunnelBidAdapter.js b/modules/ucfunnelBidAdapter.js index 7f652e38c3d0..c9548a280a02 100644 --- a/modules/ucfunnelBidAdapter.js +++ b/modules/ucfunnelBidAdapter.js @@ -19,16 +19,16 @@ export const spec = { }, /** - * Format the bid request object for our endpoint - * @param {BidRequest[]} bidRequests Array of ucfunnel bidders - * @return object of parameters for Prebid AJAX request + * @param {BidRequest[]} bidRequests + * @param {*} bidderRequest + * @return {ServerRequest} */ - buildRequests: function(validBidRequests) { + buildRequests: function(validBidRequests, bidderRequest) { var bidRequests = []; for (var i = 0; i < validBidRequests.length; i++) { var bid = validBidRequests[i]; - var ucfunnelUrlParams = buildUrlParams(bid); + var ucfunnelUrlParams = buildUrlParams(bid, bidderRequest); bidRequests.push({ method: 'GET', @@ -69,7 +69,7 @@ export const spec = { }; registerBidder(spec); -function buildUrlParams(bid) { +function buildUrlParams(bid, bidderRequest) { const host = utils.getTopWindowLocation().host; const page = utils.getTopWindowLocation().pathname; const refer = document.referrer; @@ -88,6 +88,11 @@ function buildUrlParams(bid) { 'ver', VER ]; + if (bidderRequest && bidderRequest.gdprConsent) { + queryString.push('gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0); + queryString.push('euconsent', bidderRequest.gdprConsent.consentString); + } + return queryString.reduce( (memo, curr, index) => index % 2 === 0 && queryString[index + 1] !== undefined ? memo + curr + '=' + encodeURIComponent(queryString[index + 1]) + '&' : memo, ''