From 8ae5925743c1d3708a11fe65cc62c730d29fc9ae Mon Sep 17 00:00:00 2001 From: mkendall07 Date: Fri, 5 May 2017 11:59:53 -0400 Subject: [PATCH 1/4] Clear cookie sync to prevent multiple calls --- src/adapters/rhythmone.js | 96 +++++++++++++++++++-------------------- src/cookie.js | 2 + 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/adapters/rhythmone.js b/src/adapters/rhythmone.js index 9d24e9fac98..c8e81d110e3 100644 --- a/src/adapters/rhythmone.js +++ b/src/adapters/rhythmone.js @@ -3,7 +3,7 @@ var bidmanager = require('../bidmanager.js'), CONSTANTS = require('../constants.json'); import {ajax as ajax} from '../ajax'; - + module.exports = function(bidManager, global, loader){ var version = "0.9.0.0", @@ -15,16 +15,16 @@ module.exports = function(bidManager, global, loader){ loadStart, configuredPlacements = [], fat = /(^v|(\.0)+$)/gi; - + if(typeof global === "undefined") global = window; - + if(typeof bidManager === "undefined") bidManager = bidmanager; - + if(typeof loader === "undefined") loader = ajax; - + function applyMacros(txt, values){ return txt.replace(/\{([^\}]+)\}/g, function(match){ var v = values[match.replace(/[\{\}]/g, "").toLowerCase()]; @@ -32,7 +32,7 @@ module.exports = function(bidManager, global, loader){ return match; }); } - + function load(bidParams, url, callback){ loader(url, function(responseText, response){ if(response.status === 200) @@ -49,7 +49,7 @@ module.exports = function(bidManager, global, loader){ t = "application/x-shockwave-flash", x = global.ActiveXObject; - if(p && + if(p && p["Shockwave Flash"] && m && m[t] && @@ -63,28 +63,28 @@ module.exports = function(bidManager, global, loader){ return false; } - + var bidderCode = "rhythmone"; - + function attempt(valueFunction, defaultValue){ try{ return valueFunction(); }catch(ex){} return defaultValue; } - + function logToConsole(txt){ if(debug) console.log(txt); } - + function getBidParameters(bids){ for(var i=0;i 0 && typeof bids[i].sizes[0] === "number") bids[i].sizes = [bids[i].sizes]; - + for(var j = 0; j 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); if(bidParams === null){ @@ -240,7 +240,7 @@ module.exports = function(bidManager, global, loader){ for(var i = 0; i Date: Fri, 5 May 2017 12:01:41 -0400 Subject: [PATCH 2/4] unit tests --- test/spec/cookie_spec.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/spec/cookie_spec.js diff --git a/test/spec/cookie_spec.js b/test/spec/cookie_spec.js new file mode 100644 index 00000000000..1cf3fa80b02 --- /dev/null +++ b/test/spec/cookie_spec.js @@ -0,0 +1,33 @@ +import cookie from '../../src/cookie'; +import { expect } from 'chai'; +var utils = require('../../src/utils'); + +describe('cookie.queueSync', () => { + + let insertCookieSyncIframeStub = sinon.stub(utils, 'insertCookieSyncIframe'); + let insertPixelStub = sinon.stub(utils, 'insertPixel'); + + beforeEach(() => { + insertCookieSyncIframeStub.reset(); + insertPixelStub.reset(); + }); + + it('queues and fires a pixel URL', () => { + cookie.queueSync({'bidder' : 'testBidder', 'url': 'http://url.com'}); + cookie.syncCookies(); + expect(insertPixelStub.getCall(0).args[0]).to.exist.and.to.equal('http://url.com'); + }); + + it('queues and fires a iframe URL', () => { + cookie.queueSync({'url': 'http://url.com', 'type': 'iframe'}); + cookie.syncCookies(); + expect(insertCookieSyncIframeStub.getCall(0).args[0]).to.exist.and.to.equal('http://url.com'); + }); + + it('clears queue after sync', () => { + cookie.syncCookies(); + expect(insertCookieSyncIframeStub.callCount).to.equal(0); + expect(insertPixelStub.callCount).to.equal(0); + }); + +}); From f57d083f98cdd9cfadcffc6ff2c437ba68f27500 Mon Sep 17 00:00:00 2001 From: mkendall07 Date: Fri, 5 May 2017 12:09:52 -0400 Subject: [PATCH 3/4] style fixed --- src/cookie.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/cookie.js b/src/cookie.js index 82d34e3d852..95f80623c25 100644 --- a/src/cookie.js +++ b/src/cookie.js @@ -6,7 +6,7 @@ const queue = []; function fireSyncs() { queue.forEach(obj => { utils.logMessage(`Invoking cookie sync for bidder: ${obj.bidder}`); - if(obj.type === 'iframe') { + if (obj.type === 'iframe') { utils.insertCookieSyncIframe(obj.url, false); } else { utils.insertPixel(obj.url); @@ -21,7 +21,7 @@ function fireSyncs() { * @param {String} bidder bidder code * @param {String} url optional URL for invoking cookie sync if provided. */ -cookie.queueSync = function ({bidder, url, type}) { +cookie.queueSync = function({bidder, url, type}) { queue.push({bidder, url, type}); }; @@ -30,16 +30,15 @@ cookie.queueSync = function ({bidder, url, type}) { * @param {number} timeout time in ms to delay in sending */ cookie.syncCookies = function(timeout) { - if(timeout) { + if (timeout) { setTimeout(fireSyncs, timeout); - } - else { + } else { fireSyncs(); } }; cookie.persist = function(url, msgHtml) { - if(!utils.isSafariBrowser()){ + if (!utils.isSafariBrowser()) { return; } linkOverride(url); @@ -47,7 +46,7 @@ cookie.persist = function(url, msgHtml) { }; function linkOverride(url) { - for (var i = 0; i < document.links.length; i++){ + for (var i = 0; i < document.links.length; i++) { var link = document.links[i]; link.href = url + encodeURIComponent(link.href); } @@ -66,21 +65,17 @@ function createFooter(msgHtml) { footer.style.background = '#D3D3D3'; footer.style.color = '#555'; footer.style.boxShadow = '0 -1px 2px rgba(0, 0, 0, 0.2)'; - footer.style.fontFamily = 'sans-serif'; footer.style.lineHeight = '1.5'; - footer.style.position = 'fixed'; footer.style.bottom = '0'; footer.style.left = '0'; footer.style.right = '0'; footer.style.width = '100%'; - footer.style.padding = '1em 0'; footer.style.zindex = '1000'; const footerText = document.createElement('p'); - footerText.style.margin = '0 2em'; footerText.innerHTML = msgHtml; footer.appendChild(footerText); From 5514c3c2d4195afebfd5c12606e3b41befbc4807 Mon Sep 17 00:00:00 2001 From: mkendall07 Date: Fri, 5 May 2017 12:12:02 -0400 Subject: [PATCH 4/4] put back margin --- src/cookie.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cookie.js b/src/cookie.js index 95f80623c25..8e823b1acd9 100644 --- a/src/cookie.js +++ b/src/cookie.js @@ -6,7 +6,7 @@ const queue = []; function fireSyncs() { queue.forEach(obj => { utils.logMessage(`Invoking cookie sync for bidder: ${obj.bidder}`); - if (obj.type === 'iframe') { + if(obj.type === 'iframe') { utils.insertCookieSyncIframe(obj.url, false); } else { utils.insertPixel(obj.url); @@ -21,7 +21,7 @@ function fireSyncs() { * @param {String} bidder bidder code * @param {String} url optional URL for invoking cookie sync if provided. */ -cookie.queueSync = function({bidder, url, type}) { +cookie.queueSync = function ({bidder, url, type}) { queue.push({bidder, url, type}); }; @@ -30,15 +30,16 @@ cookie.queueSync = function({bidder, url, type}) { * @param {number} timeout time in ms to delay in sending */ cookie.syncCookies = function(timeout) { - if (timeout) { + if(timeout) { setTimeout(fireSyncs, timeout); - } else { + } + else { fireSyncs(); } }; cookie.persist = function(url, msgHtml) { - if (!utils.isSafariBrowser()) { + if(!utils.isSafariBrowser()){ return; } linkOverride(url); @@ -46,7 +47,7 @@ cookie.persist = function(url, msgHtml) { }; function linkOverride(url) { - for (var i = 0; i < document.links.length; i++) { + for (var i = 0; i < document.links.length; i++){ var link = document.links[i]; link.href = url + encodeURIComponent(link.href); } @@ -76,6 +77,7 @@ function createFooter(msgHtml) { footer.style.zindex = '1000'; const footerText = document.createElement('p'); + footerText.style.margin = '0 2em'; footerText.innerHTML = msgHtml; footer.appendChild(footerText);