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

AudienceRun Bid Adapter: Add Support for User Matching, Referer, … #8261

Merged
merged 3 commits into from
Apr 18, 2022
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
97 changes: 75 additions & 22 deletions modules/audiencerunBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import { deepAccess, isFn, logError, getValue, getBidIdParameter, _each, isArray, triggerPixel } from '../src/utils.js';
import {
deepAccess,
isFn,
logError,
getValue,
getBidIdParameter,
_each,
isArray,
triggerPixel,
formatQS,
} from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { createEidsArray } from './userId/eids.js';

const BIDDER_CODE = 'audiencerun';
const BASE_URL = 'https://d.audiencerun.com';
const AUCTION_URL = `${BASE_URL}/prebid`;
const TIMEOUT_EVENT_URL = `${BASE_URL}/ps/pbtimeout`;
const ERROR_EVENT_URL = `${BASE_URL}/js_log`;
const DEFAULT_CURRENCY = 'USD';

let requestedBids = [];

/**
* Gets bidder request referer
*
* @param {Object} bidderRequest
* @return {string}
*/
function getPageUrl(bidderRequest) {
return (
config.getConfig('pageUrl') ||
deepAccess(bidderRequest, 'refererInfo.referer') ||
null
);
}

/**
* Returns bidfloor through floors module if available
* Returns bidfloor through floors module if available.
*
* @param {Object} bid
* @returns {number}
Expand All @@ -44,19 +42,53 @@ function getBidFloor(bid) {
});
return bidFloor.floor;
} catch (_) {
return 0
return 0;
}
}

/**
* Returns the most top page referer.
*
* @returns {string}
*/
function getPageReferer() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is being duplicated?

bidderRequest.refererInfo.referer does this logic already, so not really sure this is needed.

https://github.com/prebid/Prebid.js/blob/master/src/refererDetection.js

Copy link
Contributor Author

@audiencerun audiencerun Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @robertrmartinez, it is not a duplicate as bidderRequest.refererInfo.referer seems to return at first the URL of the page where Prebid.js is called while we need the URL that linked to this page and not the URL of the current page.

Here is a screen that shows it and is available at https://7buoei.csb.app/?pbjs_debug=true

pWjdre9U

Feel free if you need more details.

let t, e;
do {
t = t ? t.parent : window;
try {
e = t.document.referrer;
} catch (_) {
break;
}
} while (t !== window.top);
return e;
}

/**
* Returns bidder request page url.
*
* @param {Object} bidderRequest
* @return {string}
*/
function getPageUrl(bidderRequest) {
return (
config.getConfig('pageUrl') ||
deepAccess(bidderRequest, 'refererInfo.referer') ||
getPageReferer() ||
null
);
}

export const spec = {
version: '1.1.0',
version: '1.2.0',
code: BIDDER_CODE,
gvlid: 944,
supportedMediaTypes: [BANNER],

/**
* Determines whether or not the given bid request is valid.
*
* @param {object} bid The bid to validate.
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
Expand Down Expand Up @@ -95,12 +127,19 @@ export const spec = {

const payload = {
libVersion: this.version,
referer: getPageUrl(bidderRequest),
pageUrl: config.getConfig('pageUrl'),
pageReferer: getPageReferer(),
referer: deepAccess(bidderRequest, 'refererInfo.referer'),
refererInfo: deepAccess(bidderRequest, 'refererInfo'),
currencyCode: config.getConfig('currency.adServerCurrency'),
timeout: config.getConfig('bidderTimeout'),
bids,
};

payload.uspConsent = deepAccess(bidderRequest, 'uspConsent');
payload.schain = deepAccess(bidRequests, '0.schain');
payload.userId = deepAccess(bidRequests, '0.userId') ? createEidsArray(bidRequests[0].userId) : [];

if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr = {
consent: bidderRequest.gdprConsent.consentString,
Expand All @@ -117,7 +156,7 @@ export const spec = {

return {
method: 'POST',
url: AUCTION_URL,
url: deepAccess(bidRequests, '0.params.auctionUrl', AUCTION_URL),
data: JSON.stringify(payload),
options: {
withCredentials: true,
Expand Down Expand Up @@ -201,7 +240,9 @@ export const spec = {
}

timeoutData.forEach((bid) => {
const bidOnTimeout = requestedBids.find((requestedBid) => requestedBid.bidId === bid.bidId);
const bidOnTimeout = requestedBids.find(
(requestedBid) => requestedBid.bidId === bid.bidId
);

if (bidOnTimeout) {
triggerPixel(
Expand All @@ -210,6 +251,18 @@ export const spec = {
}
});
},

/**
* Registers bidder specific code, which will execute if the bidder responded with an error.
* @param {{bidderRequest: object}} args An object from which we extract bidderRequest object.
*/
onBidderError: function ({ bidderRequest }) {
const queryString = formatQS({
message: `Prebid.js: Server call for ${bidderRequest.bidderCode} failed.`,
url: encodeURIComponent(getPageUrl(bidderRequest)),
});
triggerPixel(`${ERROR_EVENT_URL}/?${queryString}`);
},
};

registerBidder(spec);
Loading