Skip to content

Commit

Permalink
AdYouLike Bid Adapter: add video capabilities (prebid#6398)
Browse files Browse the repository at this point in the history
* read and send getFloor value

* improve robustness on OnEvent fields

* add video mediatype to adyoulike  adapter

* improve robustness on OnEvent fields

* handle instream cases

* minor format fix

* move the atob call to apply it on every Vast response

* update adyoulike md file with video type

* update adyoulike bidder doc

* fix merge error on 'bid' var name

* update adyoulike bidder doc
  • Loading branch information
guiann authored and stsepelin committed May 28, 2021
1 parent bb97526 commit 884cbf4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 24 deletions.
73 changes: 59 additions & 14 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import find from 'core-js-pure/features/array/find.js';
import {BANNER, NATIVE} from '../src/mediaTypes.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';

const VERSION = '1.0';
const BIDDER_CODE = 'adyoulike';
const DEFAULT_DC = 'hb-api';
const CURRENCY = 'USD';

const NATIVE_IMAGE = {
image: {
Expand Down Expand Up @@ -34,7 +35,7 @@ const NATIVE_IMAGE = {

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, NATIVE],
supportedMediaTypes: [BANNER, NATIVE, VIDEO],
aliases: ['ayl'], // short code
/**
* Determines whether or not the given bid request is valid.
Expand All @@ -59,21 +60,28 @@ export const spec = {
buildRequests: function (bidRequests, bidderRequest) {
const payload = {
Version: VERSION,
Bids: bidRequests.reduce((accumulator, bid) => {
let sizesArray = getSizeArray(bid);
Bids: bidRequests.reduce((accumulator, bidReq) => {
let mediatype = getMediatype(bidReq);
let sizesArray = getSizeArray(bidReq);
let size = getSize(sizesArray);
accumulator[bid.bidId] = {};
accumulator[bid.bidId].PlacementID = bid.params.placement;
accumulator[bid.bidId].TransactionID = bid.transactionId;
accumulator[bid.bidId].Width = size.width;
accumulator[bid.bidId].Height = size.height;
accumulator[bid.bidId].AvailableSizes = sizesArray.join(',');
if (bid.mediaTypes && bid.mediaTypes.native) {
let nativeReq = bid.mediaTypes.native;
accumulator[bidReq.bidId] = {};
accumulator[bidReq.bidId].PlacementID = bidReq.params.placement;
accumulator[bidReq.bidId].TransactionID = bidReq.transactionId;
accumulator[bidReq.bidId].Width = size.width;
accumulator[bidReq.bidId].Height = size.height;
accumulator[bidReq.bidId].AvailableSizes = sizesArray.join(',');
if (typeof bidReq.getFloor === 'function') {
accumulator[bidReq.bidId].Pricing = getFloor(bidReq, size, mediatype);
}
if (mediatype === NATIVE) {
let nativeReq = bidReq.mediaTypes.native;
if (nativeReq.type === 'image') {
nativeReq = Object.assign({}, NATIVE_IMAGE, nativeReq);
}
accumulator[bid.bidId].Native = nativeReq;
accumulator[bidReq.bidId].Native = nativeReq;
}
if (mediatype === VIDEO) {
accumulator[bidReq.bidId].Video = bidReq.mediaTypes.video;
}
return accumulator;
}, {}),
Expand Down Expand Up @@ -156,6 +164,31 @@ function getCanonicalUrl() {
return '';
}

/* Get mediatype from bidRequest */
function getMediatype(bidRequest) {
var type = BANNER;

if (utils.deepAccess(bidRequest, 'mediaTypes.native')) {
type = NATIVE;
} else if (utils.deepAccess(bidRequest, 'mediaTypes.video')) {
type = VIDEO;
}

return type;
}
/* Get Floor price information */
function getFloor(bidRequest, size, mediaType) {
const bidFloors = bidRequest.getFloor({
currency: CURRENCY,
mediaType,
size: [ size.width, size.height ]
});

if (!isNaN(bidFloors.floor) && (bidFloors.currency === CURRENCY)) {
return bidFloors.floor;
}
}

/* Get information on page refresh */
function getPageRefreshed() {
try {
Expand Down Expand Up @@ -287,6 +320,14 @@ function getTrackers(eventsArray, jsTrackers) {
return result;
}

function getVideoAd(response) {
var adJson = {};
if (typeof response.Ad === 'string') {
adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]);
return utils.deepAccess(adJson, 'Content.MainVideo.Vast');
}
}

function getNativeAssets(response, nativeConfig) {
const native = {};

Expand Down Expand Up @@ -402,12 +443,16 @@ function createBid(response, bidRequests) {
creativeId: response.CreativeID,
cpm: response.Price,
netRevenue: true,
currency: 'USD'
currency: CURRENCY
};

if (request && request.Native) {
bid.native = getNativeAssets(response, request.Native);
bid.mediaType = 'native';
} else if (request && request.Video) {
const vast64 = response.Vast || getVideoAd(response);
bid.vastXml = vast64 ? window.atob(vast64) : '';
bid.mediaType = 'video';
} else {
bid.width = response.Width;
bid.height = response.Height;
Expand Down
24 changes: 14 additions & 10 deletions modules/adyoulikeBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ Maintainer: prebid@adyoulike.com
# Description

Module that connects to Adyoulike demand sources.
Banner formats are supported.
Banner, Native and Video ad formats are supported.

# Test Parameters
```
var adUnits = {
var adUnits = {
"code": "test-div",
"mediaTypes": {
"banner": {
"sizes": ["300x250"]
},
"video": {
context: "instream",
playerSize: [[640, 480]]
},
"native": {
"image": {
"required": true,
Expand Down Expand Up @@ -48,12 +52,12 @@ Banner formats are supported.
"sizes": []
}
}
bids: [{
bidder: "adyoulike",
params: {
placement: 194 f787b85c829fb8822cdaf1ae64435,
DC: "fra01", // Optional for set the data center name
}
}]
};
},
bids: [{
bidder: "adyoulike",
params: {
placement: "e622af275681965d3095808561a1e510"
}
}]
};
```

0 comments on commit 884cbf4

Please sign in to comment.