Skip to content

Commit

Permalink
Support Prebid.js User ID module in Sharethrough bid adapter (prebid#…
Browse files Browse the repository at this point in the history
…3819)

* Add HTML5 video support param to bid requests

* Use const instead of var for consistency

* Update supported sizes

- Default size returned changed from 0x0 to 1x1 to support PrebidServer
- Now will always respect the bid sizes supported when configured

Co-authored-by: Josh Becker <[email protected]>

* Update maintainer contact email

* Support Prebid.js User ID module

- Add support for Unified ID solution of User ID module by
  checking for `bidRequest.userId.tdid` param in `buildRequests`
  method of Sharethrough's adapter
- Update specs, maintain 80%+ code coverage

* Update logic for changing userAgent string in tests
  • Loading branch information
madma authored and Alex committed Aug 1, 2019
1 parent e28ce30 commit b4483c4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 18 deletions.
16 changes: 10 additions & 6 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const sharethroughAdapterSpec = {
isBidRequestValid: bid => !!bid.params.pkey && bid.bidder === BIDDER_CODE,

buildRequests: (bidRequests, bidderRequest) => {
return bidRequests.map(bid => {
return bidRequests.map(bidRequest => {
let query = {
placement_key: bid.params.pkey,
bidId: bid.bidId,
placement_key: bidRequest.params.pkey,
bidId: bidRequest.bidId,
consent_required: false,
instant_play_capable: canAutoPlayHTML5Video(),
hbSource: 'prebid',
Expand All @@ -30,12 +30,16 @@ export const sharethroughAdapterSpec = {
query.consent_required = !!bidderRequest.gdprConsent.gdprApplies;
}

if (bidRequest.userId && bidRequest.userId.tdid) {
query.ttduid = bidRequest.userId.tdid;
}

// Data that does not need to go to the server,
// but we need as part of interpretResponse()
const strData = {
stayInIframe: bid.params.iframe,
iframeSize: bid.params.iframeSize,
sizes: bid.sizes
stayInIframe: bidRequest.params.iframe,
iframeSize: bidRequest.params.iframeSize,
sizes: bidRequest.sizes
}

return {
Expand Down
78 changes: 66 additions & 12 deletions test/spec/modules/sharethroughBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { sharethroughAdapterSpec } from 'modules/sharethroughBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';

const spec = newBidder(sharethroughAdapterSpec).getSpec();
const bidderRequest = [
const bidRequests = [
{
bidder: 'sharethrough',
bidId: 'bidId1',
sizes: [[600, 300]],
placementCode: 'foo',
params: {
pkey: 'aaaa1111'
}
},
userId: { tdid: 'fake-tdid' }
},
{
bidder: 'sharethrough',
Expand Down Expand Up @@ -128,6 +129,12 @@ const b64EncodeUnicode = (str) => {
}));
}

const setUserAgent = (str) => {
window.navigator['__defineGetter__']('userAgent', function () {
return str;
});
}

describe('sharethrough adapter spec', function () {
describe('.code', function () {
it('should return a bidder code of sharethrough', function () {
Expand Down Expand Up @@ -157,36 +164,78 @@ describe('sharethrough adapter spec', function () {
});

it('should return true if req is correct', function () {
expect(spec.isBidRequestValid(bidderRequest[0])).to.eq(true);
expect(spec.isBidRequestValid(bidderRequest[1])).to.eq(true);
expect(spec.isBidRequestValid(bidRequests[0])).to.eq(true);
expect(spec.isBidRequestValid(bidRequests[1])).to.eq(true);
})
});

describe('.buildRequests', function () {
it('should return an array of requests', function () {
const bidRequests = spec.buildRequests(bidderRequest);
const builtBidRequests = spec.buildRequests(bidRequests);

expect(bidRequests[0].url).to.eq(
expect(builtBidRequests[0].url).to.eq(
'http://btlr.sharethrough.com/header-bid/v1');
expect(bidRequests[1].url).to.eq(
expect(builtBidRequests[1].url).to.eq(
'http://btlr.sharethrough.com/header-bid/v1')
expect(bidRequests[0].method).to.eq('GET');
expect(builtBidRequests[0].method).to.eq('GET');
});

it('should set the instant_play_capable parameter correctly based on browser userAgent string', function () {
setUserAgent('Android Chrome/60');
let builtBidRequests = spec.buildRequests(bidRequests);
expect(builtBidRequests[0].data.instant_play_capable).to.be.true;

setUserAgent('iPhone Version/11');
builtBidRequests = spec.buildRequests(bidRequests);
expect(builtBidRequests[0].data.instant_play_capable).to.be.true;

setUserAgent('iPhone CriOS/60');
builtBidRequests = spec.buildRequests(bidRequests);
expect(builtBidRequests[0].data.instant_play_capable).to.be.true;

setUserAgent('Android Chrome/50');
builtBidRequests = spec.buildRequests(bidRequests);
expect(builtBidRequests[0].data.instant_play_capable).to.be.false;

setUserAgent('Android Chrome');
builtBidRequests = spec.buildRequests(bidRequests);
expect(builtBidRequests[0].data.instant_play_capable).to.be.false;

setUserAgent(undefined);
builtBidRequests = spec.buildRequests(bidRequests);
expect(builtBidRequests[0].data.instant_play_capable).to.be.false;
});

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

it('should handle gdprConsent is present but values are undefined case', function () {
const gdprConsent = { consent_string: undefined, gdprApplies: undefined };
const fakeBidRequest = { gdprConsent: gdprConsent };
const bidRequest = spec.buildRequests(bidderRequest, fakeBidRequest)[0];
const bidderRequest = { gdprConsent: gdprConsent };
const bidRequest = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(bidRequest.data).to.not.include.any.keys('consent_string')
});

it('should add the ttduid parameter if a bid request contains a value for Unified ID from The Trade Desk', function () {
const bidRequest = spec.buildRequests(bidRequests)[0];
expect(bidRequest.data.ttduid).to.eq('fake-tdid');
});

it('should add Sharethrough specific parameters', function () {
const builtBidRequests = spec.buildRequests(bidRequests);
expect(builtBidRequests[0]).to.deep.include({
strData: {
stayInIframe: undefined,
iframeSize: undefined,
sizes: [[600, 300]]
}
});
});
});

describe('.interpretResponse', function () {
Expand Down Expand Up @@ -319,6 +368,11 @@ describe('sharethrough adapter spec', function () {
);
});

it('returns an empty array if serverResponses is empty', function () {
const syncArray = spec.getUserSyncs({ pixelEnabled: true }, []);
expect(syncArray).to.be.an('array').that.is.empty;
});

it('returns an empty array if the body is null', function () {
const syncArray = spec.getUserSyncs({ pixelEnabled: true }, [{ body: null }]);
expect(syncArray).to.be.an('array').that.is.empty;
Expand Down

0 comments on commit b4483c4

Please sign in to comment.