Skip to content

Commit

Permalink
Add native support to ablida Bid Adapter (#5545)
Browse files Browse the repository at this point in the history
* add onBidWon function, add bidder adapter version to bid requests

* add support for native

* use triggerPxel instead of ajax, because ajax was called 3 times with native
  • Loading branch information
Dan authored Sep 1, 2020
1 parent c4c060e commit 6af92be
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
20 changes: 11 additions & 9 deletions modules/ablidaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as utils from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {ajax} from '../src/ajax.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';

const BIDDER_CODE = 'ablida';
const ENDPOINT_URL = 'https://bidder.ablida.net/prebid';

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

/**
* Determines whether or not the given bid request is valid.
Expand All @@ -31,20 +32,22 @@ export const spec = {
return [];
}
return validBidRequests.map(bidRequest => {
const sizes = utils.parseSizesInput(bidRequest.sizes)[0];
const size = sizes.split('x');
let sizes = []
if (bidRequest.mediaTypes && bidRequest.mediaTypes[BANNER] && bidRequest.mediaTypes[BANNER].sizes) {
sizes = bidRequest.mediaTypes[BANNER].sizes;
}
const jaySupported = 'atob' in window && 'currentScript' in document;
const device = getDevice();
const payload = {
placementId: bidRequest.params.placementId,
width: size[0],
height: size[1],
sizes: sizes,
bidId: bidRequest.bidId,
categories: bidRequest.params.categories,
referer: bidderRequest.refererInfo.referer,
jaySupported: jaySupported,
device: device,
adapterVersion: 2
adapterVersion: 3,
mediaTypes: bidRequest.mediaTypes
};
return {
method: 'POST',
Expand Down Expand Up @@ -72,9 +75,8 @@ export const spec = {
return bidResponses;
},
onBidWon: function (bid) {
if (!bid['nurl']) { return false; }
ajax(bid['nurl'], null);
return true;
if (!bid['nurl']) { return; }
utils.triggerPixel(bid['nurl']);
}
};

Expand Down
26 changes: 25 additions & 1 deletion modules/ablidaBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ Module that connects to Ablida's bidder for bids.
}
}
]
}, {
code: 'native-ad-div',
mediaTypes: {
native: {
image: {
sendId: true,
required: true
},
title: {
required: true
},
body: {
required: true
}
}
},
bids: [
{
bidder: 'ablida',
params: {
placementId: 'native-demo'
}
}
]
}
];
];
```
16 changes: 12 additions & 4 deletions test/spec/modules/ablidaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {assert, expect} from 'chai';
import {spec} from 'modules/ablidaBidAdapter.js';
import {newBidder} from 'src/adapters/bidderFactory.js';
import * as utils from 'src/utils.js';

const ENDPOINT_URL = 'https://bidder.ablida.net/prebid';

Expand Down Expand Up @@ -104,16 +105,23 @@ describe('ablidaBidAdapter', function () {
});

describe('onBidWon', function() {
it('Should not ajax call if bid does not contain nurl', function() {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});

it('Should not trigger pixel if bid does not contain nurl', function() {
const result = spec.onBidWon({});
expect(result).to.equal(false)
expect(utils.triggerPixel.callCount).to.equal(0)
})

it('Should ajax call if bid nurl', function() {
it('Should trigger pixel if bid nurl', function() {
const result = spec.onBidWon({
nurl: 'https://example.com/some-tracker'
});
expect(result).to.equal(true)
expect(utils.triggerPixel.callCount).to.equal(1)
})
})
});

0 comments on commit 6af92be

Please sign in to comment.