Skip to content

Commit

Permalink
RichAudience BidAdapter - Changes video Adapter (prebid#5213)
Browse files Browse the repository at this point in the history
* Changes video Adapter

* Update MD Richaudience

Co-authored-by: sgimenez <sergi.gimenez@richaudience.com>
  • Loading branch information
richaudience and richaudience authored May 19, 2020
1 parent 334cb01 commit 60c83ea
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 54 deletions.
43 changes: 37 additions & 6 deletions modules/richaudienceBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const spec = {
numIframes: (typeof bidderRequest.refererInfo.numIframes != 'undefined' ? bidderRequest.refererInfo.numIframes : null),
transactionId: bid.transactionId,
timeout: config.getConfig('bidderTimeout'),
user: raiSetEids(bid)
user: raiSetEids(bid),
demand: raiGetDemandType(bid) ? 'video' : 'display',
videoData: raiGetVideoInfo(bid)
};

REFERER = (typeof bidderRequest.refererInfo.referer != 'undefined' ? encodeURIComponent(bidderRequest.refererInfo.referer) : null)
Expand Down Expand Up @@ -116,16 +118,28 @@ export const spec = {

var rand = Math.floor(Math.random() * 9999999999);
var syncUrl = '';
var consent = '';

gdprConsent && typeof gdprConsent.consentString === 'string' ? syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand + '&pubconsent=' + gdprConsent.consentString + '&euconsent=' + gdprConsent.consentString : syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand;
if (gdprConsent && typeof gdprConsent.consentString === 'string' && typeof gdprConsent.consentString != 'undefined') {
consent = `pubconsent='${gdprConsent.consentString}'&euconsent='${gdprConsent.consentString}'`
}

if (syncOptions.iframeEnabled) {
syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand
if (consent != '') {
syncUrl += `&${consent}`
}
syncs.push({
type: 'iframe',
url: syncUrl
});
} else if (syncOptions.pixelEnabled && REFERER != null) {
typeof gdprConsent != 'undefined' && typeof gdprConsent.consentString != 'undefined' ? syncUrl = `https://sync.richaudience.com/bf7c142f4339da0278e83698a02b0854/?euconsent=${gdprConsent.consentString}&referrer=${REFERER}` : syncUrl = `https://sync.richaudience.com/bf7c142f4339da0278e83698a02b0854/?referrer=${REFERER}`;
}

if (syncOptions.pixelEnabled && REFERER != null && syncs.length == 0) {
syncUrl = `https://sync.richaudience.com/bf7c142f4339da0278e83698a02b0854/?referrer=${REFERER}`;
if (consent != '') {
syncUrl += `&${consent}`
}
syncs.push({
type: 'image',
url: syncUrl
Expand All @@ -141,8 +155,6 @@ function raiGetSizes(bid) {
let raiNewSizes;
if (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) {
raiNewSizes = bid.mediaTypes.banner.sizes
} else {
raiNewSizes = bid.sizes
}
if (raiNewSizes != null) {
return raiNewSizes.map(size => ({
Expand All @@ -152,6 +164,25 @@ function raiGetSizes(bid) {
}
}

function raiGetDemandType(bid) {
if (bid.mediaTypes != undefined) {
if (bid.mediaTypes.video != undefined) {
return true;
}
}
return false;
}

function raiGetVideoInfo(bid) {
let videoData = [];
if (raiGetDemandType(bid)) {
videoData.push({format: bid.mediaTypes.video.context});
videoData.push({playerSize: bid.mediaTypes.video.playerSize});
videoData.push({mimes: bid.mediaTypes.video.mimes});
}
return videoData;
}

function raiSetEids(bid) {
let eids = [];

Expand Down
21 changes: 18 additions & 3 deletions modules/richaudienceBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ Please reach out to your account manager for more information.
var adUnits = [
{
code: 'test-div1',
sizes: [[300, 250],[300, 600]],
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
bids: [{
bidder: 'richaudience',
params: {
Expand Down Expand Up @@ -85,7 +89,18 @@ Rich Audience strongly recommends enabling user syncing through iframes. Be sure
```javascript
pbjs.setConfig({
userSync: {
iframeEnabled: true
}
filterSettings: {
iframe: {
bidders: '*',
filter: 'include'
},
image: {
bidders: '*',
filter: 'include'
}
},
syncsPerBidder: 3,
syncDelay: 6000,
}
});
```
74 changes: 29 additions & 45 deletions test/spec/modules/richaudienceBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import {
} from 'modules/richaudienceBidAdapter.js';
import {config} from 'src/config.js';
import * as utils from 'src/utils.js';
import { getGlobal } from 'src/prebidGlobal.js';

describe('Richaudience adapter tests', function () {
var DEFAULT_PARAMS = [{
var DEFAULT_PARAMS_NEW_SIZES = [{
adUnitCode: 'test-div',
bidId: '2c7c8e9c900244',
sizes: [
[300, 250],
[300, 600],
[728, 90],
[970, 250]
],
mediaTypes: {
banner: {
sizes: [
[300, 250], [300, 600], [728, 90], [970, 250]]
}
},
bidder: 'richaudience',
params: {
bidfloor: 0.5,
Expand All @@ -30,13 +29,14 @@ describe('Richaudience adapter tests', function () {
user: {}
}];

var DEFAULT_PARAMS_NEW_SIZES = [{
var DEFAULT_PARAMS_VIDEO = [{
adUnitCode: 'test-div',
bidId: '2c7c8e9c900244',
mediaTypes: {
banner: {
sizes: [
[300, 250], [300, 600], [728, 90], [970, 250]]
video: {
context: 'instream', // or 'outstream'
playerSize: [640, 480],
mimes: ['video/mp4']
}
},
bidder: 'richaudience',
Expand Down Expand Up @@ -136,34 +136,12 @@ describe('Richaudience adapter tests', function () {
}
}

it('Verify build request', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'USD'
}
});

const request = spec.buildRequests(DEFAULT_PARAMS, DEFAULT_PARAMS_GDPR);

expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);
expect(requestContent).to.have.property('sizes');
expect(requestContent.sizes[0]).to.have.property('w').and.to.equal(300);
expect(requestContent.sizes[0]).to.have.property('h').and.to.equal(250);
expect(requestContent.sizes[1]).to.have.property('w').and.to.equal(300);
expect(requestContent.sizes[1]).to.have.property('h').and.to.equal(600);
expect(requestContent.sizes[2]).to.have.property('w').and.to.equal(728);
expect(requestContent.sizes[2]).to.have.property('h').and.to.equal(90);
expect(requestContent.sizes[3]).to.have.property('w').and.to.equal(970);
expect(requestContent.sizes[3]).to.have.property('h').and.to.equal(250);
});

it('Referer undefined', function() {
config.setConfig({
'currency': {'adServerCurrency': 'USD'}
})

const request = spec.buildRequests(DEFAULT_PARAMS, {
const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, {
gdprConsent: {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
gdprApplies: true
Expand All @@ -175,7 +153,7 @@ describe('Richaudience adapter tests', function () {
expect(requestContent).to.have.property('referer').and.to.equal(null);
})

it('Verify build request to prebid 3.0', function() {
it('Verify build request to prebid 3.0 display test', function() {
const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, {
gdprConsent: {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
Expand Down Expand Up @@ -280,7 +258,7 @@ describe('Richaudience adapter tests', function () {
});

describe('UID test', function () {
getGlobal().setConfig({
pbjs.setConfig({
consentManagement: {
cmpApi: 'iab',
timeout: 5000,
Expand Down Expand Up @@ -498,7 +476,7 @@ describe('Richaudience adapter tests', function () {
});

it('Verify interprete response', function () {
const request = spec.buildRequests(DEFAULT_PARAMS, {
const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, {
gdprConsent: {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
gdprApplies: true
Expand All @@ -525,7 +503,7 @@ describe('Richaudience adapter tests', function () {
});

it('no banner media response', function () {
const request = spec.buildRequests(DEFAULT_PARAMS, {
const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, {
gdprConsent: {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
gdprApplies: true
Expand All @@ -551,7 +529,7 @@ describe('Richaudience adapter tests', function () {
});

it('Verifies if bid request is valid', function () {
expect(spec.isBidRequestValid(DEFAULT_PARAMS[0])).to.equal(true);
expect(spec.isBidRequestValid(DEFAULT_PARAMS_NEW_SIZES[0])).to.equal(true);
expect(spec.isBidRequestValid(DEFAULT_PARAMS_WO_OPTIONAL[0])).to.equal(true);
expect(spec.isBidRequestValid({})).to.equal(false);
expect(spec.isBidRequestValid({
Expand Down Expand Up @@ -613,13 +591,14 @@ describe('Richaudience adapter tests', function () {
})).to.equal(true);
});

it('Verifies user sync', function () {
it('Verifies user syncs iframe', function () {
var syncs = spec.getUserSyncs({
iframeEnabled: true
}, [BID_RESPONSE], {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
gdprApplies: true
});

expect(syncs).to.have.lengthOf(1);
expect(syncs[0].type).to.equal('iframe');
syncs = spec.getUserSyncs({
Expand All @@ -640,18 +619,21 @@ describe('Richaudience adapter tests', function () {
}, [], {consentString: '', gdprApplies: true});
expect(syncs).to.have.lengthOf(0);

getGlobal().setConfig({
pbjs.setConfig({
consentManagement: {
cmpApi: 'iab',
timeout: 5000,
allowAuctionWithoutConsent: true,
pixelEnabled: true
}
});
});

syncs = spec.getUserSyncs({
it('Verifies user syncs image', function () {
var syncs = spec.getUserSyncs({
iframeEnabled: false,
pixelEnabled: true
}, [], {
}, [BID_RESPONSE], {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
referer: 'http://domain.com',
gdprApplies: true
Expand All @@ -660,8 +642,9 @@ describe('Richaudience adapter tests', function () {
expect(syncs[0].type).to.equal('image');

syncs = spec.getUserSyncs({
iframeEnabled: false,
pixelEnabled: true
}, [], {
}, [BID_RESPONSE], {
consentString: '',
referer: 'http://domain.com',
gdprApplies: true
Expand All @@ -670,6 +653,7 @@ describe('Richaudience adapter tests', function () {
expect(syncs[0].type).to.equal('image');

syncs = spec.getUserSyncs({
iframeEnabled: false,
pixelEnabled: true
}, [], {
consentString: null,
Expand Down

0 comments on commit 60c83ea

Please sign in to comment.