Skip to content

Commit

Permalink
Vidazoo Adapter: refactor/user-sync (#5654)
Browse files Browse the repository at this point in the history
* feat(module): multi size request

* fix getUserSyncs
added tests

* update(module): package-lock.json from master

* feat(client): initial refactor commit

* fix(client): lint issues

Co-authored-by: roman <[email protected]>
  • Loading branch information
uditalias and shmoop207 authored Sep 5, 2020
1 parent 7743713 commit 9626398
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
45 changes: 11 additions & 34 deletions modules/vidazooBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ const TTL_SECONDS = 60 * 5;
const DEAL_ID_EXPIRY = 1000 * 60 * 15;
const UNIQUE_DEAL_ID_EXPIRY = 1000 * 60 * 15;
const SESSION_ID_KEY = 'vidSid';
const INTERNAL_SYNC_TYPE = {
IFRAME: 'iframe',
IMAGE: 'img'
};
const EXTERNAL_SYNC_TYPE = {
IFRAME: 'iframe',
IMAGE: 'image'
};
export const SUPPORTED_ID_SYSTEMS = {
'britepoolid': 1,
'criteoId': 1,
Expand Down Expand Up @@ -176,39 +168,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 9626398

Please sign in to comment.