Skip to content

Commit

Permalink
bring back original sync
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipStamenkovic committed Aug 14, 2024
1 parent 6b698ac commit 10cc542
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 60 deletions.
59 changes: 31 additions & 28 deletions modules/showheroes-bsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
deepAccess,
deepSetValue,
triggerPixel,
formatQS,
isFn,
logInfo} from '../src/utils.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
Expand Down Expand Up @@ -63,12 +62,6 @@ const converter = ortbConverter({
},
})

var hasSynced = false;

export function resetUserSync() {
hasSynced = false;
}

function getEnvURLs(isStage) {
return {
pubTag: isStage ? STAGE_PUBLISHER_TAG : PROD_PUBLISHER_TAG,
Expand Down Expand Up @@ -106,33 +99,43 @@ export const spec = {
interpretResponse: (response, request) => {
return createBids(response.body, request.data);
},
getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent, gppConsent) => {
if (hasSynced || !syncOptions.iframeEnabled) return;
getUserSyncs: (syncOptions, serverResponses) => {
const syncs = [];

// data is only assigned if params are available to pass to syncEndpoint
let params = {};

if (gdprConsent) {
params['gdpr'] = gdprConsent.gdprApplies ? 1 : 0;
params['gdpr_consent'] = encodeURIComponent(gdprConsent.consentString);
if (!serverResponses.length || !serverResponses[0].body.userSync) {
return syncs;
}

if (uspConsent) {
params['usp'] = encodeURIComponent(uspConsent);
const userSync = serverResponses[0].body.userSync;

if (syncOptions.iframeEnabled && userSync?.iframes?.length) {
userSync.iframes.forEach(url => {
syncs.push({
type: 'iframe',
url
});
(userSync.pixels || []).forEach(url => {
syncs.push({
type: 'iframe',
url
});
});
});
logInfo(`found ${syncs.length} iframe urls to sync`);
return syncs;
}

if (gppConsent?.gppString) {
params['gpp'] = gppConsent.gppString;
params['gpp_sid'] = gppConsent.applicableSections?.join();
}
if (syncOptions.pixelEnabled) {
(userSync.pixels || []).forEach(url => {
syncs.push({
type: 'image',
url
});
});

params = Object.keys(params).length ? `?${formatQS(params)}` : '';

hasSynced = true;
return {
type: 'iframe',
url: SYNC_URL + params,
};
logInfo(`found ${syncs.length} pixel urls to sync`);
}
return syncs;
},

onBidWon(bid) {
Expand Down
56 changes: 24 additions & 32 deletions test/spec/modules/showheroes-bsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,46 +311,38 @@ describe('shBidAdapter', () => {
})
});

describe('user sync', () => {
beforeEach(() => {
resetUserSync();
});
describe('getUserSyncs', function () {
const response = [{
body: {
userSync: {
iframes: ['https://sync.showheroes.com/iframe'],
pixels: ['https://sync.showheroes.com/pixel']
}
}
}]

it('should register the ShowHeroes iframe', () => {
const syncs = spec.getUserSyncs({
iframeEnabled: true
});
it('empty', function () {
let result = spec.getUserSyncs({}, []);

expect(syncs).to.deep.equal({ type: 'iframe', url: SYNC_URL });
const secondSync = spec.getUserSyncs({
iframeEnabled: true
});

expect(secondSync).to.be.undefined;
expect(result).to.deep.equal([]);
});

it('should skip sync without iframe', () => {
const sync = spec.getUserSyncs({
iframeEnabled: false
});
it('iframe', function () {
let result = spec.getUserSyncs({
iframeEnabled: true
}, response);

expect(sync).to.be.undefined;
expect(result[0].type).to.equal('iframe');
expect(result[0].url).to.equal('https://sync.showheroes.com/iframe');
});

it('should include privacy parameters', () => {
const syncs = spec.getUserSyncs({
iframeEnabled: true
}, undefined, {
gdprApplies: true,
consentString: 'test_consent',
},
'1---', {
gppString: 'test_gpp',
applicableSections: ['1', '2'],
});
it('pixel', function () {
let result = spec.getUserSyncs({
pixelEnabled: true
}, response);

const expectedURL = `${SYNC_URL}?gdpr=1&gdpr_consent=test_consent&usp=1---&gpp=test_gpp&gpp_sid=1,2`;
expect(syncs).to.deep.equal({ type: 'iframe', url: expectedURL });
expect(result[0].type).to.equal('image');
expect(result[0].url).to.equal('https://sync.showheroes.com/pixel');
});
});
});

0 comments on commit 10cc542

Please sign in to comment.