Skip to content

Commit

Permalink
C Wire Adapter: Add support for user-syncs (c-wire/prebid#8) (prebid#…
Browse files Browse the repository at this point in the history
  • Loading branch information
espen-j authored and Santiago Carabone committed Aug 22, 2023
1 parent 6cd7f64 commit 97689eb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/cwireBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getStorageManager} from '../src/storageManager.js';
import {BANNER} from '../src/mediaTypes.js';
import {generateUUID, getParameterByName, isNumber, logError, logInfo} from '../src/utils.js';
import {hasPurpose1Consent} from '../src/utils/gpdr.js';

// ------------------------------------
const BIDDER_CODE = 'cwire';
Expand Down Expand Up @@ -230,5 +231,23 @@ export const spec = {
navigator.sendBeacon(EVENT_ENDPOINT, JSON.stringify(event))
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
logInfo('Collecting user-syncs: ', JSON.stringify({syncOptions, gdprConsent, uspConsent, serverResponses}));

const syncs = []
if (hasPurpose1Consent(gdprConsent)) {
logInfo('GDPR purpose 1 consent was given, adding user-syncs')
let type = (syncOptions.pixelEnabled) ? 'image' : null ?? (syncOptions.iframeEnabled) ? 'iframe' : null
if (type) {
syncs.push({
type: type,
url: 'https://ib.adnxs.com/getuid?https://prebid.cwi.re/v1/cookiesync?xandrId=$UID'
})
}
}
logInfo('Collected user-syncs: ', JSON.stringify({syncs}))
return syncs
}

};
registerBidder(spec);
47 changes: 47 additions & 0 deletions test/spec/modules/cwireBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,51 @@ describe('C-WIRE bid adapter', () => {
expect(bids[0].ad).to.exist;
})
});

describe('add user-syncs', function () {
it('empty user-syncs if no consent given', function () {
const userSyncs = spec.getUserSyncs({}, {}, {}, {});

expect(userSyncs).to.be.empty
})
it('empty user-syncs if no syncOption enabled', function () {
let gdprConsent = {
vendorData: {
purpose: {
consents: 1
}
}};
const userSyncs = spec.getUserSyncs({}, {}, gdprConsent, {});

expect(userSyncs).to.be.empty
})

it('user-syncs with enabled pixel option', function () {
let gdprConsent = {
vendorData: {
purpose: {
consents: 1
}
}};
let synOptions = {pixelEnabled: true, iframeEnabled: true};
const userSyncs = spec.getUserSyncs(synOptions, {}, gdprConsent, {});

expect(userSyncs[0].type).to.equal('image');
expect(userSyncs[0].url).to.equal('https://ib.adnxs.com/getuid?https://prebid.cwi.re/v1/cookiesync?xandrId=$UID');
})

it('user-syncs with enabled iframe option', function () {
let gdprConsent = {
vendorData: {
purpose: {
consents: 1
}
}};
let synOptions = {iframeEnabled: true};
const userSyncs = spec.getUserSyncs(synOptions, {}, gdprConsent, {});

expect(userSyncs[0].type).to.equal('iframe');
expect(userSyncs[0].url).to.equal('https://ib.adnxs.com/getuid?https://prebid.cwi.re/v1/cookiesync?xandrId=$UID');
})
})
});

0 comments on commit 97689eb

Please sign in to comment.