Skip to content

Commit 7f48677

Browse files
piotr-yuxuanAdSpacesDevelopers
authored and
AdSpacesDevelopers
committed
Add code, test, and doc for Adikteev adapter (prebid#3229)
* Add code, test, and doc for Adikteev adapter * Reflect comments on other PR http://prebid.org/dev-docs/bidder-adaptor.html#referrers prebid#3230 (comment) * 'currency' isn't a bidder-specific param Update PR following this remark on another one: prebid#3228 (comment) * Add integration example, fix bid requestId
1 parent d2af7af commit 7f48677

File tree

5 files changed

+466
-2
lines changed

5 files changed

+466
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<html>
2+
3+
<head>
4+
<link rel="icon" type="image/png" href="/favicon.png">
5+
<script async src="//www.googletagservices.com/tag/js/gpt.js"></script>
6+
<script type="text/javascript" src="../../build/dev/prebid.js" async></script>
7+
<script>
8+
var sizes = [
9+
[300, 250],
10+
[250, 300],
11+
[300, 600]
12+
];
13+
var PREBID_TIMEOUT = 3000;
14+
var FAILSAFE_TIMEOUT = 3000;
15+
16+
var adUnits = [{
17+
code: '/19968336/header-bid-tag-1',
18+
mediaTypes: {
19+
banner: {
20+
sizes: sizes
21+
}
22+
},
23+
bids: [{
24+
bidder: 'adikteev',
25+
params: {
26+
placementId: 13144370,
27+
stagingEnvironment: true,
28+
bidFloorPrice: 0.1,
29+
}
30+
}]
31+
}];
32+
33+
// ======== DO NOT EDIT BELOW THIS LINE =========== //
34+
var googletag = googletag || {};
35+
googletag.cmd = googletag.cmd || [];
36+
googletag.cmd.push(function () {
37+
googletag.pubads().disableInitialLoad();
38+
});
39+
40+
var pbjs = pbjs || {};
41+
pbjs.que = pbjs.que || [];
42+
43+
pbjs.que.push(function () {
44+
pbjs.addAdUnits(adUnits);
45+
pbjs.requestBids({
46+
bidsBackHandler: initAdserver,
47+
timeout: PREBID_TIMEOUT
48+
});
49+
});
50+
51+
function initAdserver() {
52+
if (pbjs.initAdserverSet) return;
53+
pbjs.initAdserverSet = true;
54+
googletag.cmd.push(function () {
55+
pbjs.que.push(function () {
56+
pbjs.setTargetingForGPTAsync();
57+
googletag.pubads().refresh();
58+
});
59+
});
60+
}
61+
62+
63+
// in case PBJS doesn't load
64+
setTimeout(function () {
65+
console.log("prebid.js setTimeout");
66+
initAdserver();
67+
}, FAILSAFE_TIMEOUT);
68+
69+
googletag.cmd.push(function () {
70+
googletag.defineSlot('/19968336/header-bid-tag-1', sizes, 'div-1')
71+
.addService(googletag.pubads());
72+
googletag.pubads().enableSingleRequest();
73+
googletag.enableServices();
74+
});
75+
76+
</script>
77+
78+
</head>
79+
80+
<body>
81+
<h2>Basic Prebid.js Example</h2>
82+
<h5>Div-1</h5>
83+
<div id='div-1'>
84+
<script type='text/javascript'>
85+
googletag.cmd.push(function () {
86+
googletag.display('div-1');
87+
});
88+
89+
</script>
90+
</div>
91+
</body>
92+
93+
</html>

integrationExamples/gpt/pbjs_example_gpt.html

+9-2
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,15 @@
312312
width: '300',
313313
height: '250',
314314
}
315-
}
316-
315+
},
316+
{
317+
bidder: 'adikteev',
318+
params: {
319+
placementId: 12345,
320+
currency: 'EUR',
321+
bidFloorPrice: 0.1,
322+
}
323+
},
317324
]
318325
}, {
319326
code: 'div-gpt-ad-12345678-1',

modules/adikteevBidAdapter.js

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import {registerBidder} from 'src/adapters/bidderFactory';
2+
import {BANNER} from 'src/mediaTypes';
3+
import * as utils from '../src/utils';
4+
import {config} from 'src/config';
5+
6+
export const BIDDER_CODE = 'adikteev';
7+
export const ENDPOINT_URL = 'https://serve-adserver.adikteev.com/api/prebid/bid';
8+
export const ENDPOINT_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/bid';
9+
export const USER_SYNC_IFRAME_URL = 'https://serve-adserver.adikteev.com/api/prebid/sync-iframe';
10+
export const USER_SYNC_IFRAME_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/sync-iframe';
11+
export const USER_SYNC_IMAGE_URL = 'https://serve-adserver.adikteev.com/api/prebid/sync-image';
12+
export const USER_SYNC_IMAGE_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/sync-image';
13+
14+
export let stagingEnvironmentSwitch = false; // Don't use it. Allow us to make tests on staging
15+
16+
export function setstagingEnvironmentSwitch(value) {
17+
stagingEnvironmentSwitch = value;
18+
}
19+
20+
function validateSizes(sizes) {
21+
if (!utils.isArray(sizes) || typeof sizes[0] === 'undefined') {
22+
return false;
23+
}
24+
return sizes.every(size => utils.isArray(size) && size.length === 2);
25+
}
26+
27+
export const spec = {
28+
code: BIDDER_CODE,
29+
supportedMediaTypes: [BANNER],
30+
31+
isBidRequestValid: (bid) => {
32+
setstagingEnvironmentSwitch(stagingEnvironmentSwitch || !!bid.params.stagingEnvironment);
33+
return !!(
34+
bid &&
35+
bid.params &&
36+
bid.params.bidFloorPrice &&
37+
bid.params.placementId &&
38+
bid.bidder === BIDDER_CODE &&
39+
validateSizes(bid.mediaTypes.banner.sizes)
40+
);
41+
},
42+
43+
buildRequests: (validBidRequests, bidderRequest) => {
44+
const payload = {
45+
validBidRequests,
46+
bidderRequest,
47+
refererInfo: bidderRequest.refererInfo,
48+
currency: config.getConfig('currency'),
49+
userAgent: navigator.userAgent,
50+
screen: {
51+
width: window.screen.width,
52+
height: window.screen.height
53+
},
54+
language: navigator.language,
55+
cookies: document.cookie.split(';'),
56+
prebidUpdateVersion: '1.29.0',
57+
};
58+
return {
59+
method: 'POST',
60+
url: stagingEnvironmentSwitch ? ENDPOINT_URL_STAGING : ENDPOINT_URL,
61+
data: JSON.stringify(payload),
62+
};
63+
},
64+
65+
interpretResponse: (serverResponse, bidRequests) => {
66+
const returnedBids = [];
67+
const validBidRequests = JSON.parse(bidRequests.data).validBidRequests;
68+
serverResponse.body.forEach((value, index) => {
69+
const overrides = {
70+
requestId: validBidRequests[index].bidId,
71+
};
72+
returnedBids.push(Object.assign({}, value, overrides));
73+
});
74+
return returnedBids;
75+
},
76+
77+
getUserSyncs: (syncOptions, serverResponses) => {
78+
const syncs = [];
79+
if (syncOptions.iframeEnabled) {
80+
syncs.push({
81+
type: 'iframe',
82+
url: stagingEnvironmentSwitch ? USER_SYNC_IFRAME_URL_STAGING : USER_SYNC_IFRAME_URL,
83+
});
84+
}
85+
if (syncOptions.pixelEnabled && serverResponses.length > 0) {
86+
syncs.push({
87+
type: 'image',
88+
url: stagingEnvironmentSwitch ? USER_SYNC_IMAGE_URL_STAGING : USER_SYNC_IMAGE_URL,
89+
});
90+
}
91+
return syncs;
92+
},
93+
};
94+
registerBidder(spec);

modules/adikteevBidAdapter.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Overview
2+
3+
```
4+
Module Name: Adikteev Bidder Adapter
5+
Module Type: Bidder Adapter
6+
Maintainer: [email protected]
7+
```
8+
9+
# Description
10+
11+
Module that connects to Adikteev's demand sources
12+
13+
# Test Parameters
14+
15+
``` javascript
16+
var adUnits = [
17+
{
18+
code: 'test-div',
19+
mediaTypes: {
20+
banner: {
21+
sizes: [[750, 200]], // a display size
22+
}
23+
},
24+
bids: [
25+
{
26+
bidder: 'adikteev',
27+
params: {
28+
placementId: 12345,
29+
bidFloorPrice: 0.1,
30+
}
31+
}
32+
]
33+
}
34+
];
35+
```

0 commit comments

Comments
 (0)