From 2779585f55655f928c583285237c6b606d63ebd2 Mon Sep 17 00:00:00 2001 From: Keiran Date: Mon, 3 Dec 2018 07:52:36 -0800 Subject: [PATCH] new TapHype bidder adapter (#3319) * new TapHype bidder adapter * Added 930x600 to Rubicon Adapter (#3323) * PubMatic adapter to support TTD (#3311) * first commit * added unit test cases for TTD id * Sonobi - support video and display same adunit (#3325) * changed adapter to support video and display for ad unit * added case for sbi_ct outstream * outstream is display media type * Fix user-sync iframes insertion bug (#3300) According to documentation, iframes should be inserted at bottom of head, rather than at top. * Prevent 33Across adapter from throwing an error when unable to getElementById(), fix JSDocs in utils.js (#3333) * check gdpr in buildRequest * User sync based on whether gdpr applies or not * check if consent data exists during user sync * split user sync into further branches: 1) when gdpr does not apply 2) when consent data is unavailable * contribute viewability to ttxRequest * update tests * remove window mock from tests * use local variables * introduce ServerRequestBuilder * add withOptions() method to ServerRequestBuilder * add semicolons * sync up package-lock.json with upstream/master * stub window.top in tests * introduce getTopWindowSize() for test purpose * reformat code * add withSite() method to TtxRequestBuilder add withSite() method to TtxRequestBuilder * add isIframe() and _isViewabilityMeasurable() * handle NON_MEASURABLE viewability in nested iframes * consider page visibility, stub utils functions getWindowTop() and getWindowSelf() * contribute viewability as 0 for inactive tab * add prebidjs version to ttx request * send caller as an array * fix JSDoc in utils.js * send viewability as non measurable when unable to locate target HTMLElement, add warning message * TripleliftBidAdapter-update creative_id (#3324) * removed dependancy on getTopWindowUrl for referer * protect against undefined obj and remove test on old dependency * added unit test for referer and gdpr in query string * removed gdpr test * removed gdpr from bidderRequest obj * decontructed bidder request obj in chai test * just need to run karma tests again * added gdpr consent to all bidderRequest obj in chai tests * changed creativeId to be a Triplelift specific id rather than represent SRA impression * error-proofed creative id * Update taphypeBidAdapter.js removed `supportedMediaTypes` and logging * Update taphypeBidAdapter.js remove mediaTypes import * new TapHype bidder adapter * Update taphypeBidAdapter.js removed `supportedMediaTypes` and logging * Update taphypeBidAdapter.js remove mediaTypes import --- modules/taphypeBidAdapter.js | 45 +++++++++++++++++ modules/taphypeBidAdapter.md | 32 ++++++++++++ test/spec/modules/taphypeBidAdapter_spec.js | 56 +++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 modules/taphypeBidAdapter.js create mode 100644 modules/taphypeBidAdapter.md create mode 100644 test/spec/modules/taphypeBidAdapter_spec.js diff --git a/modules/taphypeBidAdapter.js b/modules/taphypeBidAdapter.js new file mode 100644 index 00000000000..ae9eb7296e0 --- /dev/null +++ b/modules/taphypeBidAdapter.js @@ -0,0 +1,45 @@ +import {registerBidder} from 'src/adapters/bidderFactory'; + +export const spec = { + code: 'taphype', + isBidRequestValid: function (bid) { + return !!bid.params.placementId; + }, + buildRequests: function (bidRequests) { + const requests = bidRequests.map(function (bid) { + const params = { + placementId: bid.params.placementId, + url: encodeURIComponent(window.location.href), + size: bid.sizes[0][0] + 'x' + bid.sizes[0][1], + rnd: Math.random(), + bidId: bid.bidId, + }; + + return {method: 'GET', url: 'https://us-central1-taphype-internal.cloudfunctions.net/th-prebid', data: params, options: {withCredentials: false}} + }); + + return requests; + }, + interpretResponse: function (serverResponse, bidRequest) { + if (!serverResponse || !serverResponse.body || !serverResponse.body.ad) { + return []; + } + + const bid = serverResponse.body; + const sizes = bid.size.split(','); + + return [{ + requestId: bidRequest.data.bidId, + cpm: bid.price, + width: sizes[0], + height: sizes[1], + creativeId: bidRequest.data.bidId, + currency: bid.currency || 'USD', + netRevenue: true, + ad: bid.ad, + ttl: 360 + }]; + }, +}; + +registerBidder(spec); diff --git a/modules/taphypeBidAdapter.md b/modules/taphypeBidAdapter.md new file mode 100644 index 00000000000..c6ff40a42ba --- /dev/null +++ b/modules/taphypeBidAdapter.md @@ -0,0 +1,32 @@ +# Overview + +Module Name: TapHype Bidder Adapter +Module Type: Bidder Adapter +Maintainer: admin@taphype.com + +# Description + +You can use this adapter to get a bid from taphype.com. + + +# Test Parameters +```javascript + var adUnits = [ + { + code: 'div-taphype-example', + sizes: [[300, 250]], + bids: [ + { + bidder: "taphype", + params: { + placementId: 12345 + } + } + ] + } + ]; +``` + +Where: + +* placementId - TapHype Placement ID diff --git a/test/spec/modules/taphypeBidAdapter_spec.js b/test/spec/modules/taphypeBidAdapter_spec.js new file mode 100644 index 00000000000..2fcdd964520 --- /dev/null +++ b/test/spec/modules/taphypeBidAdapter_spec.js @@ -0,0 +1,56 @@ +import { expect } from 'chai'; +import { spec } from 'modules/taphypeBidAdapter'; + +describe('taphypeBidAdapterTests', function () { + it('validate_pub_params', function () { + expect(spec.isBidRequestValid({ + bidder: 'taphype', + params: { + placementId: 12345 + } + })).to.equal(true); + }); + + it('validate_generated_params', function () { + let bidRequestData = [{ + bidId: 'bid12345', + bidder: 'taphype', + params: { + placementId: 12345 + }, + sizes: [[300, 250]] + }]; + + let request = spec.buildRequests(bidRequestData); + let req_data = request[0].data; + + expect(req_data.bidId).to.equal('bid12345'); + }); + + it('validate_response_params', function () { + let bidRequestData = { + data: { + bidId: 'bid12345' + } + }; + + let serverResponse = { + body: { + price: 1.23, + ad: '', + size: '300,250' + } + }; + + let bids = spec.interpretResponse(serverResponse, bidRequestData); + expect(bids).to.have.lengthOf(1); + let bid = bids[0]; + expect(bid.cpm).to.equal(1.23); + expect(bid.currency).to.equal('USD'); + expect(bid.width).to.equal('300'); + expect(bid.height).to.equal('250'); + expect(bid.netRevenue).to.equal(true); + expect(bid.requestId).to.equal('bid12345'); + expect(bid.ad).to.equal(''); + }); +});