Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vidazoo Adapter: refactor/user-sync #5654

Merged
merged 13 commits into from
Sep 5, 2020
Merged
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