1
1
import { find } from '../src/polyfill.js' ;
2
2
import {
3
+ canAccessWindowTop ,
3
4
cleanObj ,
4
5
deepAccess ,
5
6
deepClone ,
@@ -8,17 +9,18 @@ import {
8
9
getUniqueIdentifierStr ,
9
10
getWindowSelf ,
10
11
getWindowTop ,
11
- inIframe ,
12
12
isArray ,
13
+ isArrayOfNums ,
13
14
isFn ,
15
+ inIframe ,
14
16
isInteger ,
15
17
isNumber ,
16
- isArrayOfNums ,
18
+ isSafeFrameWindow ,
19
+ isStr ,
17
20
logError ,
18
21
logInfo ,
19
22
logWarn ,
20
23
mergeDeep ,
21
- isStr ,
22
24
} from '../src/utils.js' ;
23
25
import { config } from '../src/config.js' ;
24
26
import { registerBidder } from '../src/adapters/bidderFactory.js' ;
@@ -104,13 +106,15 @@ export const GlobalExchange = (function() {
104
106
getOrSetGlobalFeatures : function ( ) {
105
107
if ( ! features ) {
106
108
features = {
109
+ type : 'bidAdapter' ,
107
110
page_dimensions : getPageDimensions ( ) . toString ( ) ,
108
111
viewport_dimensions : getViewPortDimensions ( ) . toString ( ) ,
109
112
user_timestamp : getTimestampUTC ( ) . toString ( ) ,
110
113
dom_loading : getDomLoadingDuration ( ) . toString ( ) ,
111
114
}
112
115
}
113
- return features ;
116
+
117
+ return { ...features } ;
114
118
} ,
115
119
116
120
prepareExchangeData ( storageValue ) {
@@ -130,7 +134,7 @@ export const GlobalExchange = (function() {
130
134
const data = {
131
135
session : {
132
136
new : newSession ,
133
- rnd : random
137
+ rnd : random ,
134
138
}
135
139
}
136
140
@@ -149,6 +153,9 @@ export const GlobalExchange = (function() {
149
153
} ;
150
154
} ) ( ) ;
151
155
156
+ /**
157
+ * @deprecated will be removed in Prebid.js 9.
158
+ */
152
159
export function adagioScriptFromLocalStorageCb ( ls ) {
153
160
try {
154
161
if ( ! ls ) {
@@ -179,6 +186,9 @@ export function adagioScriptFromLocalStorageCb(ls) {
179
186
}
180
187
}
181
188
189
+ /**
190
+ * @deprecated will be removed in Prebid.js 9.
191
+ */
182
192
export function getAdagioScript ( ) {
183
193
storage . getDataFromLocalStorage ( ADAGIO_LOCALSTORAGE_KEY , ( ls ) => {
184
194
internal . adagioScriptFromLocalStorageCb ( ls ) ;
@@ -204,31 +214,14 @@ export function getAdagioScript() {
204
214
} ) ;
205
215
}
206
216
207
- function canAccessTopWindow ( ) {
208
- try {
209
- if ( getWindowTop ( ) . location . href ) {
210
- return true ;
211
- }
212
- } catch ( error ) {
213
- return false ;
214
- }
215
- }
216
-
217
217
function getCurrentWindow ( ) {
218
218
return currentWindow || getWindowSelf ( ) ;
219
219
}
220
220
221
- function isSafeFrameWindow ( ) {
222
- const ws = getWindowSelf ( ) ;
223
- return ! ! ( ws . $sf && ws . $sf . ext ) ;
224
- }
225
-
226
221
function initAdagio ( ) {
227
- if ( canAccessTopWindow ( ) ) {
228
- currentWindow = ( canAccessTopWindow ( ) ) ? getWindowTop ( ) : getWindowSelf ( ) ;
229
- }
222
+ currentWindow = ( canAccessWindowTop ( ) ) ? getWindowTop ( ) : getWindowSelf ( ) ;
230
223
231
- const w = internal . getCurrentWindow ( ) ;
224
+ const w = currentWindow ;
232
225
233
226
w . ADAGIO = w . ADAGIO || { } ;
234
227
w . ADAGIO . adUnits = w . ADAGIO . adUnits || { } ;
@@ -240,13 +233,16 @@ function initAdagio() {
240
233
241
234
storage . getDataFromLocalStorage ( 'adagio' , ( storageData ) => {
242
235
try {
243
- GlobalExchange . prepareExchangeData ( storageData ) ;
236
+ if ( w . ADAGIO . hasRtd !== true ) {
237
+ logInfo ( `${ LOG_PREFIX } RTD module not found. Loading external script from adagioBidAdapter is deprecated and will be removed in Prebid.js 9.` ) ;
238
+
239
+ GlobalExchange . prepareExchangeData ( storageData ) ;
240
+ getAdagioScript ( ) ;
241
+ }
244
242
} catch ( e ) {
245
243
logError ( LOG_PREFIX , e ) ;
246
244
}
247
245
} ) ;
248
-
249
- getAdagioScript ( ) ;
250
246
}
251
247
252
248
function enqueue ( ob ) {
@@ -359,6 +355,12 @@ function setPlayerName(bidRequest) {
359
355
return playerName ;
360
356
}
361
357
358
+ function hasRtd ( ) {
359
+ const w = internal . getCurrentWindow ( ) ;
360
+
361
+ return ! ! ( w . ADAGIO && w . ADAGIO . hasRtd ) ;
362
+ } ;
363
+
362
364
export const internal = {
363
365
enqueue,
364
366
getPageviewId,
@@ -368,9 +370,10 @@ export const internal = {
368
370
getRefererInfo,
369
371
adagioScriptFromLocalStorageCb,
370
372
getCurrentWindow,
371
- canAccessTopWindow ,
373
+ canAccessWindowTop ,
372
374
isRendererPreferredFromPublisher,
373
- isNewSession
375
+ isNewSession,
376
+ hasRtd
374
377
} ;
375
378
376
379
function _getGdprConsent ( bidderRequest ) {
@@ -685,7 +688,7 @@ function autoFillParams(bid) {
685
688
}
686
689
687
690
function getPageDimensions ( ) {
688
- if ( isSafeFrameWindow ( ) || ! canAccessTopWindow ( ) ) {
691
+ if ( isSafeFrameWindow ( ) || ! canAccessWindowTop ( ) ) {
689
692
return '' ;
690
693
}
691
694
@@ -708,7 +711,7 @@ function getPageDimensions() {
708
711
* @returns
709
712
*/
710
713
function getViewPortDimensions ( ) {
711
- if ( ! isSafeFrameWindow ( ) && ! canAccessTopWindow ( ) ) {
714
+ if ( ! isSafeFrameWindow ( ) && ! canAccessWindowTop ( ) ) {
712
715
return '' ;
713
716
}
714
717
@@ -746,7 +749,7 @@ function getSlotPosition(adUnitElementId) {
746
749
return '' ;
747
750
}
748
751
749
- if ( ! isSafeFrameWindow ( ) && ! canAccessTopWindow ( ) ) {
752
+ if ( ! isSafeFrameWindow ( ) && ! canAccessWindowTop ( ) ) {
750
753
return '' ;
751
754
}
752
755
@@ -769,7 +772,7 @@ function getSlotPosition(adUnitElementId) {
769
772
770
773
position . x = Math . round ( sfGeom . t ) ;
771
774
position . y = Math . round ( sfGeom . l ) ;
772
- } else if ( canAccessTopWindow ( ) ) {
775
+ } else if ( canAccessWindowTop ( ) ) {
773
776
try {
774
777
// window.top based computing
775
778
const wt = getWindowTop ( ) ;
@@ -823,22 +826,14 @@ function getTimestampUTC() {
823
826
return Math . floor ( new Date ( ) . getTime ( ) / 1000 ) - new Date ( ) . getTimezoneOffset ( ) * 60 ;
824
827
}
825
828
826
- function getPrintNumber ( adUnitCode , bidderRequest ) {
827
- if ( ! bidderRequest . bids || ! bidderRequest . bids . length ) {
828
- return 1 ;
829
- }
830
- const adagioBid = find ( bidderRequest . bids , bid => bid . adUnitCode === adUnitCode ) ;
831
- return adagioBid . bidderRequestsCount || 1 ;
832
- }
833
-
834
829
/**
835
830
* domLoading feature is computed on window.top if reachable.
836
831
*/
837
832
function getDomLoadingDuration ( ) {
838
833
let domLoadingDuration = - 1 ;
839
834
let performance ;
840
835
841
- performance = ( canAccessTopWindow ( ) ) ? getWindowTop ( ) . performance : getWindowSelf ( ) . performance ;
836
+ performance = ( canAccessWindowTop ( ) ) ? getWindowTop ( ) . performance : getWindowSelf ( ) . performance ;
842
837
843
838
if ( performance && performance . timing && performance . timing . navigationStart > 0 ) {
844
839
const val = performance . timing . domLoading - performance . timing . navigationStart ;
@@ -958,6 +953,31 @@ const OUTSTREAM_RENDERER = {
958
953
}
959
954
} ;
960
955
956
+ /**
957
+ *
958
+ * @param {* } bidRequest
959
+ * @returns
960
+ */
961
+ const _getFeatures = ( bidRequest ) => {
962
+ const f = { ...deepAccess ( bidRequest , 'ortb2.ext.features' , GlobalExchange . getOrSetGlobalFeatures ( ) ) } || { } ;
963
+
964
+ f . print_number = deepAccess ( bidRequest , 'bidderRequestsCount' , 1 ) . toString ( ) ;
965
+
966
+ if ( f . type === 'bidAdapter' ) {
967
+ f . adunit_position = getSlotPosition ( bidRequest . params . adUnitElementId )
968
+ } else {
969
+ f . adunit_position = deepAccess ( bidRequest , 'ortb2Imp.ext.data.adunit_position' ) ;
970
+ }
971
+
972
+ Object . keys ( f ) . forEach ( ( prop ) => {
973
+ if ( f [ prop ] === '' ) {
974
+ delete f [ prop ] ;
975
+ }
976
+ } ) ;
977
+
978
+ return f ;
979
+ }
980
+
961
981
export const spec = {
962
982
code : BIDDER_CODE ,
963
983
gvlid : GVLID ,
@@ -986,6 +1006,7 @@ export const spec = {
986
1006
const device = internal . getDevice ( ) ;
987
1007
const site = internal . getSite ( bidderRequest ) ;
988
1008
const pageviewId = internal . getPageviewId ( ) ;
1009
+ const hasRtd = internal . hasRtd ( ) ;
989
1010
const gdprConsent = _getGdprConsent ( bidderRequest ) || { } ;
990
1011
const uspConsent = _getUspConsent ( bidderRequest ) || { } ;
991
1012
const coppa = _getCoppa ( ) ;
@@ -998,6 +1019,9 @@ export const spec = {
998
1019
// We don't validate the dsa object in adapter and let our server do it.
999
1020
const dsa = deepAccess ( bidderRequest , 'ortb2.regs.ext.dsa' ) ;
1000
1021
1022
+ let rtdSamplingSession = deepAccess ( bidderRequest , 'ortb2.ext.session' ) ;
1023
+ const dataExchange = ( rtdSamplingSession ) ? { session : rtdSamplingSession } : GlobalExchange . getExchangeData ( ) ;
1024
+
1001
1025
const aucId = generateUUID ( )
1002
1026
1003
1027
const adUnits = validBidRequests . map ( rawBidRequest => {
@@ -1006,13 +1030,6 @@ export const spec = {
1006
1030
// Fix https://github.com/prebid/Prebid.js/issues/9781
1007
1031
bidRequest . auctionId = aucId
1008
1032
1009
- const globalFeatures = GlobalExchange . getOrSetGlobalFeatures ( ) ;
1010
- const features = {
1011
- ...globalFeatures ,
1012
- print_number : getPrintNumber ( bidRequest . adUnitCode , bidderRequest ) . toString ( ) ,
1013
- adunit_position : getSlotPosition ( bidRequest . params . adUnitElementId ) // adUnitElementId à déplacer ???
1014
- } ;
1015
-
1016
1033
// Force the Split Keyword to be a String
1017
1034
if ( bidRequest . params . splitKeyword ) {
1018
1035
if ( isStr ( bidRequest . params . splitKeyword ) || isNumber ( bidRequest . params . splitKeyword ) ) {
@@ -1056,23 +1073,20 @@ export const spec = {
1056
1073
}
1057
1074
}
1058
1075
1059
- Object . keys ( features ) . forEach ( ( prop ) => {
1060
- if ( features [ prop ] === '' ) {
1061
- delete features [ prop ] ;
1062
- }
1063
- } ) ;
1064
-
1076
+ const features = _getFeatures ( bidRequest ) ;
1065
1077
bidRequest . features = features ;
1066
1078
1067
- internal . enqueue ( {
1068
- action : 'features' ,
1069
- ts : Date . now ( ) ,
1070
- data : {
1071
- features : bidRequest . features ,
1072
- params : bidRequest . params ,
1073
- adUnitCode : bidRequest . adUnitCode
1074
- }
1075
- } ) ;
1079
+ if ( ! hasRtd ) {
1080
+ internal . enqueue ( {
1081
+ action : 'features' ,
1082
+ ts : Date . now ( ) ,
1083
+ data : {
1084
+ features,
1085
+ params : { ...bidRequest . params } ,
1086
+ adUnitCode : bidRequest . adUnitCode
1087
+ }
1088
+ } ) ;
1089
+ }
1076
1090
1077
1091
// Handle priceFloors module
1078
1092
// We need to use `rawBidRequest` as param because:
@@ -1127,8 +1141,10 @@ export const spec = {
1127
1141
bidRequest . gpid = gpid ;
1128
1142
}
1129
1143
1130
- // store the whole bidRequest (adUnit) object in the ADAGIO namespace.
1131
- storeRequestInAdagioNS ( bidRequest ) ;
1144
+ if ( ! hasRtd ) {
1145
+ // store the whole bidRequest (adUnit) object in the ADAGIO namespace.
1146
+ storeRequestInAdagioNS ( bidRequest ) ;
1147
+ }
1132
1148
1133
1149
// Remove some params that are not needed on the server side.
1134
1150
delete bidRequest . params . siteId ;
@@ -1176,12 +1192,13 @@ export const spec = {
1176
1192
url : ENDPOINT ,
1177
1193
data : {
1178
1194
organizationId : organizationId ,
1195
+ hasRtd : hasRtd ? 1 : 0 ,
1179
1196
secure : secure ,
1180
1197
device : device ,
1181
1198
site : site ,
1182
1199
pageviewId : pageviewId ,
1183
1200
adUnits : groupedAdUnits [ organizationId ] ,
1184
- data : GlobalExchange . getExchangeData ( ) ,
1201
+ data : dataExchange ,
1185
1202
regs : {
1186
1203
gdpr : gdprConsent ,
1187
1204
coppa : coppa ,
0 commit comments