From 7d3d67b799fe446beadbb9b567c22147cdc14cf5 Mon Sep 17 00:00:00 2001 From: Mathieu Pheulpin Date: Wed, 6 Jul 2022 18:14:52 -0700 Subject: [PATCH] Sharethrough Bid Adapter: getUserSyncs URL clean up (#8638) * [PGE-178206841] Clean up getUserSyncs function * Increment adapter version --- modules/sharethroughBidAdapter.js | 33 +++++-------------- .../modules/sharethroughBidAdapter_spec.js | 8 ++--- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/modules/sharethroughBidAdapter.js b/modules/sharethroughBidAdapter.js index 16495b647ab..731fc5c3a4e 100644 --- a/modules/sharethroughBidAdapter.js +++ b/modules/sharethroughBidAdapter.js @@ -4,7 +4,7 @@ import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { createEidsArray } from './userId/eids.js'; -const VERSION = '4.1.0'; +const VERSION = '4.1.1'; const BIDDER_CODE = 'sharethrough'; const SUPPLY_ID = 'WYu2BXv1'; @@ -34,9 +34,8 @@ export const sharethroughAdapterSpec = { cur: ['USD'], tmax: timeout, site: { - // TODO: do the fallbacks make sense here? - domain: deepAccess(bidderRequest, 'refererInfo.domain') || window.location.hostname, - page: deepAccess(bidderRequest, 'refererInfo.page') || window.location.href, + domain: deepAccess(bidderRequest, 'refererInfo.domain', window.location.hostname), + page: deepAccess(bidderRequest, 'refererInfo.page', window.location.href), ref: deepAccess(bidderRequest, 'refererInfo.ref'), ...firstPartyData.site, }, @@ -66,7 +65,7 @@ export const sharethroughAdapterSpec = { req.user = nullish(firstPartyData.user, {}); if (!req.user.ext) req.user.ext = {}; - req.user.ext.eids = userIdAsEids(bidRequests[0]); + req.user.ext.eids = createEidsArray(deepAccess(bidRequests[0], 'userId')) || []; if (bidderRequest.gdprConsent) { const gdprApplies = bidderRequest.gdprConsent.gdprApplies === true; @@ -181,21 +180,12 @@ export const sharethroughAdapterSpec = { }); }, - getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { - const syncParams = uspConsent ? `&us_privacy=${uspConsent}` : ''; - const syncs = []; - const shouldCookieSync = syncOptions.pixelEnabled && - serverResponses.length > 0 && - serverResponses[0].body && - serverResponses[0].body.cookieSyncUrls; - - if (shouldCookieSync) { - serverResponses[0].body.cookieSyncUrls.forEach(url => { - syncs.push({ type: 'image', url: url + syncParams }); - }); - } + getUserSyncs: (syncOptions, serverResponses) => { + const shouldCookieSync = syncOptions.pixelEnabled && deepAccess(serverResponses, '0.body.cookieSyncUrls') !== undefined; - return syncs; + return shouldCookieSync + ? serverResponses[0].body.cookieSyncUrls.map(url => ({ type: 'image', url: url })) + : []; }, // Empty implementation for prebid core to be able to find it @@ -244,11 +234,6 @@ function getBidRequestFloor(bid) { return floor !== null ? floor : bid.params.floor; } -function userIdAsEids(bidRequest) { - const eids = createEidsArray(deepAccess(bidRequest, 'userId')) || []; - return eids; -} - function getProtocol() { return window.location.protocol; } diff --git a/test/spec/modules/sharethroughBidAdapter_spec.js b/test/spec/modules/sharethroughBidAdapter_spec.js index 4ef93c9b530..7addd9ee786 100644 --- a/test/spec/modules/sharethroughBidAdapter_spec.js +++ b/test/spec/modules/sharethroughBidAdapter_spec.js @@ -601,11 +601,11 @@ describe('sharethrough adapter spec', function () { const serverResponses = [{ body: { cookieSyncUrls: cookieSyncs } }]; it('returns an array of correctly formatted user syncs', function () { - const syncArray = spec.getUserSyncs({ pixelEnabled: true }, serverResponses, null, 'fake-privacy-signal'); + const syncArray = spec.getUserSyncs({ pixelEnabled: true }, serverResponses); expect(syncArray).to.deep.equal([ - { type: 'image', url: 'cookieUrl1&us_privacy=fake-privacy-signal' }, - { type: 'image', url: 'cookieUrl2&us_privacy=fake-privacy-signal' }, - { type: 'image', url: 'cookieUrl3&us_privacy=fake-privacy-signal' }], + { type: 'image', url: 'cookieUrl1' }, + { type: 'image', url: 'cookieUrl2' }, + { type: 'image', url: 'cookieUrl3' }], ); });