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

update AJA adaptor: support native format #3504

Merged
merged 5 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions modules/ajaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Renderer } from '../src/Renderer';
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';
import { VIDEO, BANNER } from '../src/mediaTypes';
import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes';

const BIDDER_CODE = 'aja';
const URL = '//ad.as.amanad.adtdp.com/v2/prebid';
Expand All @@ -14,7 +14,7 @@ const AD_TYPE = {

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [VIDEO, BANNER],
supportedMediaTypes: [VIDEO, BANNER, NATIVE],

isBidRequestValid: function(bid) {
return !!(bid.params.asi);
Expand Down Expand Up @@ -86,6 +86,41 @@ export const spec = {
} catch (error) {
utils.logError('Error appending tracking pixel', error);
}
} else if (AD_TYPE.NATIVE === ad.ad_type) {
const nativeAds = ad.native.template_and_ads.ads;

nativeAds.forEach(nativeAd => {
const assets = nativeAd.assets;

Object.assign(bid, {
mediaType: NATIVE
});

bid.native = {
title: assets.title,
body: assets.description,
cta: assets.cta_text,
sponsoredBy: assets.sponsor,
clickUrl: assets.lp_link,
impressionTrackers: nativeAd.imps,
};

if (assets.img_main !== undefined) {
bid.native.image = {
url: assets.img_main,
width: parseInt(assets.img_main_width, 10),
height: parseInt(assets.img_main_height, 10)
};
}

if (assets.img_icon !== undefined) {
bid.native.icon = {
url: assets.img_icon,
width: parseInt(assets.img_icon_width, 10),
height: parseInt(assets.img_icon_height, 10)
};
}
});
}

return [bid];
Expand Down
48 changes: 43 additions & 5 deletions modules/ajaBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Connects to Aja exchange for bids.
Aja bid adapter supports Banner and Outstream Video.

# Test Parameters
```
```js
var adUnits = [
// Banner adUnit
{
code: 'banner-div',
code: 'prebid_banner',
mediaTypes: {
banner: {
sizes: [
Expand All @@ -26,13 +26,13 @@ var adUnits = [
bids: [{
bidder: 'aja',
params: {
asi: 'szs4htFiR'
asi: 'tk82gbLmg'
}
}]
},
// Video outstream adUnit
{
code: 'video-outstream',
code: 'prebid_video',
mediaTypes: {
video: {
context: 'outstream',
Expand All @@ -42,7 +42,45 @@ var adUnits = [
bids: [{
bidder: 'aja',
params: {
asi: 'Kp2O2tFig'
asi: '1-KwEG_iR'
}
}]
},
// Native adUnit
{
code: 'prebid_native',
mediaTypes: {
native: {
image: {
required: true,
sendId: false
},
title: {
required: true,
sendId: true
},
sponsoredBy: {
required: false,
sendId: true
},
clickUrl: {
required: false,
sendId: true
},
body: {
required: false,
sendId: true
},
icon: {
required: false,
sendId: false
}
}
},
bids: [{
bidder: 'aja',
params: {
asi: 'qxueUGliR'
}
}]
}
Expand Down
134 changes: 112 additions & 22 deletions test/spec/modules/ajaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,31 @@ describe('AjaAdapter', function () {
expect(requests[0].method).to.equal('GET');
});
});
describe('interpretResponse', function () {
let response = {
'is_ad_return': true,
'ad': {
'ad_type': 1,
'prebid_id': '51ef8751f9aead',
'price': 12.34,
'currency': 'USD',
'creative_id': '123abc',
'banner': {
'w': 300,
'h': 250,
'tag': '<div></div>',
'imps': [
'//as.amanad.adtdp.com/v1/imp'
]
}
},
'syncs': [
'https://example.com'
]
};

describe('interpretResponse', function () {
it('should get correct banner bid response', function () {
let response = {
'is_ad_return': true,
'ad': {
'ad_type': 1,
'prebid_id': '51ef8751f9aead',
'price': 12.34,
'currency': 'USD',
'creative_id': '123abc',
'banner': {
'w': 300,
'h': 250,
'tag': '<div></div>',
'imps': [
'//as.amanad.adtdp.com/v1/imp'
]
}
},
'syncs': [
'https://example.com'
]
};

let expectedResponse = [
{
'requestId': '51ef8751f9aead',
Expand Down Expand Up @@ -130,6 +131,95 @@ describe('AjaAdapter', function () {
expect(result[0]).to.have.property('mediaType', 'video');
});

it('handles native response', function () {
let response = {
'is_ad_return': true,
'ad': {
'ad_type': 2,
'prebid_id': '51ef8751f9aead',
'price': 12.34,
'currency': 'JPY',
'creative_id': '123abc',
'native': {
'template_and_ads': {
'head': '',
'body_wrapper': '',
'body': '',
'ads': [
{
'ad_format_id': 10,
'assets': {
'ad_spot_id': '123abc',
'index': 0,
'adchoice_url': 'https://aja-kk.co.jp/optout',
'cta_text': 'cta',
'img_icon': 'https://example.com/img_icon',
'img_icon_width': '50',
'img_icon_height': '50',
'img_main': 'https://example.com/img_main',
'img_main_width': '200',
'img_main_height': '100',
'lp_link': 'https://example.com/lp?k=v',
'sponsor': 'sponsor',
'title': 'ad_title',
'description': 'ad_desc'
},
'imps': [
'https://example.com/imp'
],
'inviews': [
'https://example.com/inview'
],
'jstracker': '',
'disable_trimming': false
}
]
}
}
},
'syncs': [
'https://example.com'
]
};

let expectedResponse = [
{
'requestId': '51ef8751f9aead',
'cpm': 12.34,
'creativeId': '123abc',
'dealId': undefined,
'mediaType': 'native',
'currency': 'JPY',
'ttl': 300,
'netRevenue': true,
'native': {
'title': 'ad_title',
'body': 'ad_desc',
'cta': 'cta',
'sponsoredBy': 'sponsor',
'image': {
'url': 'https://example.com/img_main',
'width': 200,
'height': 100
},
'icon': {
'url': 'https://example.com/img_icon',
'width': 50,
'height': 50
},
'clickUrl': 'https://example.com/lp?k=v',
'impressionTrackers': [
'https://example.com/imp'
]
}
}
];

let bidderRequest;
let result = spec.interpretResponse({ body: response }, {bidderRequest})
expect(result).to.deep.equal(expectedResponse)
});

it('handles nobid responses', function () {
let response = {
'is_ad_return': false,
Expand Down