Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trion gdpr and usp consent #4740

Merged
merged 26 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
21bab6b
Adding files associated with the trion adapter update to the newest p…
Oct 17, 2017
fae1208
Merge branch 'master' into master
grohm33 Oct 17, 2017
3abcf64
Updating pull request with safer checks for user sync and general cle…
Oct 18, 2017
0c040fc
removing a call to bidder code for pull request review. also removin…
Nov 13, 2017
40444f7
Merge remote-tracking branch 'upstream/master'
Nov 13, 2017
324d157
there were some changes to the bid factory after our initial release …
Dec 5, 2017
bb5f8c7
Revert "there were some changes to the bid factory after our initial …
Dec 5, 2017
8d40681
Merge remote-tracking branch 'upstream/master'
Dec 5, 2017
8d67f63
there were some changes to the bid factory after our initial release …
Dec 5, 2017
6f213fb
Merge remote-tracking branch 'upstream/master'
Feb 8, 2019
c734aff
adding safety checks to Trion adapter
Feb 8, 2019
2bc52cf
Merge remote-tracking branch 'upstream/master'
Nov 26, 2019
29320de
Sending up to trion endpoint if there is bot traffic or the browser t…
Dec 2, 2019
f0c2028
sending the wrong param in the test.
Dec 2, 2019
2e4b257
Merge remote-tracking branch 'upstream/master'
Dec 2, 2019
5546465
Merge remote-tracking branch 'upstream/master'
Dec 3, 2019
3322fd4
Trion test cleanup. returning document and window states to their or…
Dec 9, 2019
4521bf0
Trion test cleanup. using before and after to alter window and docum…
Dec 9, 2019
d36ba3b
Merge remote-tracking branch 'upstream/master'
Dec 13, 2019
d408b9c
re-adding trion adapter to prebid project to stop using deprecated fu…
Dec 13, 2019
abe60af
minor formatting change
Dec 16, 2019
a8cd6af
accept size array from media types banner over the sizes array from p…
Dec 16, 2019
2bd5be7
Merge remote-tracking branch 'upstream/master'
Jan 14, 2020
914150a
updating trion bid adapter to be us privacy and gdpr compliant
Jan 16, 2020
cc017f9
encoding consent strings for test
Jan 16, 2020
61dd262
Merge remote-tracking branch 'upstream/master'
Jan 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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