From c96a5af56c49a401db307da2d1af1a7e7a1e16c1 Mon Sep 17 00:00:00 2001
From: banakemi
Date: Mon, 5 Jul 2021 20:41:44 +0900
Subject: [PATCH 1/5] update AdGenerationBidAdapter for ver5.x. adding adomain
---
modules/adgenerationBidAdapter.js | 242 +++++++++++
.../modules/adgenerationBidAdapter_spec.js | 410 ++++++++++++++++++
2 files changed, 652 insertions(+)
create mode 100644 modules/adgenerationBidAdapter.js
create mode 100644 test/spec/modules/adgenerationBidAdapter_spec.js
diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js
new file mode 100644
index 00000000000..0cc88ab4f54
--- /dev/null
+++ b/modules/adgenerationBidAdapter.js
@@ -0,0 +1,242 @@
+import * as utils from '../src/utils.js';
+import {registerBidder} from '../src/adapters/bidderFactory.js';
+import {BANNER, NATIVE} from '../src/mediaTypes.js';
+import {config} from '../src/config.js';
+
+const ADG_BIDDER_CODE = 'adgeneration';
+
+export const spec = {
+ code: ADG_BIDDER_CODE,
+ aliases: ['adg'], // short code
+ supportedMediaTypes: [BANNER, NATIVE],
+ /**
+ * Determines whether or not the given bid request is valid.
+ *
+ * @param {BidRequest} bid The bid params to validate.
+ * @return boolean True if this is a valid bid, and false otherwise.
+ */
+ isBidRequestValid: function (bid) {
+ return !!(bid.params.id);
+ },
+ /**
+ * Make a server request from the list of BidRequests.
+ *
+ * @param {validBidRequests[]} - an array of bids
+ * @return ServerRequest Info describing the request to the server.
+ */
+ buildRequests: function (validBidRequests, bidderRequest) {
+ const ADGENE_PREBID_VERSION = '1.1.0';
+ let serverRequests = [];
+ for (let i = 0, len = validBidRequests.length; i < len; i++) {
+ const validReq = validBidRequests[i];
+ const DEBUG_URL = 'https://api-test.scaleout.jp/adsv/v1';
+ const URL = 'https://d.socdm.com/adsv/v1';
+ const url = validReq.params.debug ? DEBUG_URL : URL;
+ let data = ``;
+ data = utils.tryAppendQueryString(data, 'posall', 'SSPLOC');
+ const id = utils.getBidIdParameter('id', validReq.params);
+ data = utils.tryAppendQueryString(data, 'id', id);
+ data = utils.tryAppendQueryString(data, 'sdktype', '0');
+ data = utils.tryAppendQueryString(data, 'hb', 'true');
+ data = utils.tryAppendQueryString(data, 't', 'json3');
+ data = utils.tryAppendQueryString(data, 'transactionid', validReq.transactionId);
+ data = utils.tryAppendQueryString(data, 'sizes', getSizes(validReq));
+ data = utils.tryAppendQueryString(data, 'currency', getCurrencyType());
+ data = utils.tryAppendQueryString(data, 'pbver', '$prebid.version$');
+ data = utils.tryAppendQueryString(data, 'sdkname', 'prebidjs');
+ data = utils.tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION);
+ // native以外にvideo等の対応が入った場合は要修正
+ if (!validReq.mediaTypes || !validReq.mediaTypes.native) {
+ data = utils.tryAppendQueryString(data, 'imark', '1');
+ }
+ data = utils.tryAppendQueryString(data, 'tp', bidderRequest.refererInfo.referer);
+ // remove the trailing "&"
+ if (data.lastIndexOf('&') === data.length - 1) {
+ data = data.substring(0, data.length - 1);
+ }
+ serverRequests.push({
+ method: 'GET',
+ url: url,
+ data: data,
+ bidRequest: validBidRequests[i]
+ });
+ }
+ return serverRequests;
+ },
+ /**
+ * Unpack the response from the server into a list of bids.
+ *
+ * @param {ServerResponse} serverResponse A successful response from the server.
+ * @param {BidRequest} bidRequests
+ * @return {Bid[]} An array of bids which were nested inside the server.
+ */
+ interpretResponse: function (serverResponse, bidRequests) {
+ const body = serverResponse.body;
+ if (!body.results || body.results.length < 1) {
+ return [];
+ }
+ const bidRequest = bidRequests.bidRequest;
+ const bidResponse = {
+ requestId: bidRequest.bidId,
+ cpm: body.cpm || 0,
+ width: body.w ? body.w : 1,
+ height: body.h ? body.h : 1,
+ creativeId: body.creativeid || '',
+ dealId: body.dealid || '',
+ currency: getCurrencyType(),
+ netRevenue: true,
+ ttl: body.ttl || 10,
+ };
+ if (body.adomain && body.adomain.length) {
+ bidResponse.meta = {
+ advertiserDomains: body.adomain
+ }
+ }
+ if (isNative(body)) {
+ bidResponse.native = createNativeAd(body);
+ bidResponse.mediaType = NATIVE;
+ } else {
+ // banner
+ bidResponse.ad = createAd(body, bidRequest);
+ }
+ return [bidResponse];
+ },
+
+ /**
+ * Register the user sync pixels which should be dropped after the auction.
+ *
+ * @param {SyncOptions} syncOptions Which user syncs are allowed?
+ * @param {ServerResponse[]} serverResponses List of server's responses.
+ * @return {UserSync[]} The user syncs which should be dropped.
+ */
+ getUserSyncs: function (syncOptions, serverResponses) {
+ const syncs = [];
+ return syncs;
+ }
+};
+
+function createAd(body, bidRequest) {
+ let ad = body.ad;
+ if (body.vastxml && body.vastxml.length > 0) {
+ ad = `${createAPVTag()}${insertVASTMethod(bidRequest.bidId, body.vastxml)}`;
+ }
+ ad = appendChildToBody(ad, body.beacon);
+ if (removeWrapper(ad)) return removeWrapper(ad);
+ return ad;
+}
+
+function isNative(body) {
+ if (!body) return false;
+ return body.native_ad && body.native_ad.assets.length > 0;
+}
+
+function createNativeAd(body) {
+ let native = {};
+ if (body.native_ad && body.native_ad.assets.length > 0) {
+ const assets = body.native_ad.assets;
+ for (let i = 0, len = assets.length; i < len; i++) {
+ switch (assets[i].id) {
+ case 1:
+ native.title = assets[i].title.text;
+ break;
+ case 2:
+ native.image = {
+ url: assets[i].img.url,
+ height: assets[i].img.h,
+ width: assets[i].img.w,
+ };
+ break;
+ case 3:
+ native.icon = {
+ url: assets[i].img.url,
+ height: assets[i].img.h,
+ width: assets[i].img.w,
+ };
+ break;
+ case 4:
+ native.sponsoredBy = assets[i].data.value;
+ break;
+ case 5:
+ native.body = assets[i].data.value;
+ break;
+ case 6:
+ native.cta = assets[i].data.value;
+ break;
+ case 502:
+ native.privacyLink = encodeURIComponent(assets[i].data.value);
+ break;
+ }
+ }
+ native.clickUrl = body.native_ad.link.url;
+ native.clickTrackers = body.native_ad.link.clicktrackers || [];
+ native.impressionTrackers = body.native_ad.imptrackers || [];
+ if (body.beaconurl && body.beaconurl != '') {
+ native.impressionTrackers.push(body.beaconurl)
+ }
+ }
+ return native;
+}
+
+function appendChildToBody(ad, data) {
+ return ad.replace(/<\/\s?body>/, `${data}
');
+ const lastBodyIndex = ad.lastIndexOf('', '').replace('
↵ ↵ ↵
↵ Creative<\/body>'}
+ ],
+ rotation: '0',
+ scheduleid: '512603',
+ sdktype: '0',
+ creativeid: '1k2kv35vsa5r',
+ dealid: 'fd5sa5fa7f',
+ ttl: 1000
+ }
+ };
+
+ const bidResponses = {
+ banner: {
+ requestId: '2f6ac468a9c15e',
+ cpm: 36.0008,
+ width: 320,
+ height: 100,
+ creativeId: '1k2kv35vsa5r',
+ dealId: 'fd5sa5fa7f',
+ currency: 'JPY',
+ netRevenue: true,
+ ttl: 1000,
+ ad: '↵ ↵
',
+ adomain: ['advertiserdomain.com']
+ },
+ native: {
+ requestId: '2f6ac468a9c15e',
+ cpm: 36.0008,
+ width: 1,
+ height: 1,
+ creativeId: '1k2kv35vsa5r',
+ dealId: 'fd5sa5fa7f',
+ currency: 'JPY',
+ netRevenue: true,
+ ttl: 1000,
+ ad: '↵ ↵ ↵
↵ ',
+ native: {
+ title: 'Title',
+ image: {
+ url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
+ height: 250,
+ width: 300
+ },
+ icon: {
+ url: 'https://placehold.jp/300x300.png',
+ height: 300,
+ width: 300
+ },
+ sponsoredBy: 'Sponsored',
+ body: 'Description',
+ cta: 'CTA',
+ privacyLink: 'https://supership.jp/optout/#',
+ clickUrl: 'https://supership.jp',
+ clickTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'],
+ impressionTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif']
+ },
+ mediaType: NATIVE
+ }
+ };
+
+ it('no bid responses', function () {
+ const result = spec.interpretResponse({body: serverResponse.noAd}, bidRequests.banner);
+ expect(result.length).to.equal(0);
+ });
+
+ it('handles banner responses', function () {
+ const result = spec.interpretResponse({body: serverResponse.banner}, bidRequests.banner)[0];
+ expect(result.requestId).to.equal(bidResponses.banner.requestId);
+ expect(result.width).to.equal(bidResponses.banner.width);
+ expect(result.height).to.equal(bidResponses.banner.height);
+ expect(result.creativeId).to.equal(bidResponses.banner.creativeId);
+ expect(result.dealId).to.equal(bidResponses.banner.dealId);
+ expect(result.currency).to.equal(bidResponses.banner.currency);
+ expect(result.netRevenue).to.equal(bidResponses.banner.netRevenue);
+ expect(result.ttl).to.equal(bidResponses.banner.ttl);
+ expect(result.ad).to.equal(bidResponses.banner.ad);
+ expect(result.meta.advertiserDomains).deep.equal(bidResponses.banner.adomain);
+ });
+
+ it('handles native responses', function () {
+ const result = spec.interpretResponse({body: serverResponse.native}, bidRequests.native)[0];
+ expect(result.requestId).to.equal(bidResponses.native.requestId);
+ expect(result.width).to.equal(bidResponses.native.width);
+ expect(result.height).to.equal(bidResponses.native.height);
+ expect(result.creativeId).to.equal(bidResponses.native.creativeId);
+ expect(result.dealId).to.equal(bidResponses.native.dealId);
+ expect(result.currency).to.equal(bidResponses.native.currency);
+ expect(result.netRevenue).to.equal(bidResponses.native.netRevenue);
+ expect(result.ttl).to.equal(bidResponses.native.ttl);
+ expect(result.native.title).to.equal(bidResponses.native.native.title);
+ expect(result.native.image.url).to.equal(bidResponses.native.native.image.url);
+ expect(result.native.image.height).to.equal(bidResponses.native.native.image.height);
+ expect(result.native.image.width).to.equal(bidResponses.native.native.image.width);
+ expect(result.native.icon.url).to.equal(bidResponses.native.native.icon.url);
+ expect(result.native.icon.width).to.equal(bidResponses.native.native.icon.width);
+ expect(result.native.icon.height).to.equal(bidResponses.native.native.icon.height);
+ expect(result.native.sponsoredBy).to.equal(bidResponses.native.native.sponsoredBy);
+ expect(result.native.body).to.equal(bidResponses.native.native.body);
+ expect(result.native.cta).to.equal(bidResponses.native.native.cta);
+ expect(decodeURIComponent(result.native.privacyLink)).to.equal(bidResponses.native.native.privacyLink);
+ expect(result.native.clickUrl).to.equal(bidResponses.native.native.clickUrl);
+ expect(result.native.impressionTrackers[0]).to.equal(bidResponses.native.native.impressionTrackers[0]);
+ expect(result.native.clickTrackers[0]).to.equal(bidResponses.native.native.clickTrackers[0]);
+ expect(result.mediaType).to.equal(bidResponses.native.mediaType);
+ });
+ });
+});
From 6a6b6c43c1af809ec0fa1ff0b537f387a7781334 Mon Sep 17 00:00:00 2001
From: banakemi
Date: Tue, 6 Jul 2021 14:51:59 +0900
Subject: [PATCH 2/5] Fixed adomain value check.
---
modules/adgenerationBidAdapter.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js
index 0cc88ab4f54..1ed0de30eb6 100644
--- a/modules/adgenerationBidAdapter.js
+++ b/modules/adgenerationBidAdapter.js
@@ -87,7 +87,7 @@ export const spec = {
netRevenue: true,
ttl: body.ttl || 10,
};
- if (body.adomain && body.adomain.length) {
+ if (body.adomain && Array.isArray(body.adomain) && body.adomain[0].length) {
bidResponse.meta = {
advertiserDomains: body.adomain
}
From 8b95650fd9a761d4df134d28a65a1dcb955c2ccf Mon Sep 17 00:00:00 2001
From: banakemi
Date: Tue, 6 Jul 2021 14:59:46 +0900
Subject: [PATCH 3/5] Fixed test_spec for adomain
---
test/spec/modules/adgenerationBidAdapter_spec.js | 3 +++
1 file changed, 3 insertions(+)
diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js
index 025079ff0ce..4688a53ca48 100644
--- a/test/spec/modules/adgenerationBidAdapter_spec.js
+++ b/test/spec/modules/adgenerationBidAdapter_spec.js
@@ -227,6 +227,7 @@ describe('AdgenerationAdapter', function () {
ids: {},
location_params: null,
locationid: '58279',
+ adomain: ['advertiserdomain.com'],
native_ad: {
assets: [
{
@@ -336,6 +337,7 @@ describe('AdgenerationAdapter', function () {
currency: 'JPY',
netRevenue: true,
ttl: 1000,
+ adomain: ['advertiserdomain.com'],
ad: '↵ ↵ ↵
↵ ',
native: {
title: 'Title',
@@ -405,6 +407,7 @@ describe('AdgenerationAdapter', function () {
expect(result.native.impressionTrackers[0]).to.equal(bidResponses.native.native.impressionTrackers[0]);
expect(result.native.clickTrackers[0]).to.equal(bidResponses.native.native.clickTrackers[0]);
expect(result.mediaType).to.equal(bidResponses.native.mediaType);
+ expect(result.meta.advertiserDomains).deep.equal(bidResponses.native.adomain);
});
});
});
From 55303604ab7ac631a575958e7b4a6e633182509e Mon Sep 17 00:00:00 2001
From: banakemi
Date: Wed, 7 Jul 2021 10:53:56 +0900
Subject: [PATCH 4/5] Fixed adomain value check.
---
modules/adgenerationBidAdapter.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js
index 1ed0de30eb6..f43fd284bad 100644
--- a/modules/adgenerationBidAdapter.js
+++ b/modules/adgenerationBidAdapter.js
@@ -87,7 +87,7 @@ export const spec = {
netRevenue: true,
ttl: body.ttl || 10,
};
- if (body.adomain && Array.isArray(body.adomain) && body.adomain[0].length) {
+ if (body.adomain && Array.isArray(body.adomain) && body.adomain.length) {
bidResponse.meta = {
advertiserDomains: body.adomain
}
From 20cdafd3ab916c5dcad337d6f541fe7023f2efb0 Mon Sep 17 00:00:00 2001
From: banakemi
Date: Wed, 7 Jul 2021 17:03:02 +0900
Subject: [PATCH 5/5] Fixed test_spec for adomain
---
.../modules/adgenerationBidAdapter_spec.js | 776 ++++++++++++++----
1 file changed, 596 insertions(+), 180 deletions(-)
diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js
index 4688a53ca48..7eacba2f7d4 100644
--- a/test/spec/modules/adgenerationBidAdapter_spec.js
+++ b/test/spec/modules/adgenerationBidAdapter_spec.js
@@ -198,169 +198,497 @@ describe('AdgenerationAdapter', function () {
noAd: {
results: [],
},
- banner: {
- ad: '↵ ↵
',
- beacon: '',
- cpm: 36.0008,
- displaytype: '1',
- ids: {},
- w: 320,
- h: 100,
- location_params: null,
- locationid: '58279',
- rotation: '0',
- scheduleid: '512603',
- sdktype: '0',
- creativeid: '1k2kv35vsa5r',
- dealid: 'fd5sa5fa7f',
- ttl: 1000,
- results: [
- {ad: '
'},
- ],
- adomain: ['advertiserdomain.com']
- },
- native: {
- ad: '↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵
↵ ',
- beacon: '',
- cpm: 36.0008,
- displaytype: '1',
- ids: {},
- location_params: null,
- locationid: '58279',
- adomain: ['advertiserdomain.com'],
- native_ad: {
- assets: [
- {
- data: {
- label: 'accompanying_text',
- value: 'AD'
+ normal: {
+ banner: {
+ ad: '↵ ↵
',
+ beacon: '',
+ cpm: 36.0008,
+ displaytype: '1',
+ ids: {},
+ w: 320,
+ h: 100,
+ location_params: null,
+ locationid: '58279',
+ rotation: '0',
+ scheduleid: '512603',
+ sdktype: '0',
+ creativeid: '1k2kv35vsa5r',
+ dealid: 'fd5sa5fa7f',
+ ttl: 1000,
+ results: [
+ {ad: '
'},
+ ],
+ adomain: ['advertiserdomain.com']
+ },
+ native: {
+ ad: '↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵
↵ ',
+ beacon: '',
+ cpm: 36.0008,
+ displaytype: '1',
+ ids: {},
+ location_params: null,
+ locationid: '58279',
+ adomain: ['advertiserdomain.com'],
+ native_ad: {
+ assets: [
+ {
+ data: {
+ label: 'accompanying_text',
+ value: 'AD'
+ },
+ id: 501
},
- id: 501
- },
- {
- data: {
- label: 'optout_url',
- value: 'https://supership.jp/optout/#'
+ {
+ data: {
+ label: 'optout_url',
+ value: 'https://supership.jp/optout/#'
+ },
+ id: 502
},
- id: 502
- },
- {
- data: {
- ext: {
- black_back: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_white.png',
+ {
+ data: {
+ ext: {
+ black_back: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_white.png',
+ },
+ label: 'information_icon_url',
+ value: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_gray.png',
+ id: 503
+ }
+ },
+ {
+ id: 1,
+ required: 1,
+ title: {text: 'Title'}
+ },
+ {
+ id: 2,
+ img: {
+ h: 250,
+ url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
+ w: 300
+ },
+ required: 1
+ },
+ {
+ id: 3,
+ img: {
+ h: 300,
+ url: 'https://placehold.jp/300x300.png',
+ w: 300
},
- label: 'information_icon_url',
- value: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_gray.png',
- id: 503
+ required: 1
+ },
+ {
+ data: {value: 'Description'},
+ id: 5,
+ required: 0
+ },
+ {
+ data: {value: 'CTA'},
+ id: 6,
+ required: 0
+ },
+ {
+ data: {value: 'Sponsored'},
+ id: 4,
+ required: 0
}
+ ],
+ imptrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif'],
+ link: {
+ clicktrackers: [
+ 'https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'
+ ],
+ url: 'https://supership.jp'
},
- {
- id: 1,
- required: 1,
- title: {text: 'Title'}
- },
- {
- id: 2,
- img: {
- h: 250,
- url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
- w: 300
+ },
+ results: [
+ {ad: 'Creative<\/body>'}
+ ],
+ rotation: '0',
+ scheduleid: '512603',
+ sdktype: '0',
+ creativeid: '1k2kv35vsa5r',
+ dealid: 'fd5sa5fa7f',
+ ttl: 1000
+ }
+ },
+ emptyAdomain: {
+ banner: {
+ ad: '↵ ↵
',
+ beacon: '',
+ cpm: 36.0008,
+ displaytype: '1',
+ ids: {},
+ w: 320,
+ h: 100,
+ location_params: null,
+ locationid: '58279',
+ rotation: '0',
+ scheduleid: '512603',
+ sdktype: '0',
+ creativeid: '1k2kv35vsa5r',
+ dealid: 'fd5sa5fa7f',
+ ttl: 1000,
+ results: [
+ {ad: '
'},
+ ],
+ adomain: []
+ },
+ native: {
+ ad: '↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵
↵ ',
+ beacon: '',
+ cpm: 36.0008,
+ displaytype: '1',
+ ids: {},
+ location_params: null,
+ locationid: '58279',
+ adomain: [],
+ native_ad: {
+ assets: [
+ {
+ data: {
+ label: 'accompanying_text',
+ value: 'AD'
+ },
+ id: 501
},
- required: 1
- },
- {
- id: 3,
- img: {
- h: 300,
- url: 'https://placehold.jp/300x300.png',
- w: 300
+ {
+ data: {
+ label: 'optout_url',
+ value: 'https://supership.jp/optout/#'
+ },
+ id: 502
},
- required: 1
- },
- {
- data: {value: 'Description'},
- id: 5,
- required: 0
- },
- {
- data: {value: 'CTA'},
- id: 6,
- required: 0
+ {
+ data: {
+ ext: {
+ black_back: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_white.png',
+ },
+ label: 'information_icon_url',
+ value: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_gray.png',
+ id: 503
+ }
+ },
+ {
+ id: 1,
+ required: 1,
+ title: {text: 'Title'}
+ },
+ {
+ id: 2,
+ img: {
+ h: 250,
+ url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
+ w: 300
+ },
+ required: 1
+ },
+ {
+ id: 3,
+ img: {
+ h: 300,
+ url: 'https://placehold.jp/300x300.png',
+ w: 300
+ },
+ required: 1
+ },
+ {
+ data: {value: 'Description'},
+ id: 5,
+ required: 0
+ },
+ {
+ data: {value: 'CTA'},
+ id: 6,
+ required: 0
+ },
+ {
+ data: {value: 'Sponsored'},
+ id: 4,
+ required: 0
+ }
+ ],
+ imptrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif'],
+ link: {
+ clicktrackers: [
+ 'https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'
+ ],
+ url: 'https://supership.jp'
},
- {
- data: {value: 'Sponsored'},
- id: 4,
- required: 0
- }
+ },
+ results: [
+ {ad: 'Creative<\/body>'}
+ ],
+ rotation: '0',
+ scheduleid: '512603',
+ sdktype: '0',
+ creativeid: '1k2kv35vsa5r',
+ dealid: 'fd5sa5fa7f',
+ ttl: 1000
+ }
+ },
+ noAdomain: {
+ banner: {
+ ad: '↵ ↵
',
+ beacon: '',
+ cpm: 36.0008,
+ displaytype: '1',
+ ids: {},
+ w: 320,
+ h: 100,
+ location_params: null,
+ locationid: '58279',
+ rotation: '0',
+ scheduleid: '512603',
+ sdktype: '0',
+ creativeid: '1k2kv35vsa5r',
+ dealid: 'fd5sa5fa7f',
+ ttl: 1000,
+ results: [
+ {ad: '
'},
],
- imptrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif'],
- link: {
- clicktrackers: [
- 'https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'
+ },
+ native: {
+ ad: '↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵ ↵
↵ ',
+ beacon: '',
+ cpm: 36.0008,
+ displaytype: '1',
+ ids: {},
+ location_params: null,
+ locationid: '58279',
+ native_ad: {
+ assets: [
+ {
+ data: {
+ label: 'accompanying_text',
+ value: 'AD'
+ },
+ id: 501
+ },
+ {
+ data: {
+ label: 'optout_url',
+ value: 'https://supership.jp/optout/#'
+ },
+ id: 502
+ },
+ {
+ data: {
+ ext: {
+ black_back: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_white.png',
+ },
+ label: 'information_icon_url',
+ value: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_gray.png',
+ id: 503
+ }
+ },
+ {
+ id: 1,
+ required: 1,
+ title: {text: 'Title'}
+ },
+ {
+ id: 2,
+ img: {
+ h: 250,
+ url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
+ w: 300
+ },
+ required: 1
+ },
+ {
+ id: 3,
+ img: {
+ h: 300,
+ url: 'https://placehold.jp/300x300.png',
+ w: 300
+ },
+ required: 1
+ },
+ {
+ data: {value: 'Description'},
+ id: 5,
+ required: 0
+ },
+ {
+ data: {value: 'CTA'},
+ id: 6,
+ required: 0
+ },
+ {
+ data: {value: 'Sponsored'},
+ id: 4,
+ required: 0
+ }
],
- url: 'https://supership.jp'
+ imptrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif'],
+ link: {
+ clicktrackers: [
+ 'https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'
+ ],
+ url: 'https://supership.jp'
+ },
},
- },
- results: [
- {ad: 'Creative<\/body>'}
- ],
- rotation: '0',
- scheduleid: '512603',
- sdktype: '0',
- creativeid: '1k2kv35vsa5r',
- dealid: 'fd5sa5fa7f',
- ttl: 1000
+ results: [
+ {ad: 'Creative<\/body>'}
+ ],
+ rotation: '0',
+ scheduleid: '512603',
+ sdktype: '0',
+ creativeid: '1k2kv35vsa5r',
+ dealid: 'fd5sa5fa7f',
+ ttl: 1000
+ }
}
};
const bidResponses = {
- banner: {
- requestId: '2f6ac468a9c15e',
- cpm: 36.0008,
- width: 320,
- height: 100,
- creativeId: '1k2kv35vsa5r',
- dealId: 'fd5sa5fa7f',
- currency: 'JPY',
- netRevenue: true,
- ttl: 1000,
- ad: '↵ ↵
',
- adomain: ['advertiserdomain.com']
- },
- native: {
- requestId: '2f6ac468a9c15e',
- cpm: 36.0008,
- width: 1,
- height: 1,
- creativeId: '1k2kv35vsa5r',
- dealId: 'fd5sa5fa7f',
- currency: 'JPY',
- netRevenue: true,
- ttl: 1000,
- adomain: ['advertiserdomain.com'],
- ad: '↵ ↵ ↵
↵ ',
+ normal: {
+ banner: {
+ requestId: '2f6ac468a9c15e',
+ cpm: 36.0008,
+ width: 320,
+ height: 100,
+ creativeId: '1k2kv35vsa5r',
+ dealId: 'fd5sa5fa7f',
+ currency: 'JPY',
+ netRevenue: true,
+ ttl: 1000,
+ ad: '↵ ↵
',
+ adomain: ['advertiserdomain.com']
+ },
native: {
- title: 'Title',
- image: {
- url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
- height: 250,
- width: 300
+ requestId: '2f6ac468a9c15e',
+ cpm: 36.0008,
+ width: 1,
+ height: 1,
+ creativeId: '1k2kv35vsa5r',
+ dealId: 'fd5sa5fa7f',
+ currency: 'JPY',
+ netRevenue: true,
+ ttl: 1000,
+ adomain: ['advertiserdomain.com'],
+ ad: '↵ ↵ ↵
↵ ',
+ native: {
+ title: 'Title',
+ image: {
+ url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
+ height: 250,
+ width: 300
+ },
+ icon: {
+ url: 'https://placehold.jp/300x300.png',
+ height: 300,
+ width: 300
+ },
+ sponsoredBy: 'Sponsored',
+ body: 'Description',
+ cta: 'CTA',
+ privacyLink: 'https://supership.jp/optout/#',
+ clickUrl: 'https://supership.jp',
+ clickTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'],
+ impressionTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif']
},
- icon: {
- url: 'https://placehold.jp/300x300.png',
- height: 300,
- width: 300
+ mediaType: NATIVE
+ }
+ },
+ emptyAdomain: {
+ banner: {
+ requestId: '2f6ac468a9c15e',
+ cpm: 36.0008,
+ width: 320,
+ height: 100,
+ creativeId: '1k2kv35vsa5r',
+ dealId: 'fd5sa5fa7f',
+ currency: 'JPY',
+ netRevenue: true,
+ ttl: 1000,
+ ad: '↵ ↵
',
+ adomain: []
+ },
+ native: {
+ requestId: '2f6ac468a9c15e',
+ cpm: 36.0008,
+ width: 1,
+ height: 1,
+ creativeId: '1k2kv35vsa5r',
+ dealId: 'fd5sa5fa7f',
+ currency: 'JPY',
+ netRevenue: true,
+ ttl: 1000,
+ adomain: [],
+ ad: '↵ ↵ ↵
↵ ',
+ native: {
+ title: 'Title',
+ image: {
+ url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
+ height: 250,
+ width: 300
+ },
+ icon: {
+ url: 'https://placehold.jp/300x300.png',
+ height: 300,
+ width: 300
+ },
+ sponsoredBy: 'Sponsored',
+ body: 'Description',
+ cta: 'CTA',
+ privacyLink: 'https://supership.jp/optout/#',
+ clickUrl: 'https://supership.jp',
+ clickTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'],
+ impressionTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif']
},
- sponsoredBy: 'Sponsored',
- body: 'Description',
- cta: 'CTA',
- privacyLink: 'https://supership.jp/optout/#',
- clickUrl: 'https://supership.jp',
- clickTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'],
- impressionTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif']
+ mediaType: NATIVE
},
- mediaType: NATIVE
- }
+ },
+ noAdomain: {
+ banner: {
+ requestId: '2f6ac468a9c15e',
+ cpm: 36.0008,
+ width: 320,
+ height: 100,
+ creativeId: '1k2kv35vsa5r',
+ dealId: 'fd5sa5fa7f',
+ currency: 'JPY',
+ netRevenue: true,
+ ttl: 1000,
+ ad: '↵ ↵
',
+ },
+ native: {
+ requestId: '2f6ac468a9c15e',
+ cpm: 36.0008,
+ width: 1,
+ height: 1,
+ creativeId: '1k2kv35vsa5r',
+ dealId: 'fd5sa5fa7f',
+ currency: 'JPY',
+ netRevenue: true,
+ ttl: 1000,
+ ad: '↵ ↵ ↵
↵ ',
+ native: {
+ title: 'Title',
+ image: {
+ url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
+ height: 250,
+ width: 300
+ },
+ icon: {
+ url: 'https://placehold.jp/300x300.png',
+ height: 300,
+ width: 300
+ },
+ sponsoredBy: 'Sponsored',
+ body: 'Description',
+ cta: 'CTA',
+ privacyLink: 'https://supership.jp/optout/#',
+ clickUrl: 'https://supership.jp',
+ clickTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'],
+ impressionTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif']
+ },
+ mediaType: NATIVE
+ }
+ },
};
it('no bid responses', function () {
@@ -369,45 +697,133 @@ describe('AdgenerationAdapter', function () {
});
it('handles banner responses', function () {
- const result = spec.interpretResponse({body: serverResponse.banner}, bidRequests.banner)[0];
- expect(result.requestId).to.equal(bidResponses.banner.requestId);
- expect(result.width).to.equal(bidResponses.banner.width);
- expect(result.height).to.equal(bidResponses.banner.height);
- expect(result.creativeId).to.equal(bidResponses.banner.creativeId);
- expect(result.dealId).to.equal(bidResponses.banner.dealId);
- expect(result.currency).to.equal(bidResponses.banner.currency);
- expect(result.netRevenue).to.equal(bidResponses.banner.netRevenue);
- expect(result.ttl).to.equal(bidResponses.banner.ttl);
- expect(result.ad).to.equal(bidResponses.banner.ad);
- expect(result.meta.advertiserDomains).deep.equal(bidResponses.banner.adomain);
+ const result = spec.interpretResponse({body: serverResponse.normal.banner}, bidRequests.banner)[0];
+ expect(result.requestId).to.equal(bidResponses.normal.banner.requestId);
+ expect(result.width).to.equal(bidResponses.normal.banner.width);
+ expect(result.height).to.equal(bidResponses.normal.banner.height);
+ expect(result.creativeId).to.equal(bidResponses.normal.banner.creativeId);
+ expect(result.dealId).to.equal(bidResponses.normal.banner.dealId);
+ expect(result.currency).to.equal(bidResponses.normal.banner.currency);
+ expect(result.netRevenue).to.equal(bidResponses.normal.banner.netRevenue);
+ expect(result.ttl).to.equal(bidResponses.normal.banner.ttl);
+ expect(result.ad).to.equal(bidResponses.normal.banner.ad);
+ expect(result.meta.advertiserDomains).deep.equal(bidResponses.normal.banner.adomain);
});
it('handles native responses', function () {
- const result = spec.interpretResponse({body: serverResponse.native}, bidRequests.native)[0];
- expect(result.requestId).to.equal(bidResponses.native.requestId);
- expect(result.width).to.equal(bidResponses.native.width);
- expect(result.height).to.equal(bidResponses.native.height);
- expect(result.creativeId).to.equal(bidResponses.native.creativeId);
- expect(result.dealId).to.equal(bidResponses.native.dealId);
- expect(result.currency).to.equal(bidResponses.native.currency);
- expect(result.netRevenue).to.equal(bidResponses.native.netRevenue);
- expect(result.ttl).to.equal(bidResponses.native.ttl);
- expect(result.native.title).to.equal(bidResponses.native.native.title);
- expect(result.native.image.url).to.equal(bidResponses.native.native.image.url);
- expect(result.native.image.height).to.equal(bidResponses.native.native.image.height);
- expect(result.native.image.width).to.equal(bidResponses.native.native.image.width);
- expect(result.native.icon.url).to.equal(bidResponses.native.native.icon.url);
- expect(result.native.icon.width).to.equal(bidResponses.native.native.icon.width);
- expect(result.native.icon.height).to.equal(bidResponses.native.native.icon.height);
- expect(result.native.sponsoredBy).to.equal(bidResponses.native.native.sponsoredBy);
- expect(result.native.body).to.equal(bidResponses.native.native.body);
- expect(result.native.cta).to.equal(bidResponses.native.native.cta);
- expect(decodeURIComponent(result.native.privacyLink)).to.equal(bidResponses.native.native.privacyLink);
- expect(result.native.clickUrl).to.equal(bidResponses.native.native.clickUrl);
- expect(result.native.impressionTrackers[0]).to.equal(bidResponses.native.native.impressionTrackers[0]);
- expect(result.native.clickTrackers[0]).to.equal(bidResponses.native.native.clickTrackers[0]);
- expect(result.mediaType).to.equal(bidResponses.native.mediaType);
- expect(result.meta.advertiserDomains).deep.equal(bidResponses.native.adomain);
+ const result = spec.interpretResponse({body: serverResponse.normal.native}, bidRequests.native)[0];
+ expect(result.requestId).to.equal(bidResponses.normal.native.requestId);
+ expect(result.width).to.equal(bidResponses.normal.native.width);
+ expect(result.height).to.equal(bidResponses.normal.native.height);
+ expect(result.creativeId).to.equal(bidResponses.normal.native.creativeId);
+ expect(result.dealId).to.equal(bidResponses.normal.native.dealId);
+ expect(result.currency).to.equal(bidResponses.normal.native.currency);
+ expect(result.netRevenue).to.equal(bidResponses.normal.native.netRevenue);
+ expect(result.ttl).to.equal(bidResponses.normal.native.ttl);
+ expect(result.native.title).to.equal(bidResponses.normal.native.native.title);
+ expect(result.native.image.url).to.equal(bidResponses.normal.native.native.image.url);
+ expect(result.native.image.height).to.equal(bidResponses.normal.native.native.image.height);
+ expect(result.native.image.width).to.equal(bidResponses.normal.native.native.image.width);
+ expect(result.native.icon.url).to.equal(bidResponses.normal.native.native.icon.url);
+ expect(result.native.icon.width).to.equal(bidResponses.normal.native.native.icon.width);
+ expect(result.native.icon.height).to.equal(bidResponses.normal.native.native.icon.height);
+ expect(result.native.sponsoredBy).to.equal(bidResponses.normal.native.native.sponsoredBy);
+ expect(result.native.body).to.equal(bidResponses.normal.native.native.body);
+ expect(result.native.cta).to.equal(bidResponses.normal.native.native.cta);
+ expect(decodeURIComponent(result.native.privacyLink)).to.equal(bidResponses.normal.native.native.privacyLink);
+ expect(result.native.clickUrl).to.equal(bidResponses.normal.native.native.clickUrl);
+ expect(result.native.impressionTrackers[0]).to.equal(bidResponses.normal.native.native.impressionTrackers[0]);
+ expect(result.native.clickTrackers[0]).to.equal(bidResponses.normal.native.native.clickTrackers[0]);
+ expect(result.mediaType).to.equal(bidResponses.normal.native.mediaType);
+ expect(result.meta.advertiserDomains).deep.equal(bidResponses.normal.native.adomain);
+ });
+
+ it('handles banner responses for empty adomain', function () {
+ const result = spec.interpretResponse({body: serverResponse.emptyAdomain.banner}, bidRequests.banner)[0];
+ expect(result.requestId).to.equal(bidResponses.emptyAdomain.banner.requestId);
+ expect(result.width).to.equal(bidResponses.emptyAdomain.banner.width);
+ expect(result.height).to.equal(bidResponses.emptyAdomain.banner.height);
+ expect(result.creativeId).to.equal(bidResponses.emptyAdomain.banner.creativeId);
+ expect(result.dealId).to.equal(bidResponses.emptyAdomain.banner.dealId);
+ expect(result.currency).to.equal(bidResponses.emptyAdomain.banner.currency);
+ expect(result.netRevenue).to.equal(bidResponses.emptyAdomain.banner.netRevenue);
+ expect(result.ttl).to.equal(bidResponses.emptyAdomain.banner.ttl);
+ expect(result.ad).to.equal(bidResponses.emptyAdomain.banner.ad);
+ expect(result).to.not.have.any.keys('meta');
+ expect(result).to.not.have.any.keys('advertiserDomains');
+ });
+
+ it('handles native responses for empty adomain', function () {
+ const result = spec.interpretResponse({body: serverResponse.emptyAdomain.native}, bidRequests.native)[0];
+ expect(result.requestId).to.equal(bidResponses.emptyAdomain.native.requestId);
+ expect(result.width).to.equal(bidResponses.emptyAdomain.native.width);
+ expect(result.height).to.equal(bidResponses.emptyAdomain.native.height);
+ expect(result.creativeId).to.equal(bidResponses.emptyAdomain.native.creativeId);
+ expect(result.dealId).to.equal(bidResponses.emptyAdomain.native.dealId);
+ expect(result.currency).to.equal(bidResponses.emptyAdomain.native.currency);
+ expect(result.netRevenue).to.equal(bidResponses.emptyAdomain.native.netRevenue);
+ expect(result.ttl).to.equal(bidResponses.emptyAdomain.native.ttl);
+ expect(result.native.title).to.equal(bidResponses.emptyAdomain.native.native.title);
+ expect(result.native.image.url).to.equal(bidResponses.emptyAdomain.native.native.image.url);
+ expect(result.native.image.height).to.equal(bidResponses.emptyAdomain.native.native.image.height);
+ expect(result.native.image.width).to.equal(bidResponses.emptyAdomain.native.native.image.width);
+ expect(result.native.icon.url).to.equal(bidResponses.emptyAdomain.native.native.icon.url);
+ expect(result.native.icon.width).to.equal(bidResponses.emptyAdomain.native.native.icon.width);
+ expect(result.native.icon.height).to.equal(bidResponses.emptyAdomain.native.native.icon.height);
+ expect(result.native.sponsoredBy).to.equal(bidResponses.emptyAdomain.native.native.sponsoredBy);
+ expect(result.native.body).to.equal(bidResponses.emptyAdomain.native.native.body);
+ expect(result.native.cta).to.equal(bidResponses.emptyAdomain.native.native.cta);
+ expect(decodeURIComponent(result.native.privacyLink)).to.equal(bidResponses.emptyAdomain.native.native.privacyLink);
+ expect(result.native.clickUrl).to.equal(bidResponses.emptyAdomain.native.native.clickUrl);
+ expect(result.native.impressionTrackers[0]).to.equal(bidResponses.emptyAdomain.native.native.impressionTrackers[0]);
+ expect(result.native.clickTrackers[0]).to.equal(bidResponses.emptyAdomain.native.native.clickTrackers[0]);
+ expect(result.mediaType).to.equal(bidResponses.emptyAdomain.native.mediaType);
+ expect(result).to.not.have.any.keys('meta');
+ expect(result).to.not.have.any.keys('advertiserDomains');
+ });
+
+ it('handles banner responses for no adomain', function () {
+ const result = spec.interpretResponse({body: serverResponse.noAdomain.banner}, bidRequests.banner)[0];
+ expect(result.requestId).to.equal(bidResponses.noAdomain.banner.requestId);
+ expect(result.width).to.equal(bidResponses.noAdomain.banner.width);
+ expect(result.height).to.equal(bidResponses.noAdomain.banner.height);
+ expect(result.creativeId).to.equal(bidResponses.noAdomain.banner.creativeId);
+ expect(result.dealId).to.equal(bidResponses.noAdomain.banner.dealId);
+ expect(result.currency).to.equal(bidResponses.noAdomain.banner.currency);
+ expect(result.netRevenue).to.equal(bidResponses.noAdomain.banner.netRevenue);
+ expect(result.ttl).to.equal(bidResponses.noAdomain.banner.ttl);
+ expect(result.ad).to.equal(bidResponses.noAdomain.banner.ad);
+ expect(result).to.not.have.any.keys('meta');
+ expect(result).to.not.have.any.keys('advertiserDomains');
+ });
+
+ it('handles native responses for no adomain', function () {
+ const result = spec.interpretResponse({body: serverResponse.noAdomain.native}, bidRequests.native)[0];
+ expect(result.requestId).to.equal(bidResponses.noAdomain.native.requestId);
+ expect(result.width).to.equal(bidResponses.noAdomain.native.width);
+ expect(result.height).to.equal(bidResponses.noAdomain.native.height);
+ expect(result.creativeId).to.equal(bidResponses.noAdomain.native.creativeId);
+ expect(result.dealId).to.equal(bidResponses.noAdomain.native.dealId);
+ expect(result.currency).to.equal(bidResponses.noAdomain.native.currency);
+ expect(result.netRevenue).to.equal(bidResponses.noAdomain.native.netRevenue);
+ expect(result.ttl).to.equal(bidResponses.noAdomain.native.ttl);
+ expect(result.native.title).to.equal(bidResponses.noAdomain.native.native.title);
+ expect(result.native.image.url).to.equal(bidResponses.noAdomain.native.native.image.url);
+ expect(result.native.image.height).to.equal(bidResponses.noAdomain.native.native.image.height);
+ expect(result.native.image.width).to.equal(bidResponses.noAdomain.native.native.image.width);
+ expect(result.native.icon.url).to.equal(bidResponses.noAdomain.native.native.icon.url);
+ expect(result.native.icon.width).to.equal(bidResponses.noAdomain.native.native.icon.width);
+ expect(result.native.icon.height).to.equal(bidResponses.noAdomain.native.native.icon.height);
+ expect(result.native.sponsoredBy).to.equal(bidResponses.noAdomain.native.native.sponsoredBy);
+ expect(result.native.body).to.equal(bidResponses.noAdomain.native.native.body);
+ expect(result.native.cta).to.equal(bidResponses.noAdomain.native.native.cta);
+ expect(decodeURIComponent(result.native.privacyLink)).to.equal(bidResponses.noAdomain.native.native.privacyLink);
+ expect(result.native.clickUrl).to.equal(bidResponses.noAdomain.native.native.clickUrl);
+ expect(result.native.impressionTrackers[0]).to.equal(bidResponses.noAdomain.native.native.impressionTrackers[0]);
+ expect(result.native.clickTrackers[0]).to.equal(bidResponses.noAdomain.native.native.clickTrackers[0]);
+ expect(result.mediaType).to.equal(bidResponses.noAdomain.native.mediaType);
+ expect(result).to.not.have.any.keys('meta');
+ expect(result).to.not.have.any.keys('advertiserDomains');
});
});
});
`);
+}
+
+function createAPVTag() {
+ const APVURL = 'https://cdn.apvdr.com/js/VideoAd.min.js';
+ let apvScript = document.createElement('script');
+ apvScript.type = 'text/javascript';
+ apvScript.id = 'apv';
+ apvScript.src = APVURL;
+ return apvScript.outerHTML;
+}
+
+function insertVASTMethod(targetId, vastXml) {
+ let apvVideoAdParam = {
+ s: targetId
+ };
+ let script = document.createElement(`script`);
+ script.type = 'text/javascript';
+ script.innerHTML = `(function(){ new APV.VideoAd(${JSON.stringify(apvVideoAdParam)}).load('${vastXml.replace(/\r?\n/g, '')}'); })();`;
+ return script.outerHTML;
+}
+
+/**
+ *
+ * @param ad
+ */
+function removeWrapper(ad) {
+ const bodyIndex = ad.indexOf('
');
+ if (bodyIndex === -1 || lastBodyIndex === -1) return false;
+ return ad.substr(bodyIndex, lastBodyIndex).replace('
', '');
+}
+
+/**
+ * request
+ * @param validReq request
+ * @returns {?string} 300x250,320x50...
+ */
+function getSizes(validReq) {
+ const sizes = validReq.sizes;
+ if (!sizes || sizes.length < 1) return null;
+ let sizesStr = '';
+ for (const i in sizes) {
+ const size = sizes[i];
+ if (size.length !== 2) return null;
+ sizesStr += `${size[0]}x${size[1]},`;
+ }
+ if (sizesStr || sizesStr.lastIndexOf(',') === sizesStr.length - 1) {
+ sizesStr = sizesStr.substring(0, sizesStr.length - 1);
+ }
+ return sizesStr;
+}
+
+/**
+ * @return {?string} USD or JPY
+ */
+function getCurrencyType() {
+ if (config.getConfig('currency.adServerCurrency') && config.getConfig('currency.adServerCurrency').toUpperCase() === 'USD') return 'USD';
+ return 'JPY';
+}
+
+registerBidder(spec);
diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js
new file mode 100644
index 00000000000..025079ff0ce
--- /dev/null
+++ b/test/spec/modules/adgenerationBidAdapter_spec.js
@@ -0,0 +1,410 @@
+import {expect} from 'chai';
+import {spec} from 'modules/adgenerationBidAdapter.js';
+import {newBidder} from 'src/adapters/bidderFactory.js';
+import {NATIVE} from 'src/mediaTypes.js';
+import {config} from 'src/config.js';
+import prebid from '../../../package.json';
+
+describe('AdgenerationAdapter', function () {
+ const adapter = newBidder(spec);
+ const ENDPOINT = ['https://api-test.scaleout.jp/adsv/v1', 'https://d.socdm.com/adsv/v1'];
+
+ describe('inherited functions', function () {
+ it('exists and is a function', function () {
+ expect(adapter.callBids).to.exist.and.to.be.a('function');
+ });
+ });
+
+ describe('isBidRequestValid', function () {
+ const bid = {
+ 'bidder': 'adg',
+ 'params': {
+ id: '58278', // banner
+ }
+ };
+ it('should return true when required params found', function () {
+ expect(spec.isBidRequestValid(bid)).to.equal(true);
+ });
+
+ it('should return false when required params are not passed', function () {
+ let bid = Object.assign({}, bid);
+ delete bid.params;
+ bid.params = {};
+ expect(spec.isBidRequestValid(bid)).to.equal(false);
+ });
+ });
+
+ describe('buildRequests', function () {
+ const bidRequests = [
+ { // banner
+ bidder: 'adg',
+ params: {
+ id: '58278',
+ currency: 'JPY',
+ },
+ adUnitCode: 'adunit-code',
+ sizes: [[300, 250], [320, 100]],
+ bidId: '2f6ac468a9c15e',
+ bidderRequestId: '14a9f773e30243',
+ auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a',
+ transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a'
+ },
+ { // native
+ bidder: 'adg',
+ params: {
+ id: '58278',
+ currency: 'JPY',
+ },
+ mediaTypes: {
+ native: {
+ image: {
+ required: true
+ },
+ title: {
+ required: true,
+ len: 80
+ },
+ sponsoredBy: {
+ required: true
+ },
+ clickUrl: {
+ required: true
+ },
+ body: {
+ required: true
+ },
+ icon: {
+ required: true
+ }
+ },
+ },
+ adUnitCode: 'adunit-code',
+ sizes: [[1, 1]],
+ bidId: '2f6ac468a9c15e',
+ bidderRequestId: '14a9f773e30243',
+ auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a',
+ transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a'
+ }
+ ];
+ const bidderRequest = {
+ refererInfo: {
+ referer: 'https://example.com'
+ }
+ };
+ const data = {
+ banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=${prebid.version}&sdkname=prebidjs&adapterver=1.1.0&imark=1&tp=https%3A%2F%2Fexample.com`,
+ bannerUSD: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=USD&pbver=${prebid.version}&sdkname=prebidjs&adapterver=1.1.0&imark=1&tp=https%3A%2F%2Fexample.com`,
+ native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=' + prebid.version + '&sdkname=prebidjs&adapterver=1.1.0&tp=https%3A%2F%2Fexample.com'
+ };
+ it('sends bid request to ENDPOINT via GET', function () {
+ const request = spec.buildRequests(bidRequests, bidderRequest)[0];
+ expect(request.url).to.equal(ENDPOINT[1]);
+ expect(request.method).to.equal('GET');
+ });
+
+ it('sends bid request to debug ENDPOINT via GET', function () {
+ bidRequests[0].params.debug = true;
+ const request = spec.buildRequests(bidRequests, bidderRequest)[0];
+ expect(request.url).to.equal(ENDPOINT[0]);
+ expect(request.method).to.equal('GET');
+ });
+
+ it('should attache params to the banner request', function () {
+ const request = spec.buildRequests(bidRequests, bidderRequest)[0];
+ expect(request.data).to.equal(data.banner);
+ });
+
+ it('should attache params to the native request', function () {
+ const request = spec.buildRequests(bidRequests, bidderRequest)[1];
+ expect(request.data).to.equal(data.native);
+ });
+ it('allows setConfig to set bidder currency for JPY', function () {
+ config.setConfig({
+ currency: {
+ adServerCurrency: 'JPY'
+ }
+ });
+ const request = spec.buildRequests(bidRequests, bidderRequest)[0];
+ expect(request.data).to.equal(data.banner);
+ config.resetConfig();
+ });
+ it('allows setConfig to set bidder currency for USD', function () {
+ config.setConfig({
+ currency: {
+ adServerCurrency: 'USD'
+ }
+ });
+ const request = spec.buildRequests(bidRequests, bidderRequest)[0];
+ expect(request.data).to.equal(data.bannerUSD);
+ config.resetConfig();
+ });
+ });
+ describe('interpretResponse', function () {
+ const bidRequests = {
+ banner: {
+ bidRequest: {
+ bidder: 'adg',
+ params: {
+ id: '58278', // banner
+ },
+ adUnitCode: 'adunit-code',
+ sizes: [[320, 100]],
+ bidId: '2f6ac468a9c15e',
+ bidderRequestId: '14a9f773e30243',
+ auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a',
+ transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a'
+ },
+ },
+ native: {
+ bidRequest: {
+ bidder: 'adg',
+ params: {
+ id: '58278', // banner
+ },
+ mediaTypes: {
+ native: {
+ image: {
+ required: true
+ },
+ title: {
+ required: true,
+ len: 80
+ },
+ sponsoredBy: {
+ required: true
+ },
+ clickUrl: {
+ required: true
+ },
+ body: {
+ required: true
+ },
+ icon: {
+ required: true
+ }
+ }
+ },
+ adUnitCode: 'adunit-code',
+ sizes: [[1, 1]],
+ bidId: '2f6ac468a9c15e',
+ bidderRequestId: '14a9f773e30243',
+ auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a',
+ transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a'
+ },
+ },
+ };
+
+ const serverResponse = {
+ noAd: {
+ results: [],
+ },
+ banner: {
+ ad: '
↵ ↵
',
+ beacon: '',
+ cpm: 36.0008,
+ displaytype: '1',
+ ids: {},
+ w: 320,
+ h: 100,
+ location_params: null,
+ locationid: '58279',
+ rotation: '0',
+ scheduleid: '512603',
+ sdktype: '0',
+ creativeid: '1k2kv35vsa5r',
+ dealid: 'fd5sa5fa7f',
+ ttl: 1000,
+ results: [
+ {ad: '
'},
+ ],
+ adomain: ['advertiserdomain.com']
+ },
+ native: {
+ ad: '↵
↵ ↵ ↵ ↵ ↵ ↵
',
+ beacon: '',
+ cpm: 36.0008,
+ displaytype: '1',
+ ids: {},
+ location_params: null,
+ locationid: '58279',
+ native_ad: {
+ assets: [
+ {
+ data: {
+ label: 'accompanying_text',
+ value: 'AD'
+ },
+ id: 501
+ },
+ {
+ data: {
+ label: 'optout_url',
+ value: 'https://supership.jp/optout/#'
+ },
+ id: 502
+ },
+ {
+ data: {
+ ext: {
+ black_back: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_white.png',
+ },
+ label: 'information_icon_url',
+ value: 'https://i.socdm.com/sdk/img/icon_adg_optout_26x26_gray.png',
+ id: 503
+ }
+ },
+ {
+ id: 1,
+ required: 1,
+ title: {text: 'Title'}
+ },
+ {
+ id: 2,
+ img: {
+ h: 250,
+ url: 'https://sdk-temp.s3-ap-northeast-1.amazonaws.com/adg-sample-ad/img/300x250.png',
+ w: 300
+ },
+ required: 1
+ },
+ {
+ id: 3,
+ img: {
+ h: 300,
+ url: 'https://placehold.jp/300x300.png',
+ w: 300
+ },
+ required: 1
+ },
+ {
+ data: {value: 'Description'},
+ id: 5,
+ required: 0
+ },
+ {
+ data: {value: 'CTA'},
+ id: 6,
+ required: 0
+ },
+ {
+ data: {value: 'Sponsored'},
+ id: 4,
+ required: 0
+ }
+ ],
+ imptrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif'],
+ link: {
+ clicktrackers: [
+ 'https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1_clicktracker_access.gif'
+ ],
+ url: 'https://supership.jp'
+ },
+ },
+ results: [
+ {ad: '