Skip to content

Commit

Permalink
Add integration example, fix bid requestId
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-yuxuan committed Oct 30, 2018
1 parent 5bd6d47 commit 32674cd
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 7 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>
17 changes: 13 additions & 4 deletions modules/adikteevBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const spec = {
bid.params.placementId &&
bid.bidder === BIDDER_CODE &&
validateSizes(bid.mediaTypes.banner.sizes)
)
);
},

buildRequests: (validBidRequests, bidderRequest) => {
Expand All @@ -55,15 +55,24 @@ export const spec = {
cookies: document.cookie.split(';'),
prebidUpdateVersion: '1.29.0',
};
const payloadString = JSON.stringify(payload);
return {
method: 'POST',
url: stagingEnvironmentSwitch ? ENDPOINT_URL_STAGING : ENDPOINT_URL,
data: payloadString,
data: JSON.stringify(payload),
};
},

interpretResponse: ({body}) => body,
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 = [];
Expand Down
15 changes: 12 additions & 3 deletions test/spec/modules/adikteevBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ describe('adikteevBidAdapter', () => {
{
body: [
{
requestId: '1258a5aa-d08f-11e8-a8d5-f2801f1b9fd1',
cpm: 1,
width: 300,
height: 250,
Expand All @@ -156,7 +155,17 @@ describe('adikteevBidAdapter', () => {
}
]
};
const bidResponses = spec.interpretResponse(serverResponse);
const payload = {
validBidRequests: [{
bidId: '2ef7bb021ac847'
}],
};
const bidRequests = {
method: 'POST',
url: stagingEnvironmentSwitch ? ENDPOINT_URL_STAGING : ENDPOINT_URL,
data: JSON.stringify(payload),
};
const bidResponses = spec.interpretResponse(serverResponse, bidRequests);
expect(bidResponses).to.be.an('array').that.is.not.empty; // yes, syntax is correct
expect(bidResponses[0]).to.have.all.keys(
'requestId',
Expand All @@ -170,7 +179,7 @@ describe('adikteevBidAdapter', () => {
'currency',
);

expect(bidResponses[0].requestId).to.equal(serverResponse.body[0].requestId);
expect(bidResponses[0].requestId).to.equal(payload.validBidRequests[0].bidId);
expect(bidResponses[0].cpm).to.equal(serverResponse.body[0].cpm);
expect(bidResponses[0].width).to.equal(serverResponse.body[0].width);
expect(bidResponses[0].height).to.equal(serverResponse.body[0].height);
Expand Down

0 comments on commit 32674cd

Please sign in to comment.