Skip to content

Commit e994684

Browse files
bjorn-lwrjvelicaria
authored andcommitted
Read OpenRTB app objects if set in config + bug fix for when ad units are reloaded (prebid#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
1 parent b5d034a commit e994684

File tree

3 files changed

+170
-36
lines changed

3 files changed

+170
-36
lines changed

modules/livewrappedAnalyticsAdapter.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ let initOptions;
1616
export const BID_WON_TIMEOUT = 500;
1717

1818
const cache = {
19-
auctions: {},
20-
bidAdUnits: {}
19+
auctions: {}
2120
};
2221

2322
let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE}), {
@@ -28,7 +27,7 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
2827
switch (eventType) {
2928
case CONSTANTS.EVENTS.AUCTION_INIT:
3029
utils.logInfo('LIVEWRAPPED_AUCTION_INIT:', args);
31-
cache.auctions[args.auctionId] = {bids: {}};
30+
cache.auctions[args.auctionId] = {bids: {}, bidAdUnits: {}};
3231
break;
3332
case CONSTANTS.EVENTS.BID_REQUESTED:
3433
utils.logInfo('LIVEWRAPPED_BID_REQUESTED:', args);
@@ -64,8 +63,12 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
6463
if (!bidResponse.ttr) {
6564
bidResponse.ttr = time - bidResponse.start;
6665
}
67-
if (!cache.bidAdUnits[bidResponse.adUnit]) {
68-
cache.bidAdUnits[bidResponse.adUnit] = {sent: 0, timeStamp: cache.auctions[args.auctionId].timeStamp};
66+
if (!cache.auctions[args.auctionId].bidAdUnits[bidResponse.adUnit]) {
67+
cache.auctions[args.auctionId].bidAdUnits[bidResponse.adUnit] =
68+
{
69+
sent: 0,
70+
timeStamp: cache.auctions[args.auctionId].timeStamp
71+
};
6972
}
7073
break;
7174
case CONSTANTS.EVENTS.BIDDER_DONE:
@@ -240,16 +243,19 @@ function getTimeouts() {
240243
function getbidAdUnits() {
241244
var bidAdUnits = [];
242245

243-
Object.keys(cache.bidAdUnits).forEach(adUnit => {
244-
let bidAdUnit = cache.bidAdUnits[adUnit];
245-
if (!bidAdUnit.sent) {
246-
bidAdUnit.sent = 1;
247-
248-
bidAdUnits.push({
249-
adUnit: adUnit,
250-
timeStamp: bidAdUnit.timeStamp
251-
});
252-
}
246+
Object.keys(cache.auctions).forEach(auctionId => {
247+
let auction = cache.auctions[auctionId];
248+
Object.keys(auction.bidAdUnits).forEach(adUnit => {
249+
let bidAdUnit = auction.bidAdUnits[adUnit];
250+
if (!bidAdUnit.sent) {
251+
bidAdUnit.sent = 1;
252+
253+
bidAdUnits.push({
254+
adUnit: adUnit,
255+
timeStamp: bidAdUnit.timeStamp
256+
});
257+
}
258+
});
253259
});
254260

255261
return bidAdUnits;

modules/livewrappedBidAdapter.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const storage = getStorageManager();
99

1010
const BIDDER_CODE = 'livewrapped';
1111
export const URL = 'https://lwadm.com/ad';
12-
const VERSION = '1.2';
12+
const VERSION = '1.3';
1313

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

@@ -69,7 +71,10 @@ export const spec = {
6971
test: test,
7072
seats: seats ? seats.params.seats : undefined,
7173
deviceId: deviceId ? deviceId.params.deviceId : undefined,
72-
ifa: ifa ? ifa.params.ifa : undefined,
74+
ifa: ifa ? ifa.params.ifa : getDeviceIfa(),
75+
bundle: bundle ? bundle.params.bundle : getAppBundle(),
76+
width: getDeviceWidth(),
77+
height: getDeviceHeight(),
7378
tid: tid ? tid.params.tid : undefined,
7479
version: VERSION,
7580
gdprApplies: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : undefined,
@@ -178,6 +183,10 @@ function hasIfaParam(bid) {
178183
return !!bid.params.ifa;
179184
}
180185

186+
function hasBundleParam(bid) {
187+
return !!bid.params.bundle;
188+
}
189+
181190
function hasTidParam(bid) {
182191
return !!bid.params.tid;
183192
}
@@ -264,4 +273,40 @@ function getTopWindowLocation(bidderRequest) {
264273
return config.getConfig('pageUrl') || url;
265274
}
266275

276+
function getAppBundle() {
277+
if (typeof config.getConfig('app') === 'object') {
278+
return config.getConfig('app').bundle;
279+
}
280+
}
281+
282+
function getAppDomain() {
283+
if (typeof config.getConfig('app') === 'object') {
284+
return config.getConfig('app').domain;
285+
}
286+
}
287+
288+
function getDeviceIfa() {
289+
if (typeof config.getConfig('device') === 'object') {
290+
return config.getConfig('device').ifa;
291+
}
292+
}
293+
294+
function getDeviceWidth() {
295+
let device = config.getConfig('device');
296+
if (typeof device === 'object' && device.width) {
297+
return device.width;
298+
}
299+
300+
return window.innerWidth;
301+
}
302+
303+
function getDeviceHeight() {
304+
let device = config.getConfig('device');
305+
if (typeof device === 'object' && device.height) {
306+
return device.height;
307+
}
308+
309+
return window.innerHeight;
310+
}
311+
267312
registerBidder(spec);

0 commit comments

Comments
 (0)