From 5d76a65be233cf4ed81ba226fcea494799564576 Mon Sep 17 00:00:00 2001 From: Matt Kendall Date: Wed, 6 Jan 2016 16:51:32 -0500 Subject: [PATCH 1/2] Cleanup AN adapter and add a unit test --- src/adapters/appnexus.js | 21 ++++----------------- test/test.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/adapters/appnexus.js b/src/adapters/appnexus.js index 8d1688693f5..f50f08b6726 100644 --- a/src/adapters/appnexus.js +++ b/src/adapters/appnexus.js @@ -97,18 +97,12 @@ var AppNexusAdapter = function AppNexusAdapter() { var referrer = utils.getBidIdParamater('referrer', bid.params); var altReferrer = utils.getBidIdParamater('alt_referrer', bid.params); - //build our base tag, based on if we are http or https var jptCall = 'http' + ('https:' === document.location.protocol ? 's://secure.adnxs.com/jpt?' : '://ib.adnxs.com/jpt?'); - //var combinedTargetingParamsList = combineTargetingParams(bidOpts); - - //callback is the callback function to call, this should be hard-coded to pbjs.handleCb once AL-107 is released - jptCall = utils.tryAppendQueryString(jptCall, 'callback', 'pbjs.handleCB'); + jptCall = utils.tryAppendQueryString(jptCall, 'callback', 'pbjs.handleAnCB'); jptCall = utils.tryAppendQueryString(jptCall, 'callback_uid', callbackId); - - //disable PSAs here, as per RAD-503 jptCall = utils.tryAppendQueryString(jptCall, 'psa', '0'); jptCall = utils.tryAppendQueryString(jptCall, 'id', placementId); jptCall = utils.tryAppendQueryString(jptCall, 'member_id', memberId); @@ -121,7 +115,6 @@ var AppNexusAdapter = function AppNexusAdapter() { if (sizeQueryString) { jptCall += sizeQueryString + '&'; } - //console.log(jptCall); var targetingParams = utils.parseQueryStringParameters(query); @@ -150,15 +143,12 @@ var AppNexusAdapter = function AppNexusAdapter() { //append a timer here to track latency bid.startTime = new Date().getTime(); - //track initial request - //adloader.trackPixel(timeTrackerBidRequested); //TODO add this back in and figure out where it goes and what it does - return jptCall; } //expose the callback to the global object: - pbjs.handleCB = function(jptResponseObj) { + pbjs.handleAnCB = function(jptResponseObj) { var bidCode; @@ -199,11 +189,8 @@ var AppNexusAdapter = function AppNexusAdapter() { var responseAd = jptResponseObj.result.ad; //store bid response //bid status is good (indicating 1) - //TODO refactor to pass a Bid object instead of multiple params - //bidmanager.addBidResponse(statusCode, placementCode, bidderCode, custObj, cpm, ad, width, height, dealId, isDeal, tier, adId ) var adId = jptResponseObj.result.creative_id; bid = bidfactory.createBid(1); - //bid.adId = adId; bid.creative_id = adId; bid.bidderCode = bidCode; bid.cpm = responseCPM; @@ -212,7 +199,6 @@ var AppNexusAdapter = function AppNexusAdapter() { bid.height = jptResponseObj.result.height; bid.dealId = jptResponseObj.result.deal_id; - //bidmanager.addBidResponse(1, placementCode, 'appnexus', jptResponseObj, responseCPM, jptResponseObj.result.ad, jptResponseObj.result.width, jptResponseObj.result.height, '', false, '', jptResponseObj.result.creative_id ); bidmanager.addBidResponse(placementCode, bid); @@ -242,7 +228,8 @@ var AppNexusAdapter = function AppNexusAdapter() { return { callBids: baseAdapter.callBids, setBidderCode: baseAdapter.setBidderCode, - createNew: exports.createNew + createNew: exports.createNew, + buildJPTCall : buildJPTCall }; }; diff --git a/test/test.js b/test/test.js index e677a24a883..9bcddc06c25 100644 --- a/test/test.js +++ b/test/test.js @@ -5,6 +5,45 @@ var assert = require("assert"); //TODO refactor to use the spec files var utils = require('../src/utils'); var bidmanager = require('../src/bidmanager'); +var appnexus = require('../src/adapters/appnexus'); + + describe('appnexus adapter unit tests', function(){ + + var adapterInstance = null; + var bidRequest = { + bidder: "appnexus", + params: { + placementId: "123345", + referrer: "url.com", + alt_referrer: "url.com", + extraParam: "foobar", + query : { + foo : 'bar', + tasty : 'treat' + } + }, + placementCode: "/19968336/header-bid-tag-0", + sizes: [ + [300, 250], + [300, 600] + ] + }; + var callbackId = 'cbId'; + + + it('Get instance', function() { + adapterInstance = appnexus.createNew(); + assert.ok(adapterInstance); + }); + + it('buildJPTCall()', function() { + var expectedUrl = 'http://ib.adnxs.com/jpt?callback=pbjs.handleAnCB&callback_uid=cbId&psa=0&id=123345&size=300x250&promo_sizes=300x600&foo=bar&tasty=treat&referrer=url.com&alt_referrer=url.com'; + var url = adapterInstance.buildJPTCall(bidRequest, callbackId); + assert.equal(url, expectedUrl); + }); + + + }); describe('replaceTokenInString', function(){ From f539d0b81c40d13a336c4e79c50a8ac23727dfe7 Mon Sep 17 00:00:00 2001 From: Matt Kendall Date: Thu, 7 Jan 2016 11:26:11 -0500 Subject: [PATCH 2/2] Allow query params directly in the Params object for AN adapter --- src/adapters/appnexus.js | 18 ++++++++++++++++++ test/test.js | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/adapters/appnexus.js b/src/adapters/appnexus.js index f50f08b6726..2dbefc16077 100644 --- a/src/adapters/appnexus.js +++ b/src/adapters/appnexus.js @@ -116,6 +116,7 @@ var AppNexusAdapter = function AppNexusAdapter() { jptCall += sizeQueryString + '&'; } + //this will be deprecated soon var targetingParams = utils.parseQueryStringParameters(query); if (targetingParams) { @@ -123,6 +124,23 @@ var AppNexusAdapter = function AppNexusAdapter() { jptCall += targetingParams; } + //append custom attributes: + var paramsCopy = utils.extend({}, bid.params); + //delete attributes already used + delete paramsCopy.placementId; + delete paramsCopy.memberId; + delete paramsCopy.invCode; + delete paramsCopy.query; + delete paramsCopy.referrer; + delete paramsCopy.alt_referrer; + + //get the reminder + var queryParams = utils.parseQueryStringParameters(paramsCopy); + //append + if (queryParams) { + jptCall += queryParams; + } + //append referrer if(referrer===''){ referrer = utils.getTopWindowUrl(); diff --git a/test/test.js b/test/test.js index 9bcddc06c25..800ec0f6817 100644 --- a/test/test.js +++ b/test/test.js @@ -13,10 +13,13 @@ var appnexus = require('../src/adapters/appnexus'); var bidRequest = { bidder: "appnexus", params: { + memberId : "123", placementId: "123345", + invCode : 'inv_code', referrer: "url.com", alt_referrer: "url.com", extraParam: "foobar", + somethingElse : 'hello', query : { foo : 'bar', tasty : 'treat' @@ -37,7 +40,7 @@ var appnexus = require('../src/adapters/appnexus'); }); it('buildJPTCall()', function() { - var expectedUrl = 'http://ib.adnxs.com/jpt?callback=pbjs.handleAnCB&callback_uid=cbId&psa=0&id=123345&size=300x250&promo_sizes=300x600&foo=bar&tasty=treat&referrer=url.com&alt_referrer=url.com'; + var expectedUrl = 'http://ib.adnxs.com/jpt?callback=pbjs.handleAnCB&callback_uid=cbId&psa=0&id=123345&member_id=123&code=inv_code&size=300x250&promo_sizes=300x600&foo=bar&tasty=treat&extraParam=foobar&somethingElse=hello&referrer=url.com&alt_referrer=url.com'; var url = adapterInstance.buildJPTCall(bidRequest, callbackId); assert.equal(url, expectedUrl); });