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

Add New Adapter dgadsBidAdapter #2429

Merged
merged 12 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from 9 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
87 changes: 87 additions & 0 deletions modules/dgadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {registerBidder} from 'src/adapters/bidderFactory';
import * as utils from 'src/utils';
import { BANNER, NATIVE } from 'src/mediaTypes';

const BIDDER_CODE = 'dgads';
const ENDPOINT = 'https://ads-tr.bigmining.com/ad/p/bid';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [ BANNER, NATIVE ],
isBidRequestValid: function(bid) {
const params = bid.params;
if (!/^\d+$/.test(params.location_id)) {
return false;
}
if (!/^\d+$/.test(params.site_id)) {
return false;
}
return true;
},
buildRequests: function(bidRequests) {
if (bidRequests.length === 0) {
return {};
}

return bidRequests.map(bidRequest => {
const params = bidRequest.params;
const data = {};

data['location_id'] = params.location_id;
data['site_id'] = params.site_id;
data['transaction_id'] = bidRequest.transactionId;
data['bid_id'] = bidRequest.bidId;

return {
method: 'POST',
url: ENDPOINT,
data,
};
});
},
interpretResponse: function(serverResponse, bidRequest) {
const bidResponses = [];
const responseObj = serverResponse.body;
const ads = responseObj.bids;
let bidResponse = {};
if (utils.isEmpty(ads)) {
return [];
}
utils._each(ads, function(ad) {
bidResponse.requestId = ad.bidId;
bidResponse.bidderCode = BIDDER_CODE;
bidResponse.cpm = ad.cpm;
bidResponse.creativeId = ad.creativeId;
bidResponse.currency = 'JPY';
bidResponse.netRevenue = true;
bidResponse.ttl = ad.ttl;
bidResponse.referrer = utils.getTopWindowUrl();
if (ad.isNative == 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere in here I would recommend to set the bid's mediaType to native.

When I was testing the native ad with the .md file's test params, the bid's mediaType was set to the default banner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. We corresponded.

bidResponse.native = setNativeResponse(ad);
} else {
bidResponse.width = parseInt(ad.w);
bidResponse.height = parseInt(ad.h);
bidResponse.ad = ad.ad;
}
bidResponses.push(bidResponse);
});
return bidResponses;
}
};
function setNativeResponse(ad) {
let nativeResponce = {};
nativeResponce.image = {
url: ad.image,
width: parseInt(ad.w),
height: parseInt(ad.h)
}
nativeResponce.title = ad.title;
nativeResponce.body = ad.desc;
nativeResponce.sponsoredBy = ad.sponsoredBy;
nativeResponce.clickUrl = ad.clickUrl;
nativeResponce.clickTrackers = ad.clickTrackers || [];
nativeResponce.impressionTrackers = ad.impressionTrackers || [];
return nativeResponce;
}

registerBidder(spec);
65 changes: 65 additions & 0 deletions modules/dgadsBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Overview

```
Module Name: Digital Garage Ads Platform Bidder Adapter
Module Type: Bidder Adapter
Maintainer:[email protected]
```

# Description

Connect to Digital Garage Ads Platform for bids.
This adapter supports Banner and Native.

# Test Parameters
```
var adUnits = [
// Banner
{
code: 'banner-div',
sizes: [[300, 250]],
bids: [{
bidder: 'dgads',
mediaTypes: 'banner',
params: {
location_id: '1',
site_id: '1';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this semi-colon?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. We corresponded.

}
}]
},
// Native
{
code: 'native-div',
sizes: [[300, 250]],
mediaTypes: {
native: {
title: {
required: true,
len: 25
},
body: {
required: true,
len: 140
},
sponsoredBy: {
required: true,
len: 40
},
image: {
required: true
},
clickUrl: {
required: true
},
}
},
bids: [{
bidder: 'dgads',
params: {
location_id: '10',
site_id: '1'
}
}]
},
];
```
Loading