Skip to content

Commit

Permalink
Add code, test, and doc for Adikteev adapter (#3229)
Browse files Browse the repository at this point in the history
* Add code, test, and doc for Adikteev adapter

* Reflect comments on other PR

http://prebid.org/dev-docs/bidder-adaptor.html#referrers
#3230 (comment)

* 'currency' isn't a bidder-specific param

Update PR following this remark on another one:
#3228 (comment)

* Add integration example, fix bid requestId
  • Loading branch information
piotr-yuxuan authored and idettman committed Oct 30, 2018
1 parent 4c085b8 commit 50d5097
Show file tree
Hide file tree
Showing 5 changed files with 466 additions and 2 deletions.
93 changes: 93 additions & 0 deletions integrationExamples/gpt/hello_world_adikteev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<html>

<head>
<link rel="icon" type="image/png" href="/favicon.png">
<script async src="//www.googletagservices.com/tag/js/gpt.js"></script>
<script type="text/javascript" src="../../build/dev/prebid.js" async></script>
<script>
var sizes = [
[300, 250],
[250, 300],
[300, 600]
];
var PREBID_TIMEOUT = 3000;
var FAILSAFE_TIMEOUT = 3000;

var adUnits = [{
code: '/19968336/header-bid-tag-1',
mediaTypes: {
banner: {
sizes: sizes
}
},
bids: [{
bidder: 'adikteev',
params: {
placementId: 13144370,
stagingEnvironment: true,
bidFloorPrice: 0.1,
}
}]
}];

// ======== DO NOT EDIT BELOW THIS LINE =========== //
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
});

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

pbjs.que.push(function () {
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: initAdserver,
timeout: PREBID_TIMEOUT
});
});

function initAdserver() {
if (pbjs.initAdserverSet) return;
pbjs.initAdserverSet = true;
googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}


// in case PBJS doesn't load
setTimeout(function () {
console.log("prebid.js setTimeout");
initAdserver();
}, FAILSAFE_TIMEOUT);

googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag-1', sizes, 'div-1')
.addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});

</script>

</head>

<body>
<h2>Basic Prebid.js Example</h2>
<h5>Div-1</h5>
<div id='div-1'>
<script type='text/javascript'>
googletag.cmd.push(function () {
googletag.display('div-1');
});

</script>
</div>
</body>

</html>
11 changes: 9 additions & 2 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,15 @@
width: '300',
height: '250',
}
}

},
{
bidder: 'adikteev',
params: {
placementId: 12345,
currency: 'EUR',
bidFloorPrice: 0.1,
}
},
]
}, {
code: 'div-gpt-ad-12345678-1',
Expand Down
94 changes: 94 additions & 0 deletions modules/adikteevBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {registerBidder} from 'src/adapters/bidderFactory';
import {BANNER} from 'src/mediaTypes';
import * as utils from '../src/utils';
import {config} from 'src/config';

export const BIDDER_CODE = 'adikteev';
export const ENDPOINT_URL = 'https://serve-adserver.adikteev.com/api/prebid/bid';
export const ENDPOINT_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/bid';
export const USER_SYNC_IFRAME_URL = 'https://serve-adserver.adikteev.com/api/prebid/sync-iframe';
export const USER_SYNC_IFRAME_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/sync-iframe';
export const USER_SYNC_IMAGE_URL = 'https://serve-adserver.adikteev.com/api/prebid/sync-image';
export const USER_SYNC_IMAGE_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/sync-image';

export let stagingEnvironmentSwitch = false; // Don't use it. Allow us to make tests on staging

export function setstagingEnvironmentSwitch(value) {
stagingEnvironmentSwitch = value;
}

function validateSizes(sizes) {
if (!utils.isArray(sizes) || typeof sizes[0] === 'undefined') {
return false;
}
return sizes.every(size => utils.isArray(size) && size.length === 2);
}

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

isBidRequestValid: (bid) => {
setstagingEnvironmentSwitch(stagingEnvironmentSwitch || !!bid.params.stagingEnvironment);
return !!(
bid &&
bid.params &&
bid.params.bidFloorPrice &&
bid.params.placementId &&
bid.bidder === BIDDER_CODE &&
validateSizes(bid.mediaTypes.banner.sizes)
);
},

buildRequests: (validBidRequests, bidderRequest) => {
const payload = {
validBidRequests,
bidderRequest,
refererInfo: bidderRequest.refererInfo,
currency: config.getConfig('currency'),
userAgent: navigator.userAgent,
screen: {
width: window.screen.width,
height: window.screen.height
},
language: navigator.language,
cookies: document.cookie.split(';'),
prebidUpdateVersion: '1.29.0',
};
return {
method: 'POST',
url: stagingEnvironmentSwitch ? ENDPOINT_URL_STAGING : ENDPOINT_URL,
data: JSON.stringify(payload),
};
},

interpretResponse: (serverResponse, bidRequests) => {
const returnedBids = [];
const validBidRequests = JSON.parse(bidRequests.data).validBidRequests;
serverResponse.body.forEach((value, index) => {
const overrides = {
requestId: validBidRequests[index].bidId,
};
returnedBids.push(Object.assign({}, value, overrides));
});
return returnedBids;
},

getUserSyncs: (syncOptions, serverResponses) => {
const syncs = [];
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: stagingEnvironmentSwitch ? USER_SYNC_IFRAME_URL_STAGING : USER_SYNC_IFRAME_URL,
});
}
if (syncOptions.pixelEnabled && serverResponses.length > 0) {
syncs.push({
type: 'image',
url: stagingEnvironmentSwitch ? USER_SYNC_IMAGE_URL_STAGING : USER_SYNC_IMAGE_URL,
});
}
return syncs;
},
};
registerBidder(spec);
35 changes: 35 additions & 0 deletions modules/adikteevBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Overview

```
Module Name: Adikteev Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

Module that connects to Adikteev's demand sources

# Test Parameters

``` javascript
var adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [[750, 200]], // a display size
}
},
bids: [
{
bidder: 'adikteev',
params: {
placementId: 12345,
bidFloorPrice: 0.1,
}
}
]
}
];
```
Loading

0 comments on commit 50d5097

Please sign in to comment.