Skip to content

Commit

Permalink
Re-implemented RhythmOne audit beacon in prebid 1.0 interface (prebid…
Browse files Browse the repository at this point in the history
…#1953)

* Re-implemented RhythmOne audit beacon in prebid 1.0 interface

* removed references to prebid_global and added more unit test coverage

* removed block that sends beacons when usersync is disabled
  • Loading branch information
jstocker76 authored and dluxemburg committed Jul 17, 2018
1 parent 672ae0d commit 681ed2f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
66 changes: 62 additions & 4 deletions modules/rhythmoneBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,61 @@ function RhythmOneBidAdapter() {
return true;
};

this.getUserSyncs = function (syncOptions) {
let slots = [];
let placementIds = [];

for (let k in slotsToBids) {
slots.push(k);
placementIds.push(getFirstParam('placementId', [slotsToBids[k]]));
}

let data = {
doc_version: 1,
doc_type: 'Prebid Audit',
placement_id: placementIds.join(',').replace(/[,]+/g, ',').replace(/^,|,$/g, '')
};
let w = typeof (window) !== 'undefined' ? window : {document: {location: {href: ''}}};
let ao = w.document.location.ancestorOrigins;
let q = [];
let u = '//hbevents.1rx.io/audit?';

if (ao && ao.length > 0) {
data.ancestor_origins = ao[ao.length - 1];
}

data.popped = w.opener !== null ? 1 : 0;
data.framed = w.top === w ? 0 : 1;

try {
data.url = w.top.document.location.href.toString();
} catch (ex) {
data.url = w.document.location.href.toString();
}

try {
data.prebid_version = '$prebid.version$';
data.prebid_timeout = config.getConfig('bidderTimeout');
} catch (ex) { }

data.response_ms = Date.now() - loadStart;
data.placement_codes = slots.join(',');
data.bidder_version = version;

for (let k in data) {
q.push(encodeURIComponent(k) + '=' + encodeURIComponent((typeof data[k] === 'object' ? JSON.stringify(data[k]) : data[k])));
}

q.sort();

if (syncOptions.pixelEnabled) {
return [{
type: 'image',
url: u + q.join('&')
}];
}
};

function getFirstParam(key, validBidRequests) {
for (let i = 0; i < validBidRequests.length; i++) {
if (validBidRequests[i].params && validBidRequests[i].params[key]) {
Expand All @@ -22,20 +77,22 @@ function RhythmOneBidAdapter() {
let slotsToBids = {};
let that = this;
let version = '1.0.0.0';
let loadStart = Date.now();

this.buildRequests = function (BRs) {
let fallbackPlacementId = getFirstParam('placementId', BRs);
if (fallbackPlacementId === undefined || BRs.length < 1) {
return [];
}

loadStart = Date.now();
slotsToBids = {};

let query = [];
let w = (typeof window !== 'undefined' ? window : {});

function p(k, v) {
if (v instanceof Array) { v = v.join(','); }
function p(k, v, d) {
if (v instanceof Array) { v = v.join((d || ',')); }
if (typeof v !== 'undefined') { query.push(encodeURIComponent(k) + '=' + encodeURIComponent(v)); }
}

Expand Down Expand Up @@ -98,8 +155,7 @@ function RhythmOneBidAdapter() {
if ((new w.ActiveXObject('ShockwaveFlash.ShockwaveFlash'))) {
return 1;
}
} catch (e) {
}
} catch (e) { }
}

return 0;
Expand Down Expand Up @@ -186,12 +242,14 @@ function RhythmOneBidAdapter() {

if (bidRequest.mediaTypes && bidRequest.mediaTypes.video) {
bidResponse.vastUrl = bid.nurl;
bidResponse.mediaType = 'video';
bidResponse.ttl = 10000;
} else {
bidResponse.ad = bid.adm;
}
bids.push(bidResponse);
}

return bids;
};
}
Expand Down
10 changes: 10 additions & 0 deletions test/spec/modules/rhythmoneBidAdapter_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 681ed2f

Please sign in to comment.