From 1964f2734c76e90e2c5b28496b867db41438af47 Mon Sep 17 00:00:00 2001 From: bjorn-lw <32431346+bjorn-lw@users.noreply.github.com> Date: Wed, 5 Feb 2020 20:01:06 +0100 Subject: [PATCH] Collect data about native + minor changes (#4807) * Livewrapped bid and analytics adapter * Fixed some tests for browser compatibility * Fixed some tests for browser compatibility * Changed analytics adapter code name * Fix double quote in debug message * modified how gdpr is being passed * Added support for Publisher Common ID Module * Corrections for ttr in analytics * ANalytics updates * Auction start time stamp changed * Detect recovered ad blocked requests Make it possible to pass dynamic parameters to adapter * Collect info on ad units receiving any valid bid * Support for ID5 Pass metadata from adapter * Typo in test + eids on wrong level * Fix for Prebid 3.0 * Fix get referer * http -> https in tests * Native support * Read sizes from mediatype.banner * Revert accidental commit * Support native data collection + minor refactorings * Set analytics endpoint --- modules/livewrappedAnalyticsAdapter.js | 7 ++- modules/livewrappedBidAdapter.js | 10 ++-- .../livewrappedAnalyticsAdapter_spec.js | 46 +++++++++++++++++-- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index d15577e215b..75d4e90fded 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -60,6 +60,7 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE bidResponse.cpm = args.cpm; bidResponse.ttr = args.timeToRespond; bidResponse.readyToSend = 1; + bidResponse.mediaType = args.mediaType == 'native' ? 2 : 1; if (!bidResponse.ttr) { bidResponse.ttr = time - bidResponse.start; } @@ -129,7 +130,7 @@ livewrappedAnalyticsAdapter.sendEvents = function() { return; } - ajax(URL, undefined, JSON.stringify(events), {method: 'POST'}); + ajax(initOptions.endpoint || URL, undefined, JSON.stringify(events), {method: 'POST'}); } function getAdblockerRecovered() { @@ -178,7 +179,8 @@ function getResponses() { height: bid.height, cpm: bid.cpm, ttr: bid.ttr, - IsBid: bid.isBid + IsBid: bid.isBid, + mediaType: bid.mediaType }); } }); @@ -204,6 +206,7 @@ function getWins() { width: bid.width, height: bid.height, cpm: bid.cpm, + mediaType: bid.mediaType }); } }); diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index c5c71a4131e..4dfd25c1fcd 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -193,19 +193,17 @@ function bidToAdRequest(bid) { options: bid.params.options }; - if (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.native) { - adRequest.banner = true; - } + adRequest.native = utils.deepAccess(bid, 'mediaTypes.native'); - if (bid.mediaTypes && bid.mediaTypes.native) { - adRequest.native = bid.mediaTypes.native; + if (adRequest.native && utils.deepAccess(bid, 'mediaTypes.banner')) { + adRequest.banner = true; } return adRequest; } function getSizes(bid) { - if (typeof utils.deepAccess(bid, 'mediaTypes.banner.sizes') !== 'undefined') { + if (utils.deepAccess(bid, 'mediaTypes.banner.sizes')) { return bid.mediaTypes.banner.sizes; } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) { return bid.sizes; diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js index 98ed21132e3..2676de0de10 100644 --- a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -32,6 +32,7 @@ const BID1 = { requestId: '2ecff0db240757', adId: '2ecff0db240757', auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', + mediaType: 'banner', getStatusCode() { return CONSTANTS.STATUS.GOOD; } @@ -52,6 +53,7 @@ const BID3 = { requestId: '4ecff0db240757', adId: '4ecff0db240757', auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', + mediaType: 'banner', getStatusCode() { return CONSTANTS.STATUS.NO_BID; } @@ -154,7 +156,8 @@ const ANALYTICS_MESSAGE = { height: 240, cpm: 1.1, ttr: 200, - IsBid: true + IsBid: true, + mediaType: 1 }, { timeStamp: 1519149562216, @@ -164,7 +167,8 @@ const ANALYTICS_MESSAGE = { height: 250, cpm: 2.2, ttr: 300, - IsBid: true + IsBid: true, + mediaType: 1 }, { timeStamp: 1519149562216, @@ -182,7 +186,8 @@ const ANALYTICS_MESSAGE = { bidder: 'livewrapped', width: 980, height: 240, - cpm: 1.1 + cpm: 1.1, + mediaType: 1 }, { timeStamp: 1519149562216, @@ -190,7 +195,8 @@ const ANALYTICS_MESSAGE = { bidder: 'livewrapped', width: 300, height: 250, - cpm: 2.2 + cpm: 2.2, + mediaType: 1 } ] }; @@ -316,4 +322,36 @@ describe('Livewrapped analytics adapter', function () { expect(message.rcv).to.equal(true); }); }); + + describe('when given other endpoint', function () { + adapterManager.registerAnalyticsAdapter({ + code: 'livewrapped', + adapter: livewrappedAnalyticsAdapter + }); + + beforeEach(function () { + adapterManager.enableAnalytics({ + provider: 'livewrapped', + options: { + publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7', + endpoint: 'https://whitelabeled.com/analytics/10' + } + }); + }); + + afterEach(function () { + livewrappedAnalyticsAdapter.disableAnalytics(); + }); + + it('should call the endpoint', function () { + performStandardAuction(); + + clock.tick(BID_WON_TIMEOUT + 1000); + + expect(server.requests.length).to.equal(1); + let request = server.requests[0]; + + expect(request.url).to.equal('https://whitelabeled.com/analytics/10'); + }); + }); });