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

Re-implemented RhythmOne audit beacon in prebid 1.0 interface #1953

Merged
merged 3 commits into from
Jan 10, 2018
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
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.