Skip to content

Commit

Permalink
Added support for user syncing pixel (prebid#3092)
Browse files Browse the repository at this point in the history
* Added Polymorph adapter

* Cleaned up code

* Updated var to let

* Updated with mediaType

* Updated tests

* Fixed tests

* Updated polymorph adapter to support cookie syncing and network key integration

* Fixed parens for lint

* Fixed a bug related to network_key approach

* Fixed double negation warning

* Updated tests for network_key

* Added bidId as cache buster and updated tests

* Fixed tests
  • Loading branch information
Kuldeep Kapade authored and Pedro López Jiménez committed Mar 18, 2019
1 parent e7afd69 commit 24f4637
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
31 changes: 28 additions & 3 deletions modules/polymorphBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER } from 'src/mediaTypes';

const PROTOCOL = getProtocol();
const BIDDER_CODE = 'polymorph';
const URL = '//api.adsnative.com/v1/ad-template.json';
const USER_SYNC_URL = PROTOCOL + '//rudy.adsnative.com/cm.gif';

function getProtocol() {
if (location.protocol && location.protocol.indexOf('https') === 0) {
return 'https:';
} else {
return 'http:';
}
}

export const polymorphAdapterSpec = {
code: BIDDER_CODE,
Expand All @@ -17,7 +27,7 @@ export const polymorphAdapterSpec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
return !!(bid.params.placementId);
return !!(bid.params.placementId) || (!!(bid.params.network_key) && !!(bid.params.widget_id) && !!(bid.params.cat));
},

/**
Expand All @@ -31,11 +41,18 @@ export const polymorphAdapterSpec = {
var payload = {
url: utils.getTopWindowUrl(),
ref: utils.getTopFrameReferrer(),
zid: bid.params.placementId,
sizes: bid.sizes,
hb: 1,
hb_source: 'prebid'
hb_source: 'prebid',
bid_id: bid.bidId,
};
if (bid.params.placementId) {
payload.zid = bid.params.placementId;
} else if (bid.params.network_key && bid.params.widget_id && bid.params.cat) {
payload.network_key = bid.params.network_key;
payload.widget_id = bid.params.widget_id;
payload.cat = bid.params.cat;
}
Object.keys(bid.params).forEach(function(key) {
if (key != 'defaultWidth' && key != 'defaultHeight') {
payload[key] = bid.params[key];
Expand Down Expand Up @@ -100,6 +117,14 @@ export const polymorphAdapterSpec = {
utils.logError(e);
}
return bidResponses;
},
getUserSyncs: function(syncOptions) {
if (syncOptions.pixelEnabled) {
return [{
type: 'image',
url: USER_SYNC_URL
}];
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions test/spec/modules/polymorphBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { newBidder } from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'polymorph';
const ENDPOINT_URL = '//api.adsnative.com/v1/ad-template.json';
const PLACEMENT_ID = 'ping';
const NETWORK_KEY = 'abcd1234';
const WIDGET_ID = 'xyz';
const CATEGORIES = 'IAB1,IAB2';

const spec = newBidder(polymorphAdapterSpec).getSpec();

Expand All @@ -31,6 +34,19 @@ const bidRequests = [{
'bidId': '30b31c1838de1d',
'bidderRequestId': '22edbae2733bf7',
'auctionId': '1d1a030790a476',
},
{
'bidder': BIDDER_CODE,
'params': {
'network_key': NETWORK_KEY,
'widget_id': WIDGET_ID,
'cat': CATEGORIES
},
'adUnitCode': 'adunit-code',
'sizes': [[700, 250], [300, 600]],
'bidId': '30b31c1838de1f',
'bidderRequestId': '22edbae2733bf7',
'auctionId': '1d1a030790a476',
}];

describe('Polymorph adapter test', function () {
Expand All @@ -45,6 +61,10 @@ describe('Polymorph adapter test', function () {
expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true);
});

it('should return true when required params found', function () {
expect(spec.isBidRequestValid(bidRequests[2])).to.equal(true);
});

it('should return false if req has no placementId', function () {
const invalidBidRequest = {
bidder: BIDDER_CODE,
Expand Down Expand Up @@ -79,6 +99,7 @@ describe('Polymorph adapter test', function () {
expect(payload1.hb_source).to.equal('prebid');
expect(payload1.zid).to.equal(PLACEMENT_ID);
expect(payload1.sizes).to.equal('300,250,300,600');
expect(payload1.bid_id).to.equal('30b31c1838de1e');

var payload2 = {};
requests[1].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) {
Expand All @@ -90,6 +111,21 @@ describe('Polymorph adapter test', function () {
expect(payload2.hb_source).to.equal('prebid');
expect(payload2.zid).to.equal(PLACEMENT_ID);
expect(payload2.sizes).to.equal('700,250,300,600');
expect(payload2.bid_id).to.equal('30b31c1838de1d');

var payload3 = {};
requests[2].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) {
payload3[decodeURIComponent(key)] = decodeURIComponent(value);
});
expect(payload3.ref).to.not.be.undefined;
expect(payload3.url).to.not.be.undefined;
expect(payload3.hb).to.equal('1');
expect(payload3.hb_source).to.equal('prebid');
expect(payload3.network_key).to.equal(NETWORK_KEY);
expect(payload3.widget_id).to.equal(WIDGET_ID);
expect(payload3.cat).to.equal(CATEGORIES);
expect(payload3.sizes).to.equal('700,250,300,600');
expect(payload3.bid_id).to.equal('30b31c1838de1f');
});

it('sends bid request to ENDPOINT via GET', function () {
Expand Down

0 comments on commit 24f4637

Please sign in to comment.