Skip to content

Commit

Permalink
feat(client): initial refactor commit
Browse files Browse the repository at this point in the history
  • Loading branch information
uditalias committed Aug 23, 2020
1 parent 8b28ac2 commit c000729
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
37 changes: 11 additions & 26 deletions modules/vidazooBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,39 +176,24 @@ function interpretResponse(serverResponse, request) {
}
}

function getUserSyncs(syncOptions, responses) {
function getUserSyncs(syncOptions, responses, gdprConsent = {}, uspConsent = '') {
let syncs = [];
const { iframeEnabled, pixelEnabled } = syncOptions;

const { gdprApplies, consentString = '' } = gdprConsent;
const params = `?gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${encodeURIComponent(consentString || '')}&us_privacy=${encodeURIComponent(uspConsent || '')}`
if (iframeEnabled) {
return [{
syncs.push({
type: 'iframe',
url: 'https://static.cootlogix.com/basev/sync/user_sync.html'
}];
url: `https://prebid.cootlogix.com/api/sync/iframe/${params}`
});
}

if (pixelEnabled) {
const lookup = {};
const syncs = [];
responses.forEach(response => {
const { body } = response;
const results = body ? body.results || [] : [];
results.forEach(result => {
(result.cookies || []).forEach(cookie => {
if (cookie.type === INTERNAL_SYNC_TYPE.IMAGE) {
if (pixelEnabled && !lookup[cookie.src]) {
syncs.push({
type: EXTERNAL_SYNC_TYPE.IMAGE,
url: cookie.src
});
}
}
});
});
syncs.push({
type: 'image',
url: `https://prebid.cootlogix.com/api/sync/image/${params}`
});
return syncs;
}

return [];
return syncs;
}

export function hashCode(s, prefix = '_') {
Expand Down
4 changes: 2 additions & 2 deletions test/spec/modules/vidazooBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ describe('VidazooBidAdapter', function () {

expect(result).to.deep.equal([{
type: 'iframe',
url: 'https://static.cootlogix.com/basev/sync/user_sync.html'
url: 'https://prebid.cootlogix.com/api/sync/iframe/?gdpr=0&gdpr_consent=&us_privacy='
}]);
});

it('should have valid user sync with pixelEnabled', function () {
const result = adapter.getUserSyncs({ pixelEnabled: true }, [SERVER_RESPONSE]);

expect(result).to.deep.equal([{
'url': 'https://sync.com',
'url': 'https://prebid.cootlogix.com/api/sync/image/?gdpr=0&gdpr_consent=&us_privacy=',
'type': 'image'
}]);
})
Expand Down

0 comments on commit c000729

Please sign in to comment.