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

Sekindo Prebid Adapter : #355

Merged
merged 8 commits into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
9 changes: 8 additions & 1 deletion integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@
publisher_id: 5000563, // REQUIRED int or str publisher ID. To get one, register at https://control.adequant.com
bidfloor: 0.01, // OPTIONAL float bid floor in $ CPM
}
}
},
{
bidder: 'sekindo',
params: {
spaceId: 14071, // REQUIRED int. To get one, contact http://www.sekindo.com
bidfloor: 0.2 // OPTIONAL float bid floor in $ CPM
}
}
]
}, {
code: 'div-gpt-ad-12345678-1',
Expand Down
106 changes: 106 additions & 0 deletions src/adapters/sekindo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { getBidRequest } from '../utils.js';
var CONSTANTS = require('../constants.json');
var utils = require('../utils.js');
var bidfactory = require('../bidfactory.js');
var bidmanager = require('../bidmanager.js');

var SekindoAdapter;
SekindoAdapter = function SekindoAdapter() {

function _callBids(params) {
var bids = params.bids;
var bidsCount = bids.length;

var pubUrl = null;
if (parent !== window)
pubUrl = document.referrer;
else
pubUrl = window.location.href;

for (var i = 0; i < bidsCount; i++) {
var bidReqeust = bids[i];
var callbackId = bidReqeust.bidId;
_requestBids(bidReqeust, callbackId, pubUrl);
//store a reference to the bidRequest from the callback id
//bidmanager.pbCallbackMap[callbackId] = bidReqeust;
}
}

pbjs.sekindoCB = function(callbackId, response)
{
if (typeof (response) != 'undefined' && typeof (response.cpm) != 'undefined')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use triple equality.

{
var bidObj = getBidRequest(callbackId);
var bid = [];
if (bidObj)
{
var bidCode = bidObj.bidder;
var placementCode = bidObj.placementCode;

if (response.cpm !== undefined && response.cpm > 0)
{

bid = bidfactory.createBid(CONSTANTS.STATUS.GOOD);
bid.adId = response.adId;
bid.callback_uid = callbackId;
bid.bidderCode = bidCode;
bid.creative_id = response.adId;
bid.cpm = parseFloat(response.cpm);
bid.ad = response.ad;
bid.width = response.width;
bid.height = response.height;

bidmanager.addBidResponse(placementCode, bid);
}
else
{
bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID);
bid.callback_uid = callbackId;
bid.bidderCode = bidCode;
bidmanager.addBidResponse(placementCode, bid);
}
}
}
else
{
utils.logMessage('No prebid response for placement %%PLACEMENT%%');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to replace %%PLACEMENT%% with the actual placement name here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sekindo
This has not been updated in the PR.

}
};

function _requestBids(bid, callbackId, pubUrl)
{
//determine tag params
var spaceId = utils.getBidIdParamater('spaceId', bid.params);
var bidfloor = utils.getBidIdParamater('bidfloor', bid.params);
var protocol = ('https:' === document.location.protocol ? 's' : '');
var scriptSrc = 'https://live.sekindo.com/live/liveView.php?';

scriptSrc = utils.tryAppendQueryString(scriptSrc, 's', spaceId);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'pubUrl', pubUrl);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbcb', callbackId);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'dcpmflr', bidfloor);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbto', pbjs.bidderTimeout);
scriptSrc = utils.tryAppendQueryString(scriptSrc, 'protocol', protocol);

var html = '<scr'+'ipt type="text/javascript" src="'+scriptSrc+'"></scr'+'ipt>';

var iframe = utils.createInvisibleIframe();
iframe.id = 'skIfr_'+callbackId;

var elToAppend = document.getElementsByTagName('head')[0];
//insert the iframe into document
elToAppend.insertBefore(iframe, elToAppend.firstChild);

var iframeDoc = utils.getIframeDocument(iframe);
iframeDoc.write(html);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this script be loaded asynchronously?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cannot, we use the iframe for async.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should document.open first before writing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. added

iframeDoc.close();
}

return {
callBids: _callBids
};
};


module.exports = SekindoAdapter;