Skip to content

Commit 8fdf61d

Browse files
Kuldeep Kapadejaiminpanchal27
Kuldeep Kapade
authored andcommitted
Added support for user syncing pixel (prebid#3092)
* 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
1 parent e72e2dc commit 8fdf61d

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

modules/polymorphBidAdapter.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ import * as utils from 'src/utils';
22
import { registerBidder } from 'src/adapters/bidderFactory';
33
import { BANNER } from 'src/mediaTypes';
44

5+
const PROTOCOL = getProtocol();
56
const BIDDER_CODE = 'polymorph';
67
const URL = '//api.adsnative.com/v1/ad-template.json';
8+
const USER_SYNC_URL = PROTOCOL + '//rudy.adsnative.com/cm.gif';
9+
10+
function getProtocol() {
11+
if (location.protocol && location.protocol.indexOf('https') === 0) {
12+
return 'https:';
13+
} else {
14+
return 'http:';
15+
}
16+
}
717

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

2333
/**
@@ -31,11 +41,18 @@ export const polymorphAdapterSpec = {
3141
var payload = {
3242
url: utils.getTopWindowUrl(),
3343
ref: utils.getTopFrameReferrer(),
34-
zid: bid.params.placementId,
3544
sizes: bid.sizes,
3645
hb: 1,
37-
hb_source: 'prebid'
46+
hb_source: 'prebid',
47+
bid_id: bid.bidId,
3848
};
49+
if (bid.params.placementId) {
50+
payload.zid = bid.params.placementId;
51+
} else if (bid.params.network_key && bid.params.widget_id && bid.params.cat) {
52+
payload.network_key = bid.params.network_key;
53+
payload.widget_id = bid.params.widget_id;
54+
payload.cat = bid.params.cat;
55+
}
3956
Object.keys(bid.params).forEach(function(key) {
4057
if (key != 'defaultWidth' && key != 'defaultHeight') {
4158
payload[key] = bid.params[key];
@@ -100,6 +117,14 @@ export const polymorphAdapterSpec = {
100117
utils.logError(e);
101118
}
102119
return bidResponses;
120+
},
121+
getUserSyncs: function(syncOptions) {
122+
if (syncOptions.pixelEnabled) {
123+
return [{
124+
type: 'image',
125+
url: USER_SYNC_URL
126+
}];
127+
}
103128
}
104129
}
105130

test/spec/modules/polymorphBidAdapter_spec.js

+36
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { newBidder } from 'src/adapters/bidderFactory';
55
const BIDDER_CODE = 'polymorph';
66
const ENDPOINT_URL = '//api.adsnative.com/v1/ad-template.json';
77
const PLACEMENT_ID = 'ping';
8+
const NETWORK_KEY = 'abcd1234';
9+
const WIDGET_ID = 'xyz';
10+
const CATEGORIES = 'IAB1,IAB2';
811

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

@@ -31,6 +34,19 @@ const bidRequests = [{
3134
'bidId': '30b31c1838de1d',
3235
'bidderRequestId': '22edbae2733bf7',
3336
'auctionId': '1d1a030790a476',
37+
},
38+
{
39+
'bidder': BIDDER_CODE,
40+
'params': {
41+
'network_key': NETWORK_KEY,
42+
'widget_id': WIDGET_ID,
43+
'cat': CATEGORIES
44+
},
45+
'adUnitCode': 'adunit-code',
46+
'sizes': [[700, 250], [300, 600]],
47+
'bidId': '30b31c1838de1f',
48+
'bidderRequestId': '22edbae2733bf7',
49+
'auctionId': '1d1a030790a476',
3450
}];
3551

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

64+
it('should return true when required params found', function () {
65+
expect(spec.isBidRequestValid(bidRequests[2])).to.equal(true);
66+
});
67+
4868
it('should return false if req has no placementId', function () {
4969
const invalidBidRequest = {
5070
bidder: BIDDER_CODE,
@@ -79,6 +99,7 @@ describe('Polymorph adapter test', function () {
7999
expect(payload1.hb_source).to.equal('prebid');
80100
expect(payload1.zid).to.equal(PLACEMENT_ID);
81101
expect(payload1.sizes).to.equal('300,250,300,600');
102+
expect(payload1.bid_id).to.equal('30b31c1838de1e');
82103

83104
var payload2 = {};
84105
requests[1].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) {
@@ -90,6 +111,21 @@ describe('Polymorph adapter test', function () {
90111
expect(payload2.hb_source).to.equal('prebid');
91112
expect(payload2.zid).to.equal(PLACEMENT_ID);
92113
expect(payload2.sizes).to.equal('700,250,300,600');
114+
expect(payload2.bid_id).to.equal('30b31c1838de1d');
115+
116+
var payload3 = {};
117+
requests[2].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) {
118+
payload3[decodeURIComponent(key)] = decodeURIComponent(value);
119+
});
120+
expect(payload3.ref).to.not.be.undefined;
121+
expect(payload3.url).to.not.be.undefined;
122+
expect(payload3.hb).to.equal('1');
123+
expect(payload3.hb_source).to.equal('prebid');
124+
expect(payload3.network_key).to.equal(NETWORK_KEY);
125+
expect(payload3.widget_id).to.equal(WIDGET_ID);
126+
expect(payload3.cat).to.equal(CATEGORIES);
127+
expect(payload3.sizes).to.equal('700,250,300,600');
128+
expect(payload3.bid_id).to.equal('30b31c1838de1f');
93129
});
94130

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

0 commit comments

Comments
 (0)