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

added usersync for adkernel adapter #951

Merged
merged 1 commit into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 25 additions & 6 deletions src/adapters/adkernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const AdKernelAdapter = function AdKernelAdapter() {
const _dispatch = {};
const originalBids = {};
const site = createSite();
const syncedHostZones = {};

//translate adunit info into rtb impression dispatched by host/zone
this.addImp = function (bid) {
Expand All @@ -48,16 +49,34 @@ const AdKernelAdapter = function AdKernelAdapter() {
//save rtb impression for specified ad-network host and zone
_dispatch[host][zone].push(imp);
originalBids[bidId] = bid;
//perform user-sync
if (!(host in syncedHostZones)){
syncedHostZones[host] = [];
}
if (syncedHostZones[host].indexOf(zone) === -1) {
syncedHostZones[host].push(zone);
insertUserSync(host, zone);
}
};

function insertUserSync(host, zone) {
var iframe = utils.createInvisibleIframe();
iframe.src = `//${host}/user-sync?zone=${zone}`;
try {
document.body.appendChild(iframe);
} catch (error) {
utils.logError(error);
}
}

/**
* Main function to get bid requests
*/
this.dispatch = function (callback) {
utils._each(_dispatch, (zones, host) => {
utils.logMessage('processing network ' + host);
utils.logMessage(`processing network ${host}`);
utils._each(zones, (impressions, zone) => {
utils.logMessage('processing zone ' + zone);
utils.logMessage(`processing zone ${zone}`);
dispatchRtbRequest(host, zone, impressions, callback);
});
});
Expand Down Expand Up @@ -106,7 +125,7 @@ const AdKernelAdapter = function AdKernelAdapter() {
* Build ad-network specific endpoint url
*/
function buildEndpointUrl(host) {
return window.location.protocol + '//' + host + '/rtbg';
return `${window.location.protocol}//${host}/rtbg`;
}

function buildRequestParams(zone, rtbReq) {
Expand Down Expand Up @@ -134,7 +153,7 @@ const AdKernelAdapter = function AdKernelAdapter() {
//process individual bids
utils._each(bids, (bid) => {
if (!validateBidParams(bid.params)) {
utils.logError('Incorrect configuration for adkernel bidder:', bid.params);
utils.logError(`Incorrect configuration for adkernel bidder: ${bid.params}`);
bidmanager.addBidResponse(bid.placementCode, createEmptyBidObject(bid));
} else {
dispatcher.addImp(bid);
Expand All @@ -144,10 +163,10 @@ const AdKernelAdapter = function AdKernelAdapter() {
dispatcher.dispatch((bid, imp, bidResp) => {
let adUnitId = bid.placementCode;
if (bidResp) {
utils.logMessage('got response for ' + adUnitId);
utils.logMessage(`got response for ${adUnitId}`);
bidmanager.addBidResponse(adUnitId, createBidObject(bidResp, bid, imp.banner.w, imp.banner.h));
} else {
utils.logMessage('got empty response for ' + adUnitId);
utils.logMessage(`got empty response for ${adUnitId}`);
bidmanager.addBidResponse(adUnitId, createEmptyBidObject(bid));
}
});
Expand Down
11 changes: 11 additions & 0 deletions test/spec/adapters/adkernel_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ describe('Adkernel adapter', () => {
expect(result.bids[0].ad).to.include(bidResponse1.seatbid[0].bid[0].nurl);
});

it('should perform usersync for each unique host/zone combination', () => {
ajaxStub.callsArgWith(1, '');
const expectedSyncUrls = ['http://rtb.adkernel.com/user-sync?zone=1', 'http://rtb.adkernel.com/user-sync?zone=2',
'http://rtb-private.adkernel.com/user-sync?zone=1'];
sandbox.spy(utils, 'createInvisibleIframe');
doRequest([bid1_zone1, bid2_zone2, bid2_zone2, bid3_host2]);
expect(utils.createInvisibleIframe.calledThrice);
let userSyncUrls = utils.createInvisibleIframe.returnValues.map( val => val.src);
expect(userSyncUrls).to.be.eql(expectedSyncUrls);
});

});

describe('adapter aliasing', () => {
Expand Down