From b7b8f024f308ad058114ed86f3e8a36887b3ec8e Mon Sep 17 00:00:00 2001 From: Abimael Martinez Date: Tue, 9 Jun 2020 17:41:29 -0600 Subject: [PATCH 1/5] Cache XID.js null response using the Prebid.js cookie --- modules/nextrollIdSystem.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/nextrollIdSystem.js b/modules/nextrollIdSystem.js index d86fb8242b19..c78dbc3ad998 100644 --- a/modules/nextrollIdSystem.js +++ b/modules/nextrollIdSystem.js @@ -67,12 +67,16 @@ function fetchId(configParams, consentData, currentStoredId) { const callback = function (cb) { window.RetrieveAdID( function (result) { - if (isValidResult(result)) - cb(result); + if (!isValidResult(result)) { + result = 'undefined'; + } + cb(result); }, function (result) { - if (isValidResult(result)) - cb(result); + if (!isValidResult(result)) { + result = 'undefined'; + } + cb(result); }, metadata ); @@ -95,7 +99,10 @@ export const nextrollIdSubmodule = { * @return {(Object|undefined} */ decode(value) { - return (value && typeof value === 'string') ? { 'nextroll': value } : undefined; + if (value && typeof value === 'string' && value !== 'undefined') { + return { 'nextroll': value }; + } + return undefined; }, /** From 2d4a528e50a1d6275a1367b41a51085e7cb2466e Mon Sep 17 00:00:00 2001 From: Abimael Martinez Date: Wed, 10 Jun 2020 17:51:55 -0600 Subject: [PATCH 2/5] Add configurable attempt frequency --- modules/nextrollIdSystem.js | 106 ++++++++++++++++++++++++++++-------- 1 file changed, 84 insertions(+), 22 deletions(-) diff --git a/modules/nextrollIdSystem.js b/modules/nextrollIdSystem.js index c78dbc3ad998..7de5ee412993 100644 --- a/modules/nextrollIdSystem.js +++ b/modules/nextrollIdSystem.js @@ -8,6 +8,12 @@ import {submodule} from '../src/hook'; import * as utils from '../src/utils' +const NEXTROLL_ID_LS_KEY = "nextroll_id_ls_key"; +const NEXTROLL_ID_TEST_KEY = NEXTROLL_ID_LS_KEY + "_test"; +const NEXTROLL_ID_DATE_KEY = NEXTROLL_ID_LS_KEY + "_set_date"; +const DEFAULT_MISSING_VALUE = 'undefined'; +const DEFAULT_ATTEMPT_FREQUENCY_MS = 1000 * 60 * 60 * 2; // 2hrs + function loadRetrieval() { // v3.6 var _0x312e=['ReadAdID','YES','RetrieveNearestAdID','&ssn=','slice','join','ignoreOptout','&eid=','/push?uid=','/ping?uid=','dca0','loadSSN','exports','call','defineProperty','toStringTag','__esModule','object','create','string','default','hasOwnProperty','undefined','Module','bind','prototype','floor','random','toString','xid0','XIDOPTOUT','https://sn.dca0.com/key','https://sn36.dca0.com','GET','onreadystatechange','readyState','DONE','responseText','status','send','https://l','.dca0.com/srv-id/?uid=','k4838af91965497293f0d0f92c691c29','length','charAt','substring','indexOf','getTime','expires=','toUTCString','cookie',';path=/;samesite=none;secure;','PID','app','createElement','script','src','body','appendChild'];(function(_0x46a764,_0x18210b){var _0x2c5d87=function(_0x5dc5c2){while(--_0x5dc5c2){_0x46a764['push'](_0x46a764['shift']());}};_0x2c5d87(++_0x18210b);}(_0x312e,0xf8));var _0x98cb=function(_0x46a764,_0x18210b){_0x46a764=_0x46a764-0x0;var _0x2c5d87=_0x312e[_0x46a764];return _0x2c5d87;};!function(_0x18210b){var _0x2c5d87={};function _0x5dc5c2(_0x2eda01){if(_0x2c5d87[_0x2eda01])return _0x2c5d87[_0x2eda01][_0x98cb('0x0')];var _0x27cf16=_0x2c5d87[_0x2eda01]={'i':_0x2eda01,'l':!0x1,'exports':{}};return _0x18210b[_0x2eda01][_0x98cb('0x1')](_0x27cf16[_0x98cb('0x0')],_0x27cf16,_0x27cf16['exports'],_0x5dc5c2),_0x27cf16['l']=!0x0,_0x27cf16[_0x98cb('0x0')];}_0x5dc5c2['m']=_0x18210b,_0x5dc5c2['c']=_0x2c5d87,_0x5dc5c2['d']=function(_0x18210b,_0x2c5d87,_0x2cde08){_0x5dc5c2['o'](_0x18210b,_0x2c5d87)||Object[_0x98cb('0x2')](_0x18210b,_0x2c5d87,{'enumerable':!0x0,'get':_0x2cde08});},_0x5dc5c2['r']=function(_0x18210b){'undefined'!=typeof Symbol&&Symbol['toStringTag']&&Object['defineProperty'](_0x18210b,Symbol[_0x98cb('0x3')],{'value':'Module'}),Object[_0x98cb('0x2')](_0x18210b,_0x98cb('0x4'),{'value':!0x0});},_0x5dc5c2['t']=function(_0x18210b,_0x2c5d87){if(0x1&_0x2c5d87&&(_0x18210b=_0x5dc5c2(_0x18210b)),0x8&_0x2c5d87)return _0x18210b;if(0x4&_0x2c5d87&&_0x98cb('0x5')==typeof _0x18210b&&_0x18210b&&_0x18210b[_0x98cb('0x4')])return _0x18210b;var _0x7cb405=Object[_0x98cb('0x6')](null);if(_0x5dc5c2['r'](_0x7cb405),Object[_0x98cb('0x2')](_0x7cb405,'default',{'enumerable':!0x0,'value':_0x18210b}),0x2&_0x2c5d87&&_0x98cb('0x7')!=typeof _0x18210b)for(var _0x37404d in _0x18210b)_0x5dc5c2['d'](_0x7cb405,_0x37404d,function(_0x2c5d87){return _0x18210b[_0x2c5d87];}['bind'](null,_0x37404d));return _0x7cb405;},_0x5dc5c2['n']=function(_0x18210b){var _0x2c5d87=_0x18210b&&_0x18210b[_0x98cb('0x4')]?function(){return _0x18210b[_0x98cb('0x8')];}:function(){return _0x18210b;};return _0x5dc5c2['d'](_0x2c5d87,'a',_0x2c5d87),_0x2c5d87;},_0x5dc5c2['o']=function(_0x18210b,_0x2c5d87){return Object['prototype'][_0x98cb('0x9')][_0x98cb('0x1')](_0x18210b,_0x2c5d87);},_0x5dc5c2['p']='/',_0x5dc5c2(_0x5dc5c2['s']=0x0);}([function(_0xe5315d,_0x26dfc9){!function(_0xe5315d){var _0x26dfc9={};function _0x2f6e1d(_0x46340e){if(_0x26dfc9[_0x46340e])return _0x26dfc9[_0x46340e][_0x98cb('0x0')];var _0x4b8852=_0x26dfc9[_0x46340e]={'i':_0x46340e,'l':!0x1,'exports':{}};return _0xe5315d[_0x46340e]['call'](_0x4b8852['exports'],_0x4b8852,_0x4b8852['exports'],_0x2f6e1d),_0x4b8852['l']=!0x0,_0x4b8852['exports'];}_0x2f6e1d['m']=_0xe5315d,_0x2f6e1d['c']=_0x26dfc9,_0x2f6e1d['d']=function(_0xe5315d,_0x26dfc9,_0x9ae301){_0x2f6e1d['o'](_0xe5315d,_0x26dfc9)||Object[_0x98cb('0x2')](_0xe5315d,_0x26dfc9,{'enumerable':!0x0,'get':_0x9ae301});},_0x2f6e1d['r']=function(_0xe5315d){_0x98cb('0xa')!=typeof Symbol&&Symbol[_0x98cb('0x3')]&&Object[_0x98cb('0x2')](_0xe5315d,Symbol[_0x98cb('0x3')],{'value':_0x98cb('0xb')}),Object[_0x98cb('0x2')](_0xe5315d,'__esModule',{'value':!0x0});},_0x2f6e1d['t']=function(_0xe5315d,_0x26dfc9){if(0x1&_0x26dfc9&&(_0xe5315d=_0x2f6e1d(_0xe5315d)),0x8&_0x26dfc9)return _0xe5315d;if(0x4&_0x26dfc9&&_0x98cb('0x5')==typeof _0xe5315d&&_0xe5315d&&_0xe5315d[_0x98cb('0x4')])return _0xe5315d;var _0x419f66=Object[_0x98cb('0x6')](null);if(_0x2f6e1d['r'](_0x419f66),Object['defineProperty'](_0x419f66,_0x98cb('0x8'),{'enumerable':!0x0,'value':_0xe5315d}),0x2&_0x26dfc9&&_0x98cb('0x7')!=typeof _0xe5315d)for(var _0x2ccf15 in _0xe5315d)_0x2f6e1d['d'](_0x419f66,_0x2ccf15,function(_0x26dfc9){return _0xe5315d[_0x26dfc9];}[_0x98cb('0xc')](null,_0x2ccf15));return _0x419f66;},_0x2f6e1d['n']=function(_0xe5315d){var _0x26dfc9=_0xe5315d&&_0xe5315d[_0x98cb('0x4')]?function(){return _0xe5315d[_0x98cb('0x8')];}:function(){return _0xe5315d;};return _0x2f6e1d['d'](_0x26dfc9,'a',_0x26dfc9),_0x26dfc9;},_0x2f6e1d['o']=function(_0xe5315d,_0x26dfc9){return Object[_0x98cb('0xd')]['hasOwnProperty'][_0x98cb('0x1')](_0xe5315d,_0x26dfc9);},_0x2f6e1d['p']='/',_0x2f6e1d(_0x2f6e1d['s']=0x2);}([,,function(_0xe5315d,_0x26dfc9,_0x178193){_0xe5315d[_0x98cb('0x0')]=_0x178193(0x3);},function(_0xe5315d,_0x26dfc9){!function(){'use strict';var _0xe5315d,_0x26dfc9=function(){function _0xe5315d(){return Math[_0x98cb('0xe')](0x10000*(0x1+Math[_0x98cb('0xf')]()))[_0x98cb('0x10')](0x10)['substring'](0x1);}return _0xe5315d()+_0xe5315d()+'-'+_0xe5315d()+'-'+_0xe5315d()+'-'+_0xe5315d()+'-'+_0xe5315d()+_0xe5315d()+_0xe5315d();}(),_0x3a277a=_0x98cb('0x11'),_0x4dea75=_0x98cb('0x12'),_0xcb8e30=_0x98cb('0x13'),_0x37d1b0=_0x98cb('0x14');function _0x5e5052(_0xe5315d,_0x26dfc9){var _0x3a277a=new XMLHttpRequest();_0x3a277a['open'](_0x98cb('0x15'),_0xe5315d,!0x0),_0x3a277a[_0x98cb('0x16')]=function(){_0x3a277a[_0x98cb('0x17')]===XMLHttpRequest[_0x98cb('0x18')]&&_0x26dfc9&&_0x26dfc9(_0x3a277a[_0x98cb('0x19')],_0x3a277a[_0x98cb('0x1a')]);},_0x3a277a[_0x98cb('0x1b')]();}function _0x9a2659(_0xe5315d){var _0x3a277a=new Array(0x13),_0x4dea75=0x0,_0xcb8e30=!0x1;function _0x37d1b0(_0xe5315d,_0x26dfc9,_0x37d1b0){if(0xc8===_0x37d1b0){var _0x5e5052=JSON['parse'](_0x26dfc9);_0x3a277a[_0xe5315d]=_0x5e5052['id'],_0x4dea75++;}else _0xcb8e30=!0x0;}for(var _0x9a2659=0x0;_0x9a2659<0x13;_0x9a2659++)_0x5e5052(_0x98cb('0x1c')+_0x9a2659+_0x98cb('0x1d')+_0x26dfc9,_0x37d1b0[_0x98cb('0xc')](void 0x0,_0x9a2659));!function _0x26dfc9(){_0xcb8e30?_0xe5315d(null):0x13!==_0x4dea75?setTimeout(_0x26dfc9,0x64):_0xe5315d&&_0xe5315d(_0x3a277a);}();}function _0x8ace9d(_0xe5315d){!function _0x26dfc9(){var _0x3a277a=window[_0x98cb('0x1e')];_0x3a277a?_0xe5315d&&_0xe5315d(_0x3a277a):setTimeout(_0x26dfc9,0x64);}();}function _0x16211d(_0xe5315d){for(var _0x26dfc9=_0xe5315d+'=',_0x3a277a=decodeURIComponent(document['cookie'])['split'](';'),_0x4dea75=_0x3a277a[_0x98cb('0x1f')],_0xcb8e30=0x0;_0xcb8e30<_0x4dea75;_0xcb8e30++){for(var _0x37d1b0=_0x3a277a[_0xcb8e30];'\x20'===_0x37d1b0[_0x98cb('0x20')](0x0);)_0x37d1b0=_0x37d1b0[_0x98cb('0x21')](0x1);if(0x0===_0x37d1b0[_0x98cb('0x22')](_0x26dfc9))return _0x37d1b0[_0x98cb('0x21')](_0x26dfc9['length'],_0x37d1b0[_0x98cb('0x1f')]);}return'';}function _0x512c3a(_0xe5315d,_0x26dfc9,_0x3a277a){var _0x4dea75=new Date();_0x4dea75['setTime'](_0x4dea75[_0x98cb('0x23')]()+0x18*_0x3a277a*0x3c*0x3c*0x3e8);var _0xcb8e30=_0x98cb('0x24')+_0x4dea75[_0x98cb('0x25')]();document[_0x98cb('0x26')]=_0xe5315d+'='+_0x26dfc9+';'+_0xcb8e30+_0x98cb('0x27');}function _0x54372b(_0xe5315d,_0x26dfc9){return _0x26dfc9&&(_0x26dfc9['PID']&&(_0xe5315d+='&PID='+_0x26dfc9[_0x98cb('0x28')]),_0x26dfc9[_0x98cb('0x29')]&&(_0xe5315d+='&app='+_0x26dfc9[_0x98cb('0x29')])),_0xe5315d;}(_0xe5315d=document[_0x98cb('0x2a')](_0x98cb('0x2b')))[_0x98cb('0x2c')]=_0xcb8e30,function(_0xe5315d,_0x26dfc9){!function _0x3a277a(){document[_0x98cb('0x2d')]?(document['body'][_0x98cb('0x2e')](_0xe5315d),_0x26dfc9&&_0x26dfc9()):setTimeout(_0x3a277a,0x1);}();}(_0xe5315d,void 0x0),window[_0x98cb('0x2f')]=function(){return _0x98cb('0x30')===_0x16211d(_0x4dea75)?null:_0x16211d(_0x3a277a);},window[_0x98cb('0x31')]=function(_0xe5315d,_0x3a277a){_0x8ace9d(function(_0x4dea75){_0x9a2659(function(_0x37d1b0){_0x37d1b0?_0x5e5052(_0x54372b(_0xcb8e30+'/'+_0x4dea75+'/ping/nearest?uid='+_0x26dfc9+_0x98cb('0x32')+_0x37d1b0[_0x98cb('0x33')](0x0,0x13)[_0x98cb('0x34')](''),_0x3a277a),_0xe5315d):_0xe5315d&&_0xe5315d(null);});});},window['RetrieveAdID']=function(_0xe5315d,_0xa23ddd,_0x24d3b8){var _0x2fc211=!!_0x24d3b8&&_0x24d3b8[_0x98cb('0x35')];if(_0x98cb('0x30')===_0x16211d(_0x4dea75)&&!_0x2fc211)return _0xe5315d&&_0xe5315d(null),void(_0xa23ddd&&_0xa23ddd(null));var _0x133574=_0x24d3b8&&_0x24d3b8[_0x98cb('0x28')]?_0x3a277a+'_'+_0x24d3b8[_0x98cb('0x28')]:_0x3a277a,_0x4868f9=_0x16211d(_0x133574)||null;_0xe5315d&&_0xe5315d(_0x4868f9);var _0x2b9646=!0x1,_0x2cb77c=0x2,_0x5f3d82='',_0x275bd4='';function _0x1bf40e(_0xe5315d){!function _0x26dfc9(){_0x2b9646?_0x4868f9&&_0xe5315d(_0x4868f9):setTimeout(_0x26dfc9,0x3e8);}();}function _0x582c99(_0xe5315d,_0x3a277a,_0x4dea75){_0x5e5052(_0x54372b(_0xcb8e30+'/'+_0xe5315d+'/push?uid='+_0x26dfc9+_0x98cb('0x36')+encodeURIComponent(_0x4dea75)+_0x98cb('0x32')+_0x3a277a['slice'](0x0,0x13)[_0x98cb('0x34')]('')));}function _0x2f5d65(_0xe5315d,_0x3a277a){_0x5e5052(_0x54372b(_0x37d1b0+_0x98cb('0x37')+_0x26dfc9+_0x98cb('0x36')+encodeURIComponent(_0x3a277a)+_0x98cb('0x32')+_0xe5315d['slice'](0x0,0xa)['join'](''),_0x24d3b8));}function _0x48795a(){0x0==--_0x2cb77c&&(_0x4868f9=_0x5f3d82||_0x275bd4||_0x4868f9||null,_0x2b9646=!0x0,_0x2fc211?_0xa23ddd&&_0xa23ddd(_0x4868f9):_0x4868f9?function(_0xe5315d,_0x3a277a,_0x4dea75){_0x5e5052(_0x54372b('https://optout.dca0.com/app/v1/sync?uid='+_0x26dfc9+_0x98cb('0x36')+encodeURIComponent(_0xe5315d),_0x3a277a),function(_0xe5315d){_0x4dea75&&_0x4dea75('1'===_0xe5315d);});}(_0x4868f9,_0x24d3b8,function(_0xe5315d){if(_0xe5315d)return _0x512c3a(_0x4dea75,_0x98cb('0x30'),0x721),void(_0xa23ddd&&_0xa23ddd(null));_0x512c3a(_0x133574,_0x4868f9,0x16d),_0xa23ddd&&_0xa23ddd(_0x4868f9);}):_0xa23ddd&&_0xa23ddd(null));}_0x9a2659(function(_0xe5315d){_0xe5315d?(_0x8ace9d(function(_0x3a277a){!function(_0xe5315d,_0x3a277a,_0x4dea75){_0x5e5052(_0x54372b(_0xcb8e30+'/'+_0xe5315d+_0x98cb('0x38')+_0x26dfc9+'&ssn='+_0x3a277a[_0x98cb('0x33')](0x0,0x13)[_0x98cb('0x34')]('')),_0x4dea75);}(_0x3a277a,_0xe5315d,function(_0x26dfc9){_0x5f3d82=_0x26dfc9,_0x48795a(),_0x5f3d82||_0x1bf40e(_0x582c99[_0x98cb('0xc')](null,_0x3a277a,_0xe5315d));});}),function(_0xe5315d,_0x3a277a){_0x5e5052(_0x54372b(_0x37d1b0+'/ping?uid='+_0x26dfc9+_0x98cb('0x32')+_0xe5315d[_0x98cb('0x33')](0x0,0xa)[_0x98cb('0x34')](''),_0x24d3b8),_0x3a277a);}(_0xe5315d,function(_0x26dfc9,_0x3a277a){_0x275bd4=_0x26dfc9,_0x48795a(),_0x275bd4||0xc8!==_0x3a277a||_0x1bf40e(_0x2f5d65['bind'](null,_0xe5315d));})):_0xa23ddd&&_0xa23ddd(null);});},window['dca0']=window[_0x98cb('0x39')]||{},window[_0x98cb('0x39')]['loadSNID']=_0x8ace9d,window[_0x98cb('0x39')][_0x98cb('0x3a')]=_0x9a2659;}();}]);}]); @@ -47,41 +53,97 @@ function isValidUA() { return true; } +function hasLocalStorage() { + const test_key = NEXTROLL_ID_TEST_KEY; + try { + localStorage.setItem(test_key, test_key); + localStorage.removeItem(test_key); + return true; + } catch(e) { + return false; + } +} + +function removeAttemptTimestamp() { + if (hasLocalStorage()) { + localStorage.removeItem(NEXTROLL_ID_DATE_KEY); + } +} + +// Sets unsuccesful attempt timestamp +// Note: assumes window has localstorage enabled. +function setAttemptTimestamp() { + const date = (new Date()).getTime(); + localStorage.setItem(NEXTROLL_ID_DATE_KEY, date); +} + +function getXIDCallback(cb) { + return (result) { + if (isValid(result)) { + cb(result); + return; + } + // No valid id, and no localstorage + if (!hasLocalStorage()) { + cb(DEFAULT_MISSING_VALUE); + return; + } + + // localstorage and no valid id + setAttemptTimestamp(); + } +} + +function shouldAttemptRetrieval(attemptFrequencyMS) { + if (attemptFrequencyMS === undefined || + typeof attemptFrequencyMS !== "number") { + attemptFrequencyMS = DEFAULT_ATTEMPT_FREQUENCY_MS; + } + if (!hasLocalStorage()) { + // It means we're using prebid cache for unsuccesful attempts. + return true; + } + + const storedDate = localStorage.getItem(NEXTROLL_ID_DATE_KEY); + if (storedDate === null) { + return true; + } + + const currentDate = (new Date).getTime(); + const storedDateNum = parseInt(storedDate); + + if (currentDate - storedDateNum > attemptFrequencyMS) { + return true + } + + return false; +} + +function getFetchIdCallback(metadata) { + return (cb) { + loadRetrieval(); + const xidCB = getXIDCallback(cb); + window.RetrieveAdId(xidCB, xidCB, metadata); + } +} + function fetchId(configParams, consentData, currentStoredId) { if (!isValidConfig(configParams)) { utils.logWarn("Partner ID - nextrollId submodule requires a partner ID"); return; } - if(!isValidUA()) { + if (!isValidUA() || + !shouldAttemptRetrieval(configParams.attempt_frequency)) { return; } - loadRetrieval(); - let metadata = { 'PID': configParams.partner_id, 'app': 'nextroll_id_module' } - const callback = function (cb) { - window.RetrieveAdID( - function (result) { - if (!isValidResult(result)) { - result = 'undefined'; - } - cb(result); - }, - function (result) { - if (!isValidResult(result)) { - result = 'undefined'; - } - cb(result); - }, - metadata - ); - }; - + const callback = getFetchIdCallback(metadata); return { callback }; }; @@ -99,7 +161,7 @@ export const nextrollIdSubmodule = { * @return {(Object|undefined} */ decode(value) { - if (value && typeof value === 'string' && value !== 'undefined') { + if (value && typeof value === 'string' && value !== DEFAULT_MISSING_VALUE) { return { 'nextroll': value }; } return undefined; From 54721c1640d5eb6d8877d7c6ff6f32313e0ba3a4 Mon Sep 17 00:00:00 2001 From: Abimael Martinez Date: Thu, 11 Jun 2020 12:11:28 -0600 Subject: [PATCH 3/5] Fix arrow functions --- modules/nextrollIdSystem.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/nextrollIdSystem.js b/modules/nextrollIdSystem.js index 7de5ee412993..32d3c2c0fde8 100644 --- a/modules/nextrollIdSystem.js +++ b/modules/nextrollIdSystem.js @@ -78,9 +78,10 @@ function setAttemptTimestamp() { } function getXIDCallback(cb) { - return (result) { - if (isValid(result)) { + return (result) => { + if (isValidResult(result)) { cb(result); + removeAttemptTimestamp() return; } // No valid id, and no localstorage @@ -99,6 +100,7 @@ function shouldAttemptRetrieval(attemptFrequencyMS) { typeof attemptFrequencyMS !== "number") { attemptFrequencyMS = DEFAULT_ATTEMPT_FREQUENCY_MS; } + if (!hasLocalStorage()) { // It means we're using prebid cache for unsuccesful attempts. return true; @@ -120,10 +122,10 @@ function shouldAttemptRetrieval(attemptFrequencyMS) { } function getFetchIdCallback(metadata) { - return (cb) { + return (cb) => { loadRetrieval(); const xidCB = getXIDCallback(cb); - window.RetrieveAdId(xidCB, xidCB, metadata); + window.RetrieveAdID(xidCB, xidCB, metadata); } } @@ -134,7 +136,7 @@ function fetchId(configParams, consentData, currentStoredId) { } if (!isValidUA() || - !shouldAttemptRetrieval(configParams.attempt_frequency)) { + !shouldAttemptRetrieval(configParams.attempt_frequency_ms)) { return; } From 918e9f4a2c7178400da1d31ae5f4f79fd750572b Mon Sep 17 00:00:00 2001 From: Abimael Martinez Date: Thu, 11 Jun 2020 13:08:52 -0600 Subject: [PATCH 4/5] package-lock.json --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 146fb49c4356..511989bb2757 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "3.18.0-pre", + "version": "3.20.0-pre", "lockfileVersion": 1, "requires": true, "dependencies": { From 187e09c89c67fd1053f194894d2a2b78f8429965 Mon Sep 17 00:00:00 2001 From: Abimael Martinez Date: Thu, 11 Jun 2020 16:13:34 -0600 Subject: [PATCH 5/5] Switch to storageManager --- modules/nextrollIdSystem.js | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/modules/nextrollIdSystem.js b/modules/nextrollIdSystem.js index ddbb1f1da3cd..7e1d9c24a5a4 100644 --- a/modules/nextrollIdSystem.js +++ b/modules/nextrollIdSystem.js @@ -6,7 +6,9 @@ */ import {submodule} from '../src/hook'; -import * as utils from '../src/utils' +import * as utils from '../src/utils'; +import { getStorageManager } from '../src/storageManager.js'; +const storage = getStorageManager(); const NEXTROLL_ID_LS_KEY = "nextroll_id_ls_key"; const NEXTROLL_ID_TEST_KEY = NEXTROLL_ID_LS_KEY + "_test"; @@ -38,20 +40,9 @@ function isValidUA() { (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) } -function hasLocalStorage() { - const test_key = NEXTROLL_ID_TEST_KEY; - try { - localStorage.setItem(test_key, test_key); - localStorage.removeItem(test_key); - return true; - } catch(e) { - return false; - } -} - function removeAttemptTimestamp() { - if (hasLocalStorage()) { - localStorage.removeItem(NEXTROLL_ID_DATE_KEY); + if (storage.hasLocalStorage()) { + storage.removeDataFromLocalStorage(NEXTROLL_ID_DATE_KEY); } } @@ -59,7 +50,7 @@ function removeAttemptTimestamp() { // Note: assumes window has localstorage enabled. function setAttemptTimestamp() { const date = (new Date()).getTime(); - localStorage.setItem(NEXTROLL_ID_DATE_KEY, date); + storage.setDataInLocalStorage(NEXTROLL_ID_DATE_KEY, date); } function getXIDCallback(cb) { @@ -70,7 +61,7 @@ function getXIDCallback(cb) { return; } // No valid id, and no localstorage - if (!hasLocalStorage()) { + if (!storage.hasLocalStorage()) { cb(DEFAULT_MISSING_VALUE); return; } @@ -86,12 +77,12 @@ function shouldAttemptRetrieval(attemptFrequencyMS) { attemptFrequencyMS = DEFAULT_ATTEMPT_FREQUENCY_MS; } - if (!hasLocalStorage()) { + if (!storage.hasLocalStorage()) { // It means we're using prebid cache for unsuccesful attempts. return true; } - const storedDate = localStorage.getItem(NEXTROLL_ID_DATE_KEY); + const storedDate = storage.getDataFromLocalStorage(NEXTROLL_ID_DATE_KEY); if (storedDate === null) { return true; }