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

Sharethrough: GDPR compliance + getUserSyncs #2503

Merged
merged 1 commit into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 27 additions & 9 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,32 @@ const STR_ENDPOINT = document.location.protocol + '//btlr.sharethrough.com/heade
export const sharethroughAdapterSpec = {
code: BIDDER_CODE,
isBidRequestValid: bid => !!bid.params.pkey && bid.bidder === BIDDER_CODE,
buildRequests: (bidRequests) => {
buildRequests: (bidRequests, bidderRequest) => {
return bidRequests.map(bid => {
let query = {
bidId: bid.bidId,
placement_key: bid.params.pkey,
hbVersion: '$prebid.version$',
strVersion: VERSION,
hbSource: 'prebid'
};

if (bidderRequest && bidderRequest.gdprConsent) {
query.consent_string = bidderRequest.gdprConsent.consentString;
query.consent_required = bidderRequest.gdprConsent.gdprApplies;
}

return {
method: 'GET',
url: STR_ENDPOINT,
data: {
bidId: bid.bidId,
placement_key: bid.params.pkey,
hbVersion: '$prebid.version$',
strVersion: VERSION,
hbSource: 'prebid'
}
data: query
};
})
},
interpretResponse: ({ body }, req) => {
if (!Object.keys(body).length) return [];
if (!body || !Object.keys(body).length || !body.creatives.length) {
return [];
}

const creative = body.creatives[0];

Expand All @@ -39,6 +48,15 @@ export const sharethroughAdapterSpec = {
ttl: 360,
ad: generateAd(body, req)
}];
},
getUserSyncs: (syncOptions, serverResponses) => {
const syncs = [];
if (syncOptions.pixelEnabled && serverResponses.length > 0) {
serverResponses[0].body.cookieSyncUrls.forEach(url => {
syncs.push({ type: 'image', url: url });
});
}
return syncs;
}
}

Expand Down
42 changes: 42 additions & 0 deletions test/spec/modules/sharethroughBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ describe('sharethrough adapter spec', () => {
'http://btlr.sharethrough.com/header-bid/v1')
expect(bidRequests[0].method).to.eq('GET');
});

it('should add consent parameters if gdprConsent is present', () => {
const gdprConsent = { consentString: 'consent_string123', gdprApplies: true };
const fakeBidRequest = { gdprConsent: gdprConsent };
const bidRequest = spec.buildRequests(bidderRequest, fakeBidRequest)[0];
expect(bidRequest.data.consent_string).to.eq('consent_string123');
expect(bidRequest.data.consent_required).to.eq(true);
});
});

describe('.interpretResponse', () => {
Expand All @@ -117,6 +125,21 @@ describe('sharethrough adapter spec', () => {
});
});

it('returns a blank array if there are no creatives', () => {
const bidResponse = { body: { creatives: [] } };
expect(spec.interpretResponse(bidResponse, prebidRequest[0])).to.be.an('array').that.is.empty;
});

it('returns a blank array if body object is empty', () => {
const bidResponse = { body: {} };
expect(spec.interpretResponse(bidResponse, prebidRequest[0])).to.be.an('array').that.is.empty;
});

it('returns a blank array if body is null', () => {
const bidResponse = { body: null };
expect(spec.interpretResponse(bidResponse, prebidRequest[0])).to.be.an('array').that.is.empty;
});

it('correctly sends back a sfp script tag', () => {
const adMarkup = spec.interpretResponse(bidderResponse, prebidRequest[0])[0].ad;
let resp = null;
Expand All @@ -134,4 +157,23 @@ describe('sharethrough adapter spec', () => {
/window.top.document.getElementsByTagName\('body'\)\[0\].appendChild\(sfp_js\);/)
});
});

describe('.getUserSyncs', () => {
const cookieSyncs = ['cookieUrl1', 'cookieUrl2', 'cookieUrl3'];
const serverResponses = [{ body: { cookieSyncUrls: cookieSyncs } }];

it('returns an array of correctly formatted user syncs', () => {
const syncArray = spec.getUserSyncs({ pixelEnabled: true }, serverResponses);
expect(syncArray).to.deep.equal([
{ type: 'image', url: 'cookieUrl1' },
{ type: 'image', url: 'cookieUrl2' },
{ type: 'image', url: 'cookieUrl3' }]
);
});

it('returns an empty array if pixels are not enabled', () => {
const syncArray = spec.getUserSyncs({ pixelEnabled: false }, serverResponses);
expect(syncArray).to.be.an('array').that.is.empty;
});
});
});