Skip to content

Commit

Permalink
Sonobi - Added support for getting the digitrust id (#3422)
Browse files Browse the repository at this point in the history
* added suppor for grabbing digitrust id off the window

* added digitrust support
  • Loading branch information
JonGoSonobi authored and mkendall07 committed Jan 9, 2019
1 parent 4c664e7 commit c07e60d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { config } from '../src/config';
const BIDDER_CODE = 'sonobi';
const STR_ENDPOINT = 'https://apex.go.sonobi.com/trinity.json';
const PAGEVIEW_ID = generateUUID();
const SONOBI_DIGITRUST_KEY = 'fhnS5drwmH';

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -75,6 +76,13 @@ export const spec = {
}
}

const digitrust = _getDigiTrustObject(SONOBI_DIGITRUST_KEY);

if (digitrust) {
payload.digid = digitrust.id;
payload.digkeyv = digitrust.keyv;
}

// If there is no key_maker data, then don't make the request.
if (isEmpty(data)) {
return null;
Expand Down Expand Up @@ -225,4 +233,18 @@ export function _getPlatform(context = window) {
return 'desktop';
}

// https://github.com/digi-trust/dt-cdn/wiki/Integration-Guide
function _getDigiTrustObject(key) {
function getDigiTrustId() {
let digiTrustUser = window.DigiTrust && (config.getConfig('digiTrustId') || window.DigiTrust.getUser({member: key}));
return (digiTrustUser && digiTrustUser.success && digiTrustUser.identity) || null;
}
let digiTrustId = getDigiTrustId();
// Verify there is an ID and this user has not opted out
if (!digiTrustId || (digiTrustId.privacy && digiTrustId.privacy.optout)) {
return null;
}
return digiTrustId;
}

registerBidder(spec);
41 changes: 41 additions & 0 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,47 @@ describe('SonobiBidAdapter', function () {
'stack': ['http://example.com']
}
};
it('should include the digitrust id and keyv', () => {
window.DigiTrust = {
getUser: function () {
}
};
let sandbox = sinon.sandbox.create();
sandbox.stub(window.DigiTrust, 'getUser').callsFake(() =>
({
success: true,
identity: {
id: 'Vb0YJIxTMJV4W0GHRdJ3MwyiOVYJjYEgc2QYdBSG',
keyv: 4,
version: 2,
privacy: {}
}
})
);
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
expect(bidRequests.data.digid).to.equal('Vb0YJIxTMJV4W0GHRdJ3MwyiOVYJjYEgc2QYdBSG');
expect(bidRequests.data.digkeyv).to.equal(4);
sandbox.restore();
delete window.DigiTrust;
});

it('should not include the digitrust id and keyv', () => {
window.DigiTrust = {
getUser: function () {
}
};
let sandbox = sinon.sandbox.create();
sandbox.stub(window.DigiTrust, 'getUser').callsFake(() =>
({
success: false
})
);
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
expect(bidRequests.data.digid).to.be.undefined;
expect(bidRequests.data.digkeyv).to.be.undefined;
sandbox.restore();
delete window.DigiTrust;
})

it('should return a properly formatted request', function () {
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
Expand Down

0 comments on commit c07e60d

Please sign in to comment.