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

Sparteo Bid Adapter: Add UserSync #10822

Merged
merged 1 commit into from
Dec 27, 2023
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
42 changes: 35 additions & 7 deletions modules/sparteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const GVLID = 1028;
const TTL = 60;
const HTTP_METHOD = 'POST';
const REQUEST_URL = 'https://bid.sparteo.com/auction';
const USER_SYNC_URL_IFRAME = 'https://sync.sparteo.com/sync/iframe.html?from=prebidjs';
let isSynced = window.sparteoCrossfire?.started || false;

const converter = ortbConverter({
context: {
Expand Down Expand Up @@ -60,7 +62,7 @@ export const spec = {
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
isBidRequestValid: function (bid) {
let bannerParams = deepAccess(bid, 'mediaTypes.banner');
let videoParams = deepAccess(bid, 'mediaTypes.video');

Expand Down Expand Up @@ -106,7 +108,7 @@ export const spec = {
return true;
},

buildRequests: function(bidRequests, bidderRequest) {
buildRequests: function (bidRequests, bidderRequest) {
const payload = converter.toORTB({bidRequests, bidderRequest})

return {
Expand All @@ -116,23 +118,49 @@ export const spec = {
};
},

interpretResponse: function(serverResponse, requests) {
interpretResponse: function (serverResponse, requests) {
const bids = converter.fromORTB({response: serverResponse.body, request: requests.data}).bids;

return bids;
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {},
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
let syncurl = '';

onTimeout: function(timeoutData) {},
if (!isSynced && !window.sparteoCrossfire?.started) {
// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
syncurl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
}
if (uspConsent && uspConsent.consentString) {
syncurl += `&usp_consent=${uspConsent.consentString}`;
}

if (syncOptions.iframeEnabled) {
isSynced = true;

window.sparteoCrossfire = {
started: true
};

return [{
type: 'iframe',
url: USER_SYNC_URL_IFRAME + syncurl
}];
}
}
},

onTimeout: function (timeoutData) {},

onBidWon: function(bid) {
onBidWon: function (bid) {
if (bid && bid.nurl) {
triggerPixel(bid.nurl, null);
}
},

onSetTargeting: function(bid) {}
onSetTargeting: function (bid) {}
};

registerBidder(spec);
26 changes: 26 additions & 0 deletions test/spec/modules/sparteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CURRENCY = 'EUR';
const TTL = 60;
const HTTP_METHOD = 'POST';
const REQUEST_URL = 'https://bid.sparteo.com/auction';
const USER_SYNC_URL_IFRAME = 'https://sync.sparteo.com/sync/iframe.html?from=prebidjs';

const VALID_BID_BANNER = {
bidder: 'sparteo',
Expand Down Expand Up @@ -438,4 +439,29 @@ describe('SparteoAdapter', function () {
});
});
});

describe('getUserSyncs', function() {
describe('Check methods succeed', function () {
it('should return the sync url', function() {
const syncOptions = {
'iframeEnabled': true,
'pixelEnabled': false
};
const gdprConsent = {
gdprApplies: 1,
consentString: 'tcfv2'
};
const uspConsent = {
consentString: '1Y---'
};

const syncUrls = [{
type: 'iframe',
url: USER_SYNC_URL_IFRAME + '&gdpr=1&gdpr_consent=tcfv2&usp_consent=1Y---'
}];

expect(adapter.getUserSyncs(syncOptions, null, gdprConsent, uspConsent)).to.deep.equal(syncUrls);
});
});
});
});