Skip to content

Commit

Permalink
Vidazoo Bid Adapter: Cookie sync improvements (prebid#8834)
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(module): VidazooBidAdapter - send top query params to server

* feat(module): changed userSync url and passes cids from responses to usersync.

* feat(module): fixed failing test.

Co-authored-by: Udi Talias <[email protected]>
Co-authored-by: roman <[email protected]>
  • Loading branch information
3 people authored and jorgeluisrocha committed May 18, 2023
1 parent 1ab2d9a commit 235a952
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
10 changes: 6 additions & 4 deletions modules/vidazooBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _each, deepAccess, parseSizesInput, parseUrl } from '../src/utils.js';
import {_each, deepAccess, parseSizesInput, parseUrl, uniques} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { getStorageManager } from '../src/storageManager.js';
Expand Down Expand Up @@ -191,17 +191,19 @@ 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 || '')}`

const cidArr = responses.filter(resp => deepAccess(resp, 'body.cid')).map(resp => resp.body.cid).filter(uniques);
const params = `?cid=${encodeURIComponent(cidArr.join(','))}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${encodeURIComponent(consentString || '')}&us_privacy=${encodeURIComponent(uspConsent || '')}`
if (iframeEnabled) {
syncs.push({
type: 'iframe',
url: `https://prebid.cootlogix.com/api/sync/iframe/${params}`
url: `https://sync.cootlogix.com/api/sync/iframe/${params}`
});
}
if (pixelEnabled) {
syncs.push({
type: 'image',
url: `https://prebid.cootlogix.com/api/sync/image/${params}`
url: `https://sync.cootlogix.com/api/sync/image/${params}`
});
}
return syncs;
Expand Down
59 changes: 36 additions & 23 deletions test/spec/modules/vidazooBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import {expect} from 'chai';
import {
spec as adapter,
SUPPORTED_ID_SYSTEMS,
Expand All @@ -15,8 +15,8 @@ import {
getVidazooSessionId,
} from 'modules/vidazooBidAdapter.js';
import * as utils from 'src/utils.js';
import { version } from 'package.json';
import { useFakeTimers } from 'sinon';
import {version} from 'package.json';
import {useFakeTimers} from 'sinon';

const SUB_DOMAIN = 'openrtb';

Expand Down Expand Up @@ -55,6 +55,7 @@ const BIDDER_REQUEST = {

const SERVER_RESPONSE = {
body: {
cid: 'testcid123',
results: [{
'ad': '<iframe>console.log("hello world")</iframe>',
'price': 0.8,
Expand Down Expand Up @@ -84,7 +85,7 @@ const REQUEST = {

function getTopWindowQueryParams() {
try {
const parsedUrl = utils.parseUrl(window.top.document.URL, { decodeSearchAsString: true });
const parsedUrl = utils.parseUrl(window.top.document.URL, {decodeSearchAsString: true});
return parsedUrl.search;
} catch (e) {
return '';
Expand Down Expand Up @@ -196,19 +197,27 @@ describe('VidazooBidAdapter', function () {
});
describe('getUserSyncs', function () {
it('should have valid user sync with iframeEnabled', function () {
const result = adapter.getUserSyncs({ iframeEnabled: true }, [SERVER_RESPONSE]);
const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]);

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

it('should have valid user sync with cid on response', function () {
const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]);
expect(result).to.deep.equal([{
type: 'iframe',
url: 'https://sync.cootlogix.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy='
}]);
});

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

expect(result).to.deep.equal([{
'url': 'https://prebid.cootlogix.com/api/sync/image/?gdpr=0&gdpr_consent=&us_privacy=',
'url': 'https://sync.cootlogix.com/api/sync/image/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=',
'type': 'image'
}]);
})
Expand All @@ -221,12 +230,12 @@ describe('VidazooBidAdapter', function () {
});

it('should return empty array when there is no ad', function () {
const responses = adapter.interpretResponse({ price: 1, ad: '' });
const responses = adapter.interpretResponse({price: 1, ad: ''});
expect(responses).to.be.empty;
});

it('should return empty array when there is no price', function () {
const responses = adapter.interpretResponse({ price: null, ad: 'great ad' });
const responses = adapter.interpretResponse({price: null, ad: 'great ad'});
expect(responses).to.be.empty;
});

Expand Down Expand Up @@ -265,10 +274,14 @@ describe('VidazooBidAdapter', function () {

const userId = (function () {
switch (idSystemProvider) {
case 'lipb': return { lipbid: id };
case 'parrableId': return { eid: id };
case 'id5id': return { uid: id };
default: return id;
case 'lipb':
return {lipbid: id};
case 'parrableId':
return {eid: id};
case 'id5id':
return {uid: id};
default:
return id;
}
})();

Expand All @@ -285,18 +298,18 @@ describe('VidazooBidAdapter', function () {

describe('alternate param names extractors', function () {
it('should return undefined when param not supported', function () {
const cid = extractCID({ 'c_id': '1' });
const pid = extractPID({ 'p_id': '1' });
const subDomain = extractSubDomain({ 'sub_domain': 'prebid' });
const cid = extractCID({'c_id': '1'});
const pid = extractPID({'p_id': '1'});
const subDomain = extractSubDomain({'sub_domain': 'prebid'});
expect(cid).to.be.undefined;
expect(pid).to.be.undefined;
expect(subDomain).to.be.undefined;
});

it('should return value when param supported', function () {
const cid = extractCID({ 'cID': '1' });
const pid = extractPID({ 'Pid': '2' });
const subDomain = extractSubDomain({ 'subDOMAIN': 'prebid' });
const cid = extractCID({'cID': '1'});
const pid = extractPID({'Pid': '2'});
const subDomain = extractSubDomain({'subDOMAIN': 'prebid'});
expect(cid).to.be.equal('1');
expect(pid).to.be.equal('2');
expect(subDomain).to.be.equal('prebid');
Expand Down Expand Up @@ -409,7 +422,7 @@ describe('VidazooBidAdapter', function () {
now
});
setStorageItem('myKey', 2020);
const { value, created } = getStorageItem('myKey');
const {value, created} = getStorageItem('myKey');
expect(created).to.be.equal(now);
expect(value).to.be.equal(2020);
expect(typeof value).to.be.equal('number');
Expand All @@ -425,8 +438,8 @@ describe('VidazooBidAdapter', function () {
});

it('should parse JSON value', function () {
const data = JSON.stringify({ event: 'send' });
const { event } = tryParseJSON(data);
const data = JSON.stringify({event: 'send'});
const {event} = tryParseJSON(data);
expect(event).to.be.equal('send');
});

Expand Down

0 comments on commit 235a952

Please sign in to comment.