Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from prebid:master #21

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions libraries/autoplayDetection/autoplay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
let autoplayEnabled = null;

/**
* Note: this function returns true if detection is not done yet. This is by design: if autoplay is not allowed,
* the call to video.play() will fail immediately, otherwise it may not terminate.
* @returns true if autoplay is not forbidden
*/
export const isAutoplayEnabled = () => autoplayEnabled !== false;

// generated with:
// ask ChatGPT for a 160x90 black PNG image (1/8th the size of 720p)
//
// encode with:
// ffmpeg -i black_image_160x90.png -r 1 -c:v libx264 -bsf:v 'filter_units=remove_types=6' -pix_fmt yuv420p autoplay.mp4
// this creates a 1 second long, 1 fps YUV 4:2:0 video encoded with H.264 without encoder details.
//
// followed by:
// echo "data:video/mp4;base64,$(base64 -i autoplay.mp4)"

const autoplayVideoUrl =
'data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAADxtZGF0AAAAMGWIhAAV//73ye/Apuvb3rW/k89I/Cy3PsIqP39atohOSV14BYa1heKCYgALQC5K4QAAAwZtb292AAAAbG12aGQAAAAAAAAAAAAAAAAAAAPoAAAD6AABAAABAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAACMHRyYWsAAABcdGtoZAAAAAMAAAAAAAAAAAAAAAEAAAAAAAAD6AAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAoAAAAFoAAAAAACRlZHRzAAAAHGVsc3QAAAAAAAAAAQAAA+gAAAAAAAEAAAAAAahtZGlhAAAAIG1kaGQAAAAAAAAAAAAAAAAAAEAAAABAAFXEAAAAAAAtaGRscgAAAAAAAAAAdmlkZQAAAAAAAAAAAAAAAFZpZGVvSGFuZGxlcgAAAAFTbWluZgAAABR2bWhkAAAAAQAAAAAAAAAAAAAAJGRpbmYAAAAcZHJlZgAAAAAAAAABAAAADHVybCAAAAABAAABE3N0YmwAAACvc3RzZAAAAAAAAAABAAAAn2F2YzEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAoABaAEgAAABIAAAAAAAAAAEVTGF2YzYwLjMxLjEwMiBsaWJ4MjY0AAAAAAAAAAAAAAAY//8AAAA1YXZjQwFkAAr/4QAYZ2QACqzZQo35IQAAAwABAAADAAIPEiWWAQAGaOvjyyLA/fj4AAAAABRidHJ0AAAAAAAAAaAAAAGgAAAAGHN0dHMAAAAAAAAAAQAAAAEAAEAAAAAAHHN0c2MAAAAAAAAAAQAAAAEAAAABAAAAAQAAABRzdHN6AAAAAAAAADQAAAABAAAAFHN0Y28AAAAAAAAAAQAAADAAAABidWR0YQAAAFptZXRhAAAAAAAAACFoZGxyAAAAAAAAAABtZGlyYXBwbAAAAAAAAAAAAAAAAC1pbHN0AAAAJal0b28AAAAdZGF0YQAAAAEAAAAATGF2ZjYwLjE2LjEwMA==';

function startDetection() {
// we create an HTMLVideoElement muted and not displayed in which we try to play a one frame video
const videoElement = document.createElement('video');
videoElement.src = autoplayVideoUrl;
videoElement.setAttribute('playsinline', 'true');
videoElement.muted = true;

videoElement
.play()
.then(() => {
autoplayEnabled = true;
videoElement.pause();
})
.catch(() => {
autoplayEnabled = false;
});
}

// starts detection as soon as this library is loaded
startDetection();
9 changes: 8 additions & 1 deletion modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ export const spec = {
ortb: bidResponse.native
};
} else {
result[ mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm;
if (mediaType === VIDEO) {
result.vastXml = bidResponse.adm;
if (bidResponse.nurl) {
result.vastUrl = bidResponse.nurl;
}
} else {
result.ad = bidResponse.adm;
}
}

if (!bid.renderer && mediaType === VIDEO && deepAccess(bid, 'mediaTypes.video.context') === 'outstream') {
Expand Down
7 changes: 3 additions & 4 deletions modules/adqueryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ export const spec = {
*/
onBidWon: (bid) => {
logInfo('onBidWon', bid);
const bidString = JSON.stringify(bid);
let copyOfBid = JSON.parse(bidString);
delete copyOfBid.ad;
const shortBidString = JSON.stringify(bid);
let copyOfBid = { ...bid }
delete copyOfBid.ad
const shortBidString = JSON.stringify(copyOfBid);
const encodedBuf = window.btoa(shortBidString);

let params = {
Expand Down
2 changes: 2 additions & 0 deletions modules/discoveryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ function getParam(validBidRequests, bidderRequest) {
const page = utils.deepAccess(bidderRequest, 'refererInfo.page');
const referer = utils.deepAccess(bidderRequest, 'refererInfo.ref');
const firstPartyData = bidderRequest.ortb2;
const tpData = utils.deepAccess(bidderRequest, 'ortb2.user.data') || undefined;
const topWindow = window.top;
const title = getPageTitle();
const desc = getPageDescription();
Expand All @@ -463,6 +464,7 @@ function getParam(validBidRequests, bidderRequest) {
firstPartyData,
ssppid: storage.getCookie(COOKIE_KEY_SSPPID) || undefined,
pmguid: getPmgUID(),
tpData,
page: {
title: title ? title.slice(0, 100) : undefined,
desc: desc ? desc.slice(0, 300) : undefined,
Expand Down
16 changes: 15 additions & 1 deletion modules/magniteAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const pbsErrorMap = {
4: 'request-error',
999: 'generic-error'
}
let cookieless;

let prebidGlobal = getGlobal();
const {
Expand Down Expand Up @@ -332,10 +333,14 @@ const getTopLevelDetails = () => {

// Add DM wrapper details
if (rubiConf.wrapperName) {
let rule;
if (cookieless) {
rule = rubiConf.rule_name ? rubiConf.rule_name.concat('_cookieless') : 'cookieless';
}
payload.wrapper = {
name: rubiConf.wrapperName,
family: rubiConf.wrapperFamily,
rule: rubiConf.rule_name
rule
}
}

Expand Down Expand Up @@ -823,6 +828,15 @@ magniteAdapter.track = ({ eventType, args }) => {
auctionData.floors = addFloorData(floorData);
}

// Identify chrome cookieless trafic
if (!cookieless) {
const cdep = deepAccess(args, 'bidderRequests.0.ortb2.device.ext.cdep');
if (cdep && (cdep.indexOf('treatment') !== -1 || cdep.indexOf('control_2') !== -1)) {
cookieless = 1;
auctionData.cdep = 1;
}
}

// GDPR info
const gdprData = deepAccess(args, 'bidderRequests.0.gdprConsent');
if (gdprData) {
Expand Down
18 changes: 12 additions & 6 deletions modules/teadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {getValue, logError, deepAccess, parseSizesInput, isArray, getBidIdParameter} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getStorageManager} from '../src/storageManager.js';
import {isAutoplayEnabled} from '../libraries/autoplayDetection/autoplay.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -120,11 +121,18 @@ export const spec = {
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidderRequest) {
const bidResponses = [];
serverResponse = serverResponse.body;

if (serverResponse.responses) {
serverResponse.responses.forEach(function (bid) {
if (!serverResponse.responses) {
return [];
}

const autoplayEnabled = isAutoplayEnabled();
return serverResponse.responses
.filter((bid) =>
// ignore this bid if it requires autoplay but it is not enabled on this browser
!bid.needAutoplay || autoplayEnabled
).map((bid) => {
const bidResponse = {
cpm: bid.cpm,
width: bid.width,
Expand All @@ -146,10 +154,8 @@ export const spec = {
if (bid?.ext?.dsa) {
bidResponse.meta.dsa = bid.ext.dsa;
}
bidResponses.push(bidResponse);
return bidResponse;
});
}
return bidResponses;
}
};

Expand Down
3 changes: 3 additions & 0 deletions modules/topicsFpdModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const bidderIframeList = {
}, {
bidder: 'taboola',
iframeURL: 'https://cdn.taboola.com/libtrc/static/topics/taboola-prebid-browsing-topics.html'
}, {
bidder: 'discovery',
iframeURL: 'https://api.popin.cc/topic/prebid-topics-frame.html'
}]
}

Expand Down
4 changes: 4 additions & 0 deletions modules/topicsFpdModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pbjs.setConfig({
bidder: 'taboola',
iframeURL: 'https://cdn.taboola.com/libtrc/static/topics/taboola-prebid-browsing-topics.html',
expiry: 7 // Configurable expiry days
}, {
bidder: 'discovery',
iframeURL: 'https://api.popin.cc/topic/prebid-topics-frame.html',
expiry: 7 // Configurable expiry days
}]
}
....
Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/adfBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,32 @@ describe('Adf adapter', function () {
assert.equal(bids[0].meta.mediaType, 'video');
});

it('should set vastUrl if nurl is present in response', function () {
let vastUrl = 'http://url.to/vast'
let serverResponse = {
body: {
seatbid: [{
bid: [{ impid: '1', adm: '<vast>', nurl: vastUrl, ext: { prebid: { type: 'video' } } }]
}]
}
};
let bidRequest = {
data: {},
bids: [
{
bidId: 'bidId1',
params: { mid: 1000 }
}
]
};

bids = spec.interpretResponse(serverResponse, bidRequest);
assert.equal(bids.length, 1);
assert.equal(bids[0].vastUrl, vastUrl);
assert.equal(bids[0].mediaType, 'video');
assert.equal(bids[0].meta.mediaType, 'video');
});

it('should add renderer for outstream bids', function () {
let serverResponse = {
body: {
Expand Down
23 changes: 23 additions & 0 deletions test/spec/modules/discoveryBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ describe('discovery:BidAdapterTests', function () {
bidderWinsCount: 0,
},
],
ortb2: {
user: {
data: {
segment: [
{
id: '412'
}
],
name: 'test.popin.cc',
ext: {
segclass: '1',
segtax: 503
}
}
}
}
};
let request = [];

Expand Down Expand Up @@ -189,6 +205,13 @@ describe('discovery:BidAdapterTests', function () {
let req_data = JSON.parse(request.data);
expect(req_data.imp).to.have.lengthOf(1);
});
describe('first party data', function () {
it('should pass additional parameter in request for topics', function () {
const request = spec.buildRequests(bidRequestData.bids, bidRequestData);
let res = JSON.parse(request.data);
expect(res.ext.tpData).to.deep.equal(bidRequestData.ortb2.user.data);
});
});

describe('discovery: buildRequests', function() {
describe('getPmgUID function', function() {
Expand Down
73 changes: 73 additions & 0 deletions test/spec/modules/magniteAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,79 @@ describe('magnite analytics adapter', function () {
expect(message1.bidsWon).to.deep.equal([expectedMessage1]);
});
});
describe('cookieless', () => {
beforeEach(() => {
magniteAdapter.enableAnalytics({
options: {
cookieles: undefined
}
});
})
afterEach(() => {
magniteAdapter.disableAnalytics();
})
it('should add sufix _cookieless to the wrapper.rule if ortb2.device.ext.cdep start with "treatment" or "control_2"', () => {
// Set the confs
config.setConfig({
rubicon: {
wrapperName: '1001_general',
wrapperFamily: 'general',
rule_name: 'desktop-magnite.com',
}
});
const auctionId = MOCK.AUCTION_INIT.auctionId;

let auctionInit = utils.deepClone(MOCK.AUCTION_INIT);
auctionInit.bidderRequests[0].ortb2.device.ext = { cdep: 'treatment' };
// Run auction
events.emit(AUCTION_INIT, auctionInit);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
[gptSlotRenderEnded0].forEach(gptEvent => mockGpt.emitEvent(gptEvent.eventName, gptEvent.params));
events.emit(BID_WON, { ...MOCK.BID_WON, auctionId });
clock.tick(rubiConf.analyticsEventDelay);
expect(server.requests.length).to.equal(1);
let request = server.requests[0];
let message = JSON.parse(request.requestBody);
expect(message.wrapper).to.deep.equal({
name: '1001_general',
family: 'general',
rule: 'desktop-magnite.com_cookieless',
});
})
it('should add cookieless to the wrapper.rule if ortb2.device.ext.cdep start with "treatment" or "control_2"', () => {
// Set the confs
config.setConfig({
rubicon: {
wrapperName: '1001_general',
wrapperFamily: 'general',
}
});
const auctionId = MOCK.AUCTION_INIT.auctionId;

let auctionInit = utils.deepClone(MOCK.AUCTION_INIT);
auctionInit.bidderRequests[0].ortb2.device.ext = { cdep: 'control_2' };
// Run auction
events.emit(AUCTION_INIT, auctionInit);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
[gptSlotRenderEnded0].forEach(gptEvent => mockGpt.emitEvent(gptEvent.eventName, gptEvent.params));
events.emit(BID_WON, { ...MOCK.BID_WON, auctionId });
clock.tick(rubiConf.analyticsEventDelay);
expect(server.requests.length).to.equal(1);
let request = server.requests[0];
let message = JSON.parse(request.requestBody);
expect(message.wrapper).to.deep.equal({
family: 'general',
name: '1001_general',
rule: 'cookieless',
});
});
});
});

describe('billing events integration', () => {
Expand Down
Loading
Loading