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

AdHash Bid Adapter: changes to support preroll videos #9870

Merged
merged 33 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e7d3b8a
AdHash Bidder Adapter: minor changes
wyand-sp Jan 7, 2022
814f3a8
Implemented brand safety
wyand-sp Jan 18, 2022
d5e34de
Fix for GDPR consent
wyand-sp Mar 10, 2022
4eb1553
Merge branch 'prebid:master' into master
wyand-sp Mar 10, 2022
bdc4fad
Ad fraud prevention formula changed
wyand-sp Mar 16, 2022
35f24dc
AdHash brand safety additions
wyand-sp Apr 14, 2022
e681fbd
AdHash brand safety updates
wyand-sp Jun 28, 2022
c837c36
Merge branch 'master' of https://github.com/AdHashProtocol/Prebid.js
wyand-sp Aug 5, 2022
a6c5faf
AdHash Analytics adapter
wyand-sp Aug 5, 2022
fc5809d
Merge branch 'prebid:master' into master
wyand-sp Aug 10, 2022
3fa0e52
Support for recent ads
wyand-sp Aug 17, 2022
66fddd1
Fix for timestamp
wyand-sp Aug 18, 2022
0c7953c
PUB-222
Sep 15, 2022
66d14ba
Unit tests for the analytics adapter
Sep 19, 2022
1c2470a
Removed export causing errors
Sep 19, 2022
6e4148b
Added globalScript parameter
wyand-sp Sep 26, 2022
ae443ae
Merge branch 'prebid:master' into master
wyand-sp Oct 4, 2022
441240d
PUB-227
vsaraminev Oct 4, 2022
a589f12
Merge branch 'prebid:master' into master
wyand-sp Oct 12, 2022
8dacbc9
GEN-964
M1TKO Oct 28, 2022
9cd75bf
GEN-1025
Nov 16, 2022
dbd9f3d
Removing the analytics adaptor
wyand-sp Nov 28, 2022
65a0d26
Fix for regexp match
wyand-sp Nov 28, 2022
e27cbe4
Version change
wyand-sp Nov 28, 2022
d68efac
MINOR
wyand-sp Dec 7, 2022
e8ab5c2
Merge branch 'prebid:master' into master
wyand-sp Feb 7, 2023
78dea30
GEN-1153
Apr 27, 2023
340e473
MINOR
wyand-sp Apr 28, 2023
cc6994b
Merge branch 'prebid:master' into master
wyand-sp Apr 28, 2023
9ee05e2
Removing globalScript flag
wyand-sp May 9, 2023
2d9d9f2
Merge branch 'prebid:master' into master
wyand-sp May 18, 2023
17cce26
Merge branch 'prebid:master' into master
wyand-sp May 18, 2023
c5942e5
Merge branch 'prebid:master' into master
wyand-sp May 19, 2023
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
45 changes: 28 additions & 17 deletions modules/adhashBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
import { includes } from '../src/polyfill.js';
import { BANNER } from '../src/mediaTypes.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

const VERSION = '3.2';
const BAD_WORD_STEP = 0.1;
Expand Down Expand Up @@ -130,13 +130,13 @@ function brandSafety(badWords, maxScore) {

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

isBidRequestValid: (bid) => {
try {
const { publisherId, platformURL, bidderURL } = bid.params;
return (
includes(Object.keys(bid.mediaTypes), BANNER) &&
(includes(Object.keys(bid.mediaTypes), BANNER) || includes(Object.keys(bid.mediaTypes), VIDEO)) &&
typeof publisherId === 'string' &&
publisherId.length === 42 &&
typeof platformURL === 'string' &&
Expand Down Expand Up @@ -168,7 +168,14 @@ export const spec = {
const url = `${bidderURL}/rtb?version=${VERSION}&prebid=true`;
const index = Math.floor(Math.random() * validBidRequests[i].sizes.length);
const size = validBidRequests[i].sizes[index].join('x');

const creativeData = includes(Object.keys(validBidRequests[i].mediaTypes), VIDEO) ? {
size: 'preroll',
position: validBidRequests[i].adUnitCode,
playerSize: size
} : {
size: size,
position: validBidRequests[i].adUnitCode
};
let recentAds = [];
if (storage.localStorageIsEnabled()) {
const prefix = validBidRequests[i].params.prefix || 'adHash';
Expand Down Expand Up @@ -204,10 +211,7 @@ export const spec = {
language: window.navigator.language,
userAgent: window.navigator.userAgent
},
creatives: [{
size: size,
position: validBidRequests[i].adUnitCode
}],
creatives: [creativeData],
blockedCreatives: [],
currentTimestamp: (new Date().getTime() / 1000) | 0,
recentAds: recentAds,
Expand All @@ -229,7 +233,6 @@ export const spec = {

interpretResponse: (serverResponse, request) => {
const responseBody = serverResponse ? serverResponse.body : {};

if (
!responseBody.creatives ||
responseBody.creatives.length === 0 ||
Expand All @@ -241,18 +244,12 @@ export const spec = {
const publisherURL = JSON.stringify(request.bidRequest.params.platformURL);
const bidderURL = request.bidRequest.params.bidderURL || 'https://bidder.adhash.com';
const oneTimeId = request.bidRequest.adUnitCode + Math.random().toFixed(16).replace('0.', '.');
const globalScript = !request.bidRequest.params.globalScript
? `<script src="${bidderURL}/static/scripts/creative.min.js"></script>`
: '';
const bidderResponse = JSON.stringify({ responseText: JSON.stringify(responseBody) });
const requestData = JSON.stringify(request.data);

return [{
var response = {
requestId: request.bidRequest.bidId,
cpm: responseBody.creatives[0].costEUR,
ad:
`<div id="${oneTimeId}"></div>${globalScript}
<script>callAdvertiser(${bidderResponse},['${oneTimeId}'],${requestData},${publisherURL})</script>`,
width: request.bidRequest.sizes[0][0],
height: request.bidRequest.sizes[0][1],
creativeId: request.bidRequest.adUnitCode,
Expand All @@ -262,7 +259,21 @@ export const spec = {
meta: {
advertiserDomains: responseBody.advertiserDomains ? [responseBody.advertiserDomains] : []
}
}];
};
if (typeof request == 'object' && typeof request.bidRequest == 'object' && typeof request.bidRequest.mediaTypes == 'object' && includes(Object.keys(request.bidRequest.mediaTypes), BANNER)) {
response = Object.assign({
ad:
`<div id="${oneTimeId}"></div>
<script src="${bidderURL}/static/scripts/creative.min.js"></script>
<script>callAdvertiser(${bidderResponse},['${oneTimeId}'],${requestData},${publisherURL})</script>`
}, response);
} else if (includes(Object.keys(request.bidRequest.mediaTypes), VIDEO)) {
response = Object.assign({
vastUrl: responseBody.creatives[0].vastURL,
mediaType: VIDEO
}, response);
}
return [response];
}
};

Expand Down
52 changes: 51 additions & 1 deletion test/spec/modules/adhashBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ describe('adhashBidAdapter', function () {
publisherId: '0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb'
},
sizes: [[300, 250]],
adUnitCode: 'adUnitCode'
adUnitCode: 'adUnitCode',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
}
};
it('should build the request correctly', function () {
const result = spec.buildRequests(
Expand Down Expand Up @@ -122,6 +127,11 @@ describe('adhashBidAdapter', function () {
sizes: [[300, 250]],
params: {
platformURL: 'https://adhash.com/p/struma/'
},
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
}
}
};
Expand Down Expand Up @@ -267,5 +277,45 @@ describe('adhashBidAdapter', function () {
it('should return empty array when something is not right', function () {
expect(spec.interpretResponse(null, request).length).to.equal(0);
});

it('should interpret the video response correctly', function () {
const result = spec.interpretResponse({
body: {
creatives: [{ costEUR: 1.234, vastURL: 'https://example.com/vast' }],
advertiserDomains: 'adhash.com'
}
}, {
data: { some: 'data' },
bidRequest: {
bidId: '12345678901234',
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
params: {
platformURL: 'https://adhash.com/p/struma/'
},
mediaTypes: {
video: {
context: 'instream',
playerSize: [300, 250],
mimes: ['video/mp4'],
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
playbackmethod: [2],
skip: 1
}
}
}
});
expect(result.length).to.equal(1);
expect(result[0].requestId).to.equal('12345678901234');
expect(result[0].cpm).to.equal(1.234);
expect(result[0].width).to.equal(300);
expect(result[0].height).to.equal(250);
expect(result[0].creativeId).to.equal('adunit-code');
expect(result[0].netRevenue).to.equal(true);
expect(result[0].currency).to.equal('EUR');
expect(result[0].ttl).to.equal(60);
expect(result[0].meta.advertiserDomains).to.eql(['adhash.com']);
expect(result[0].vastUrl).to.equal('https://example.com/vast');
});
});
});