Skip to content

Commit

Permalink
Trion gdpr and usp consent (#4740)
Browse files Browse the repository at this point in the history
* Adding files associated with the trion adapter update to the newest prebid version(1.0).

* Updating pull request with safer checks for user sync and general clean up/consistency of tests.

* removing a call to bidder code for pull request review.  also removing the test that requires it

* there were some changes to the bid factory after our initial release that we didn't account for.  Changing adapter to account for response body and required params.

* Revert "there were some changes to the bid factory after our initial release that we didn't account for.  Changing adapter to account for response body and required params."

This reverts commit 324d157.

* there were some changes to the bid factory after our initial release that we didn't account for.  Changing adapter to account for response body and required params.

* adding safety checks to Trion adapter

* Sending up to trion endpoint if there is bot traffic or the browser tab is not visible.

* sending the wrong param in the test.

* Trion test cleanup.  returning document and window states to their original form after tests.

* Trion test cleanup.  using before and after to alter window and document objects in tests.

* re-adding trion adapter to prebid project to stop using deprecated function for page url for 3.0 release

* minor formatting change

* accept size array from media types banner over the sizes array from pubs.

* updating trion bid adapter to be us privacy and gdpr compliant

* encoding consent strings for test
  • Loading branch information
grohm33 authored and bretg committed Jan 21, 2020
1 parent d67768b commit 1373313
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 8 deletions.
37 changes: 29 additions & 8 deletions modules/trionBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const spec = {
isBidRequestValid: function (bid) {
return !!(bid && bid.params && bid.params.pubId && bid.params.sectionId);
},
buildRequests: function (validBidRequests) {
buildRequests: function (validBidRequests, bidderRequest) {
var bidRequests = [];

for (var i = 0; i < validBidRequests.length; i++) {
var bid = validBidRequests[i];

var trionUrlParams = buildTrionUrlParams(bid);
var trionUrlParams = buildTrionUrlParams(bid, bidderRequest);

bidRequests.push({
method: 'GET',
Expand Down Expand Up @@ -56,26 +56,36 @@ export const spec = {

return bidResponses;
},
getUserSyncs: function getUserSyncs(syncOptions) {
getUserSyncs: function getUserSyncs(syncOptions, serverResponses, gdprConsent, usPrivacy) {
if (syncOptions.iframeEnabled) {
handlePostMessage();
return [{
type: 'iframe',
url: getSyncUrl()
url: getSyncUrl(gdprConsent, usPrivacy)
}];
}
}

};
registerBidder(spec);

function getSyncUrl() {
function getSyncUrl(gdprConsent, usPrivacy) {
var unParsedPubAndSection = getStorageData(BASE_KEY + 'lps') || ':';
var pubSectionArray = unParsedPubAndSection.split(':') || [];
var pubId = pubSectionArray[0] || -1;
var sectionId = pubSectionArray[1] || -1;
var url = getPublisherUrl();
return USER_SYNC_URL + `?p=${pubId}&s=${sectionId}&u=${url}`;
var consentParams = '';
if (gdprConsent) {
if (gdprConsent.consentString) {
consentParams += '&gc=' + encodeURIComponent(gdprConsent.consentString);
}
consentParams += '&g=' + (gdprConsent.gdprApplies ? 1 : 0);
}
if (usPrivacy) {
consentParams = '&up=' + encodeURIComponent(usPrivacy);
}
return USER_SYNC_URL + `?p=${pubId}&s=${sectionId}${consentParams}&u=${url}`;
}

function getPublisherUrl() {
Expand All @@ -95,7 +105,7 @@ function getPublisherUrl() {
return url
}

function buildTrionUrlParams(bid) {
function buildTrionUrlParams(bid, bidderRequest) {
var pubId = utils.getBidIdParameter('pubId', bid.params);
var sectionId = utils.getBidIdParameter('sectionId', bid.params);
var re = utils.getBidIdParameter('re', bid.params);
Expand Down Expand Up @@ -132,7 +142,18 @@ function buildTrionUrlParams(bid) {
trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_wd', isAutomated);
trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_hd', isHidden);
trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_vs', visibilityState);

if (bidderRequest && bidderRequest.gdprConsent) {
var gdpr = bidderRequest.gdprConsent;
if (gdpr) {
if (gdpr.consentString) {
trionUrl = utils.tryAppendQueryString(trionUrl, 'gdprc', encodeURIComponent(gdpr.consentString));
}
trionUrl = utils.tryAppendQueryString(trionUrl, 'gdpr', (gdpr.gdprApplies ? 1 : 0));
}
}
if (bidderRequest && bidderRequest.uspConsent) {
trionUrl = utils.tryAppendQueryString(trionUrl, 'usp', encodeURIComponent(bidderRequest.uspConsent));
}
// remove the trailing "&"
if (trionUrl.lastIndexOf('&') === trionUrl.length - 1) {
trionUrl = trionUrl.substring(0, trionUrl.length - 1);
Expand Down
56 changes: 56 additions & 0 deletions test/spec/modules/trionBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ const TRION_BID = {

const TRION_BID_REQUEST = [TRION_BID];

const TRION_BIDDER_REQUEST = {
'bidderCode': 'trion',
'auctionId': '12345',
'bidderRequestId': 'abc1234',
'bids': TRION_BID_REQUEST
};

const TRION_BID_RESPONSE = {
bidId: 'test-bid-id',
sizes: [[300, 250], [300, 600]],
Expand Down Expand Up @@ -197,6 +204,30 @@ describe('Trion adapter tests', function () {
expect(bidUrlParams).to.include('tr_vs=hidden');
});
});

describe('should call buildRequests with correct consent params', function () {
it('when gdpr is present', function () {
TRION_BIDDER_REQUEST.gdprConsent = {
consentString: 'test_gdpr_str',
gdprApplies: true
};
let bidRequests = spec.buildRequests(TRION_BID_REQUEST, TRION_BIDDER_REQUEST);
let bidUrlParams = bidRequests[0].data;
let gcEncoded = encodeURIComponent(TRION_BIDDER_REQUEST.gdprConsent.consentString);
expect(bidUrlParams).to.include('gdprc=' + gcEncoded);
expect(bidUrlParams).to.include('gdpr=1');
delete TRION_BIDDER_REQUEST.gdprConsent;
});

it('when us privacy is present', function () {
TRION_BIDDER_REQUEST.uspConsent = '1YYY';
let bidRequests = spec.buildRequests(TRION_BID_REQUEST, TRION_BIDDER_REQUEST);
let bidUrlParams = bidRequests[0].data;
let uspEncoded = encodeURIComponent(TRION_BIDDER_REQUEST.uspConsent);
expect(bidUrlParams).to.include('usp=' + uspEncoded);
delete TRION_BIDDER_REQUEST.uspConsent;
});
});
});

describe('interpretResponse', function () {
Expand Down Expand Up @@ -275,6 +306,31 @@ describe('Trion adapter tests', function () {
expect(syncs[0]).to.deep.equal({type: 'iframe', url: USER_SYNC_URL + syncString});
});

it('should register trion user script with gdpr params', function () {
let gdprConsent = {
consentString: 'test_gdpr_str',
gdprApplies: true
};
let syncs = spec.getUserSyncs({iframeEnabled: true}, null, gdprConsent);
let pageUrl = getPublisherUrl();
let pubId = 1;
let sectionId = 2;
let gcEncoded = encodeURIComponent(gdprConsent.consentString);
let syncString = `?p=${pubId}&s=${sectionId}&gc=${gcEncoded}&g=1&u=${pageUrl}`;
expect(syncs[0]).to.deep.equal({type: 'iframe', url: USER_SYNC_URL + syncString});
});

it('should register trion user script with us privacy params', function () {
let uspConsent = '1YYY';
let syncs = spec.getUserSyncs({iframeEnabled: true}, null, null, uspConsent);
let pageUrl = getPublisherUrl();
let pubId = 1;
let sectionId = 2;
let uspEncoded = encodeURIComponent(uspConsent);
let syncString = `?p=${pubId}&s=${sectionId}&up=${uspEncoded}&u=${pageUrl}`;
expect(syncs[0]).to.deep.equal({type: 'iframe', url: USER_SYNC_URL + syncString});
});

it('should except posted messages from user sync script', function () {
let testId = 'testId';
let message = BASE_KEY + 'userId=' + testId;
Expand Down

0 comments on commit 1373313

Please sign in to comment.