Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appnexus adapter updates #156

Merged
merged 2 commits into from
Jan 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/adapters/appnexus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -121,15 +115,32 @@ var AppNexusAdapter = function AppNexusAdapter() {
if (sizeQueryString) {
jptCall += sizeQueryString + '&';
}
//console.log(jptCall);

//this will be deprecated soon
var targetingParams = utils.parseQueryStringParameters(query);

if (targetingParams) {
//don't append a & here, we have already done it in parseQueryStringParameters
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();
Expand All @@ -150,15 +161,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;

Expand Down Expand Up @@ -199,11 +207,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;
Expand All @@ -212,7 +217,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);


Expand Down Expand Up @@ -242,7 +246,8 @@ var AppNexusAdapter = function AppNexusAdapter() {
return {
callBids: baseAdapter.callBids,
setBidderCode: baseAdapter.setBidderCode,
createNew: exports.createNew
createNew: exports.createNew,
buildJPTCall : buildJPTCall
};
};

Expand Down
42 changes: 42 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,48 @@ 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: {
memberId : "123",
placementId: "123345",
invCode : 'inv_code',
referrer: "url.com",
alt_referrer: "url.com",
extraParam: "foobar",
somethingElse : 'hello',
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&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);
});


});

describe('replaceTokenInString', function(){

Expand Down