Skip to content

Commit

Permalink
Read OpenRTB app objects if set in config + bug fix for when ad units…
Browse files Browse the repository at this point in the history
… are reloaded (#5086)

* 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

* Support for app parameters

* Fix issue where adunits with bids were not counted on reload
  • Loading branch information
bjorn-lw authored Apr 8, 2020
1 parent de504a9 commit 9eec929
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 36 deletions.
36 changes: 21 additions & 15 deletions modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ let initOptions;
export const BID_WON_TIMEOUT = 500;

const cache = {
auctions: {},
bidAdUnits: {}
auctions: {}
};

let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE}), {
Expand All @@ -28,7 +27,7 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
switch (eventType) {
case CONSTANTS.EVENTS.AUCTION_INIT:
utils.logInfo('LIVEWRAPPED_AUCTION_INIT:', args);
cache.auctions[args.auctionId] = {bids: {}};
cache.auctions[args.auctionId] = {bids: {}, bidAdUnits: {}};
break;
case CONSTANTS.EVENTS.BID_REQUESTED:
utils.logInfo('LIVEWRAPPED_BID_REQUESTED:', args);
Expand Down Expand Up @@ -64,8 +63,12 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
if (!bidResponse.ttr) {
bidResponse.ttr = time - bidResponse.start;
}
if (!cache.bidAdUnits[bidResponse.adUnit]) {
cache.bidAdUnits[bidResponse.adUnit] = {sent: 0, timeStamp: cache.auctions[args.auctionId].timeStamp};
if (!cache.auctions[args.auctionId].bidAdUnits[bidResponse.adUnit]) {
cache.auctions[args.auctionId].bidAdUnits[bidResponse.adUnit] =
{
sent: 0,
timeStamp: cache.auctions[args.auctionId].timeStamp
};
}
break;
case CONSTANTS.EVENTS.BIDDER_DONE:
Expand Down Expand Up @@ -240,16 +243,19 @@ function getTimeouts() {
function getbidAdUnits() {
var bidAdUnits = [];

Object.keys(cache.bidAdUnits).forEach(adUnit => {
let bidAdUnit = cache.bidAdUnits[adUnit];
if (!bidAdUnit.sent) {
bidAdUnit.sent = 1;

bidAdUnits.push({
adUnit: adUnit,
timeStamp: bidAdUnit.timeStamp
});
}
Object.keys(cache.auctions).forEach(auctionId => {
let auction = cache.auctions[auctionId];
Object.keys(auction.bidAdUnits).forEach(adUnit => {
let bidAdUnit = auction.bidAdUnits[adUnit];
if (!bidAdUnit.sent) {
bidAdUnit.sent = 1;

bidAdUnits.push({
adUnit: adUnit,
timeStamp: bidAdUnit.timeStamp
});
}
});
});

return bidAdUnits;
Expand Down
51 changes: 48 additions & 3 deletions modules/livewrappedBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const storage = getStorageManager();

const BIDDER_CODE = 'livewrapped';
export const URL = 'https://lwadm.com/ad';
const VERSION = '1.2';
const VERSION = '1.3';

export const spec = {
code: BIDDER_CODE,
Expand All @@ -29,6 +29,7 @@ export const spec = {
* seats: List of bidders and seats Optional. {"bidder name": ["seat 1", "seat 2"], ...}
* deviceId: Device id if available Optional.
* ifa: Advertising ID Optional.
* bundle: App bundle Optional. Read from config if exists.
* options Dynamic data Optional. Optional data to send into adapter.
*
* @param {BidRequest} bid The bid params to validate.
Expand All @@ -55,9 +56,10 @@ export const spec = {
const seats = find(bidRequests, hasSeatsParam);
const deviceId = find(bidRequests, hasDeviceIdParam);
const ifa = find(bidRequests, hasIfaParam);
const bundle = find(bidRequests, hasBundleParam);
const tid = find(bidRequests, hasTidParam);
bidUrl = bidUrl ? bidUrl.params.bidUrl : URL;
url = url ? url.params.url : getTopWindowLocation(bidderRequest);
url = url ? url.params.url : (getAppDomain() || getTopWindowLocation(bidderRequest));
test = test ? test.params.test : undefined;
var adRequests = bidRequests.map(bidToAdRequest);

Expand All @@ -69,7 +71,10 @@ export const spec = {
test: test,
seats: seats ? seats.params.seats : undefined,
deviceId: deviceId ? deviceId.params.deviceId : undefined,
ifa: ifa ? ifa.params.ifa : undefined,
ifa: ifa ? ifa.params.ifa : getDeviceIfa(),
bundle: bundle ? bundle.params.bundle : getAppBundle(),
width: getDeviceWidth(),
height: getDeviceHeight(),
tid: tid ? tid.params.tid : undefined,
version: VERSION,
gdprApplies: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : undefined,
Expand Down Expand Up @@ -178,6 +183,10 @@ function hasIfaParam(bid) {
return !!bid.params.ifa;
}

function hasBundleParam(bid) {
return !!bid.params.bundle;
}

function hasTidParam(bid) {
return !!bid.params.tid;
}
Expand Down Expand Up @@ -264,4 +273,40 @@ function getTopWindowLocation(bidderRequest) {
return config.getConfig('pageUrl') || url;
}

function getAppBundle() {
if (typeof config.getConfig('app') === 'object') {
return config.getConfig('app').bundle;
}
}

function getAppDomain() {
if (typeof config.getConfig('app') === 'object') {
return config.getConfig('app').domain;
}
}

function getDeviceIfa() {
if (typeof config.getConfig('device') === 'object') {
return config.getConfig('device').ifa;
}
}

function getDeviceWidth() {
let device = config.getConfig('device');
if (typeof device === 'object' && device.width) {
return device.width;
}

return window.innerWidth;
}

function getDeviceHeight() {
let device = config.getConfig('device');
if (typeof device === 'object' && device.height) {
return device.height;
}

return window.innerHeight;
}

registerBidder(spec);
Loading

0 comments on commit 9eec929

Please sign in to comment.