Skip to content

Commit

Permalink
Sharethrough Bid Adapter: getUserSyncs URL clean up (prebid#8638)
Browse files Browse the repository at this point in the history
* [PGE-178206841] Clean up getUserSyncs function

* Increment adapter version
  • Loading branch information
Mathieu Pheulpin authored Jul 7, 2022
1 parent 6c1a7f6 commit 7d3d67b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
33 changes: 9 additions & 24 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions test/spec/modules/sharethroughBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
);
});

Expand Down

0 comments on commit 7d3d67b

Please sign in to comment.