diff --git a/src/adapters/rhythmone.js b/src/adapters/rhythmone.js index 57b6e29a2172..9d24e9fac986 100644 --- a/src/adapters/rhythmone.js +++ b/src/adapters/rhythmone.js @@ -3,15 +3,6 @@ var bidmanager = require('../bidmanager.js'), CONSTANTS = require('../constants.json'); import {ajax as ajax} from '../ajax'; - -function track(debug) { - if(debug === true){ - //console.log('GA: %s %s %s', p1, p2, p3 || ''); - } -} - -var w = (typeof window !== "undefined" ? window : {}); -w.trackR1Impression = track; module.exports = function(bidManager, global, loader){ @@ -19,9 +10,11 @@ module.exports = function(bidManager, global, loader){ defaultZone = "1r", defaultPath = "mvo", debug = false, - auctionEnded = false, requestCompleted = false, - placementCodes = {}; + placementCodes = {}, + loadStart, + configuredPlacements = [], + fat = /(^v|(\.0)+$)/gi; if(typeof global === "undefined") global = window; @@ -71,8 +64,7 @@ module.exports = function(bidManager, global, loader){ return false; } - var bidderCode = "rhythmone", - bidLostTimeout = null; + var bidderCode = "rhythmone"; function attempt(valueFunction, defaultValue){ try{ @@ -86,34 +78,6 @@ module.exports = function(bidManager, global, loader){ console.log(txt); } - function sniffAuctionEnd(){ - - global.$$PREBID_GLOBAL$$.onEvent('bidWon', function (e) { - - if(e.bidderCode === bidderCode){ - placementCodes[e.adUnitCode] = true; - track(debug, 'hb', "bidWon"); - } - - if(auctionEnded){ - clearTimeout(bidLostTimeout); - bidLostTimeout = setTimeout(function(){ - for(var k in placementCodes) - if(placementCodes[k] === false) - track(debug, 'hb', "bidLost"); - }, 50); - } - }); - - global.$$PREBID_GLOBAL$$.onEvent('auctionEnd', function () { - - auctionEnded = true; - - if(requestCompleted === false) - track(debug, 'hb', 'rmpReplyFail', "prebid timeout post auction"); - }); - } - function getBidParameters(bids){ for(var i=0;i 0) return d[d.length-1]; - return global.top.document.location.hostname; + return global.top.document.location.hostname; // try/catch is in the attempt function },"")); - p("title", attempt(function(){return global.top.document.title;},"")); + p("title", attempt(function(){return global.top.document.title;},"")); // try/catch is in the attempt function p("url", attempt(function(){ var l; - try{l = global.top.document.location.href.toString();} + try{l = global.top.document.location.href.toString();} // try/catch is in the attempt function catch(ex){l = global.document.location.href.toString();} return l; },"")); @@ -184,19 +147,18 @@ module.exports = function(bidManager, global, loader){ p("dtype", ((/(ios|ipod|ipad|iphone|android)/i).test(global.navigator.userAgent) ? 1 : ((/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(global.navigator.userAgent) ? 3 : 2))); p("flash", (flashInstalled() ? 1 : 0)); - var placementCodes = [], - heights = [], + var heights = [], widths = [], floors = [], mediaTypes = [], - fat = /(^v|(\.0)+$)/gi, i=0; + configuredPlacements = []; + p("hbv", global.$$PREBID_GLOBAL$$.version.replace(fat,"")+","+version.replace(fat,"")); - + for(; i 0 && typeof bids[i].sizes[0] === "number") @@ -206,14 +168,14 @@ module.exports = function(bidManager, global, loader){ tw.push(bids[i].sizes[j][0]); th.push(bids[i].sizes[j][1]); } - placementCodes.push(bids[i].placementCode); + configuredPlacements.push(bids[i].placementCode); heights.push(th.join("|")); widths.push(tw.join("|")); mediaTypes.push(((/video/i).test(bids[i].mediaType) ? "v" : "d")); floors.push(0); } - p("imp", placementCodes); + p("imp", configuredPlacements); p("w", widths); p("h", heights); p("floor", floors); @@ -224,53 +186,76 @@ module.exports = function(bidManager, global, loader){ return endpoint; } + function sendAuditBeacon(placementId){ + var data = { + doc_version : 1, + doc_type : "Prebid Audit", + placement_id: placementId + }, + ao = document.location.ancestorOrigins, + q = [], + u = "//hbevents.1rx.io/audit?", + i = new Image(); + + if(ao && ao.length > 0){ + data.ancestor_origins = ao[ao.length-1]; + } + + data.popped = window.opener!==null?1:0; + data.framed = window.top===window?0:1; + + try{ + data.url = window.top.document.location.href.toString(); + }catch(ex){ + data.url = window.document.location.href.toString(); + } + + var prebid_instance = global.$$PREBID_GLOBAL$$; + + data.prebid_version = prebid_instance.version.replace(fat,""); + data.response_ms = (new Date()).getTime() - loadStart; + data.placement_codes = configuredPlacements.join(","); + data.bidder_version = version; + data.prebid_timeout = prebid_instance.cbTimeout || prebid_instance.bidderTimeout; + + for(var k in data){ + q.push(encodeURIComponent(k)+"="+encodeURIComponent((typeof data[k] === "object" ? JSON.stringify(data[k]) : data[k]))); + } + + q.sort(); + i.src = u+q.join("&"); + } + this.callBids = function(params){ var slotMap = {}, bidParams = getBidParameters(params.bids); debug = (bidParams !== null && bidParams.debug === true); - - track(debug, 'hb', 'callBids'); if(bidParams === null){ noBids(params); - track(debug, 'hb', 'misconfiguration'); return; } - sniffAuctionEnd(); - - track(debug, 'hb', 'rmpRequest'); - for(var i = 0; i