diff --git a/modules/sparteoBidAdapter.js b/modules/sparteoBidAdapter.js index 93353c5dda7..bfb527d46f2 100644 --- a/modules/sparteoBidAdapter.js +++ b/modules/sparteoBidAdapter.js @@ -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: { @@ -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'); @@ -106,7 +108,7 @@ export const spec = { return true; }, - buildRequests: function(bidRequests, bidderRequest) { + buildRequests: function (bidRequests, bidderRequest) { const payload = converter.toORTB({bidRequests, bidderRequest}) return { @@ -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); diff --git a/test/spec/modules/sparteoBidAdapter_spec.js b/test/spec/modules/sparteoBidAdapter_spec.js index 71191b44a29..293f7da30a1 100644 --- a/test/spec/modules/sparteoBidAdapter_spec.js +++ b/test/spec/modules/sparteoBidAdapter_spec.js @@ -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', @@ -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); + }); + }); + }); });