From 24f46379d089a6eb465aa1ed8ef0346683f7a478 Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Tue, 9 Oct 2018 12:33:07 -0700 Subject: [PATCH] Added support for user syncing pixel (#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 --- modules/polymorphBidAdapter.js | 31 ++++++++++++++-- test/spec/modules/polymorphBidAdapter_spec.js | 36 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index 8d07a66d0da..da5f7f711ec 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -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, @@ -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)); }, /** @@ -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]; @@ -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 + }]; + } } } diff --git a/test/spec/modules/polymorphBidAdapter_spec.js b/test/spec/modules/polymorphBidAdapter_spec.js index e2df44e8cfc..6fd4bd90288 100644 --- a/test/spec/modules/polymorphBidAdapter_spec.js +++ b/test/spec/modules/polymorphBidAdapter_spec.js @@ -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(); @@ -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 () { @@ -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, @@ -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) { @@ -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 () {