Skip to content

Commit

Permalink
Collect data about native + minor changes (prebid#4807)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bjorn-lw authored Feb 5, 2020
1 parent 50d2a29 commit 1964f27
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
7 changes: 5 additions & 2 deletions modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -178,7 +179,8 @@ function getResponses() {
height: bid.height,
cpm: bid.cpm,
ttr: bid.ttr,
IsBid: bid.isBid
IsBid: bid.isBid,
mediaType: bid.mediaType
});
}
});
Expand All @@ -204,6 +206,7 @@ function getWins() {
width: bid.width,
height: bid.height,
cpm: bid.cpm,
mediaType: bid.mediaType
});
}
});
Expand Down
10 changes: 4 additions & 6 deletions modules/livewrappedBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 42 additions & 4 deletions test/spec/modules/livewrappedAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const BID1 = {
requestId: '2ecff0db240757',
adId: '2ecff0db240757',
auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa',
mediaType: 'banner',
getStatusCode() {
return CONSTANTS.STATUS.GOOD;
}
Expand All @@ -52,6 +53,7 @@ const BID3 = {
requestId: '4ecff0db240757',
adId: '4ecff0db240757',
auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa',
mediaType: 'banner',
getStatusCode() {
return CONSTANTS.STATUS.NO_BID;
}
Expand Down Expand Up @@ -154,7 +156,8 @@ const ANALYTICS_MESSAGE = {
height: 240,
cpm: 1.1,
ttr: 200,
IsBid: true
IsBid: true,
mediaType: 1
},
{
timeStamp: 1519149562216,
Expand All @@ -164,7 +167,8 @@ const ANALYTICS_MESSAGE = {
height: 250,
cpm: 2.2,
ttr: 300,
IsBid: true
IsBid: true,
mediaType: 1
},
{
timeStamp: 1519149562216,
Expand All @@ -182,15 +186,17 @@ const ANALYTICS_MESSAGE = {
bidder: 'livewrapped',
width: 980,
height: 240,
cpm: 1.1
cpm: 1.1,
mediaType: 1
},
{
timeStamp: 1519149562216,
adUnit: 'box_d_1',
bidder: 'livewrapped',
width: 300,
height: 250,
cpm: 2.2
cpm: 2.2,
mediaType: 1
}
]
};
Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit 1964f27

Please sign in to comment.