@@ -5,7 +5,9 @@ import {VIDEO} from '../src/mediaTypes';
5
5
import { STATUS } from '../src/constants' ;
6
6
7
7
const BIDDER_CODE = 'telaria' ;
8
- const ENDPOINT = '.ads.tremorhub.com/ad/tag' ;
8
+ const DOMAIN = 'tremorhub.com' ;
9
+ const TAG_ENDPOINT = `ads.${ DOMAIN } /ad/tag` ;
10
+ const EVENTS_ENDPOINT = `events.${ DOMAIN } /diag` ;
9
11
10
12
export const spec = {
11
13
code : BIDDER_CODE ,
@@ -82,7 +84,7 @@ export const spec = {
82
84
errorMessage += `: ${ bidResult . error } ` ;
83
85
}
84
86
utils . logError ( errorMessage ) ;
85
- } else if ( bidResult . seatbid && bidResult . seatbid . length > 0 ) {
87
+ } else if ( ! utils . isEmpty ( bidResult . seatbid ) ) {
86
88
bidResult . seatbid [ 0 ] . bid . forEach ( tag => {
87
89
bids . push ( createBid ( STATUS . GOOD , bidderRequest , tag , width , height , BIDDER_CODE ) ) ;
88
90
} ) ;
@@ -100,11 +102,89 @@ export const spec = {
100
102
getUserSyncs : function ( syncOptions , serverResponses ) {
101
103
const syncs = [ ] ;
102
104
if ( syncOptions . pixelEnabled && serverResponses . length ) {
103
- try {
104
- serverResponses [ 0 ] . body . ext . telaria . userSync . forEach ( url => syncs . push ( { type : 'image' , url : url } ) ) ;
105
- } catch ( e ) { }
105
+ ( utils . deepAccess ( serverResponses , '0.body.ext.telaria.userSync' ) || [ ] ) . forEach ( url => syncs . push ( { type : 'image' , url : url } ) ) ;
106
106
}
107
107
return syncs ;
108
+ } ,
109
+
110
+ /**
111
+ * See http://prebid.org/dev-docs/bidder-adaptor.html#registering-on-timeout for detailed semantic.
112
+ * @param timeoutData bidRequest
113
+ */
114
+ onTimeout : function ( timeoutData ) {
115
+ let url = getTimeoutUrl ( timeoutData ) ;
116
+ if ( url ) {
117
+ utils . triggerPixel ( url ) ;
118
+ }
119
+ }
120
+ } ;
121
+
122
+ function getScheme ( ) {
123
+ return ( ( document . location . protocol === 'https:' ) ? 'https' : 'http' ) + '://' ;
124
+ }
125
+
126
+ function getSrcPageUrl ( params ) {
127
+ return ( params && params [ 'srcPageUrl' ] ) || encodeURIComponent ( document . location . href ) ;
128
+ }
129
+
130
+ function getEncodedValIfNotEmpty ( val ) {
131
+ return ! utils . isEmpty ( val ) ? encodeURIComponent ( val ) : '' ;
132
+ }
133
+
134
+ /**
135
+ * Converts the schain object to a url param value. Please refer to
136
+ * https://github.com/InteractiveAdvertisingBureau/openrtb/blob/master/supplychainobject.md
137
+ * (schain for non ORTB section) for more information
138
+ * @param schainObject
139
+ * @returns {string }
140
+ */
141
+ function getSupplyChainAsUrlParam ( schainObject ) {
142
+ if ( utils . isEmpty ( schainObject ) ) {
143
+ return '' ;
144
+ }
145
+
146
+ let scStr = `&schain=${ schainObject . ver } ,${ schainObject . complete } ` ;
147
+
148
+ schainObject . nodes . forEach ( ( node ) => {
149
+ scStr += '!' ;
150
+ scStr += `${ getEncodedValIfNotEmpty ( node . asi ) } ,` ;
151
+ scStr += `${ getEncodedValIfNotEmpty ( node . sid ) } ,` ;
152
+ scStr += `${ getEncodedValIfNotEmpty ( node . hp ) } ,` ;
153
+ scStr += `${ getEncodedValIfNotEmpty ( node . rid ) } ,` ;
154
+ scStr += `${ getEncodedValIfNotEmpty ( node . name ) } ,` ;
155
+ scStr += `${ getEncodedValIfNotEmpty ( node . domain ) } ` ;
156
+ } ) ;
157
+
158
+ return scStr ;
159
+ }
160
+
161
+ function getUrlParams ( params ) {
162
+ let urlSuffix = '' ;
163
+
164
+ if ( ! utils . isEmpty ( params ) ) {
165
+ for ( let key in params ) {
166
+ if ( key !== 'schain' && params . hasOwnProperty ( key ) && ! utils . isEmpty ( params [ key ] ) ) {
167
+ urlSuffix += `&${ key } =${ params [ key ] } ` ;
168
+ }
169
+ }
170
+ urlSuffix += getSupplyChainAsUrlParam ( params [ 'schain' ] ) ;
171
+ }
172
+
173
+ return urlSuffix ;
174
+ }
175
+
176
+ export const getTimeoutUrl = function ( timeoutData ) {
177
+ let params = utils . deepAccess ( timeoutData , '0.params.0' ) ;
178
+
179
+ if ( ! utils . isEmpty ( params ) ) {
180
+ let url = `${ getScheme ( ) } ${ EVENTS_ENDPOINT } ` ;
181
+
182
+ url += `?srcPageUrl=${ getSrcPageUrl ( params ) } ` ;
183
+ url += `${ getUrlParams ( params ) } ` ;
184
+
185
+ url += '&hb=1&evt=TO' ;
186
+
187
+ return url ;
108
188
}
109
189
} ;
110
190
@@ -116,9 +196,9 @@ export const spec = {
116
196
* @returns {string }
117
197
*/
118
198
function generateUrl ( bid , bidderRequest ) {
119
- let playerSize = ( bid . mediaTypes && bid . mediaTypes . video && bid . mediaTypes . video . playerSize ) ;
199
+ let playerSize = utils . deepAccess ( bid , ' mediaTypes.video. playerSize' ) ;
120
200
if ( ! playerSize ) {
121
- utils . logWarn ( ' Although player size isn\ 't required it is highly recommended' ) ;
201
+ utils . logWarn ( ` Although player size isn't required it is highly recommended` ) ;
122
202
}
123
203
124
204
let width , height ;
@@ -132,45 +212,41 @@ function generateUrl(bid, bidderRequest) {
132
212
}
133
213
}
134
214
135
- if ( bid . params . supplyCode && bid . params . adCode ) {
136
- let scheme = ( ( document . location . protocol === 'https:' ) ? 'https' : 'http' ) + '://' ;
137
- let url = scheme + bid . params . supplyCode + ENDPOINT + '?adCode=' + bid . params . adCode ;
215
+ let supplyCode = utils . deepAccess ( bid , 'params.supplyCode' ) ;
216
+ let adCode = utils . deepAccess ( bid , 'params.adCode' ) ;
217
+
218
+ if ( supplyCode && adCode ) {
219
+ let url = `${ getScheme ( ) } ${ supplyCode } .${ TAG_ENDPOINT } ?adCode=${ adCode } ` ;
138
220
139
221
if ( width ) {
140
- url += ( ' &playerWidth=' + width ) ;
222
+ url += ( ` &playerWidth=${ width } ` ) ;
141
223
}
142
224
if ( height ) {
143
- url += ( ' &playerHeight=' + height ) ;
225
+ url += ( ` &playerHeight=${ height } ` ) ;
144
226
}
145
227
146
- for ( let key in bid . params ) {
147
- if ( bid . params . hasOwnProperty ( key ) && bid . params [ key ] ) {
148
- url += ( '&' + key + '=' + bid . params [ key ] ) ;
149
- }
150
- }
228
+ url += `${ getUrlParams ( bid . params ) } ` ;
151
229
152
- if ( ! bid . params [ 'srcPageUrl' ] ) {
153
- url += ( '&srcPageUrl=' + encodeURIComponent ( document . location . href ) ) ;
154
- }
230
+ url += `&srcPageUrl=${ getSrcPageUrl ( bid . params ) } ` ;
155
231
156
- url += ( ' &transactionId=' + bid . transactionId + '&hb=1' ) ;
232
+ url += ( ` &transactionId=${ bid . transactionId } ` ) ;
157
233
158
234
if ( bidderRequest ) {
159
235
if ( bidderRequest . gdprConsent ) {
160
236
if ( typeof bidderRequest . gdprConsent . gdprApplies === 'boolean' ) {
161
- url += ( ' &gdpr=' + ( bidderRequest . gdprConsent . gdprApplies ? 1 : 0 ) ) ;
237
+ url += ( ` &gdpr=${ ( bidderRequest . gdprConsent . gdprApplies ? 1 : 0 ) } ` ) ;
162
238
}
163
239
if ( bidderRequest . gdprConsent . consentString ) {
164
- url += ( ' &gdpr_consent=' + bidderRequest . gdprConsent . consentString ) ;
240
+ url += ( ` &gdpr_consent=${ bidderRequest . gdprConsent . consentString } ` ) ;
165
241
}
166
242
}
167
243
168
244
if ( bidderRequest . refererInfo && bidderRequest . refererInfo . referer ) {
169
- url += ( ' &referrer=' + encodeURIComponent ( bidderRequest . refererInfo . referer ) ) ;
245
+ url += ( ` &referrer=${ encodeURIComponent ( bidderRequest . refererInfo . referer ) } ` ) ;
170
246
}
171
247
}
172
248
173
- return ( url + '&fmt=json' ) ;
249
+ return ( url + '&hb=1& fmt=json' ) ;
174
250
}
175
251
}
176
252
0 commit comments