1
1
import * as utils from 'src/utils' ;
2
- import { registerBidder } from 'src/adapters/bidderFactory' ;
3
- import { config } from 'src/config' ;
4
- import { Renderer } from '../src/Renderer' ;
2
+ import { registerBidder } from 'src/adapters/bidderFactory' ;
3
+ import { config } from 'src/config' ;
4
+ import { Renderer } from '../src/Renderer' ;
5
5
6
- function getTopFrame ( ) {
7
- try {
8
- return window . top === window ? 1 : 0 ;
9
- } catch ( e ) {
6
+ export const helper = {
7
+
8
+ getTopFrame : function ( ) {
9
+ try {
10
+ return window . top === window ? 1 : 0 ;
11
+ } catch ( e ) {
12
+ }
10
13
return 0 ;
11
- }
12
- }
14
+ } ,
13
15
14
- function startsWith ( str , search ) {
15
- return str . substr ( 0 , search . length ) === search ;
16
- }
16
+ startsWith : function ( str , search ) {
17
+ return str . substr ( 0 , search . length ) === search ;
18
+ } ,
17
19
18
- function getTopWindowDomain ( ) {
19
- const url = utils . getTopWindowUrl ( ) ;
20
- const domainStart = url . indexOf ( '://' ) + '://' . length ;
21
- return url . substring ( domainStart , url . indexOf ( '/' , domainStart ) < 0 ? url . length : url . indexOf ( '/' , domainStart ) ) ;
22
- }
20
+ getTopWindowDomain : function ( url ) {
21
+ const domainStart = url . indexOf ( '://' ) + '://' . length ;
22
+ return url . substring ( domainStart , url . indexOf ( '/' , domainStart ) < 0 ? url . length : url . indexOf ( '/' , domainStart ) ) ;
23
+ } ,
23
24
24
- function getTopWindowReferer ( ) {
25
- try {
26
- return window . top . document . referrer ;
27
- } catch ( e ) {
28
- utils . logMessage ( 'Failed obtaining top window\'s referrer: ' , e ) ;
25
+ getTopWindowReferer : function ( ) {
29
26
try {
30
- return window . document . referrer ;
27
+ return window . top . document . referrer ;
31
28
} catch ( e ) {
32
- utils . logMessage ( 'Failed obtaining current window\'s referrer: ' , e ) ;
33
- return '' ;
29
+ utils . logMessage ( 'Failed obtaining top window\'s referrer: ' , e ) ;
30
+ try {
31
+ return window . document . referrer ;
32
+ } catch ( e ) {
33
+ utils . logMessage ( 'Failed obtaining current window\'s referrer: ' , e ) ;
34
+ }
34
35
}
36
+ return '' ;
35
37
}
36
38
}
37
39
38
40
export const spec = {
39
- code : 'gambid ' ,
40
- aliases : [ ] ,
41
- supportedMediaTypes : [ 'banner' , 'video' ] ,
41
+ code : 'gamoshi ' ,
42
+ aliases : [ 'gambid' , 'cleanmedia' ] ,
43
+ supportedMediaTypes : [ 'banner' , 'video' ] ,
42
44
43
- isBidRequestValid : function ( bid ) {
45
+ isBidRequestValid : function ( bid ) {
44
46
return ! ! bid . params . supplyPartnerId && typeof bid . params . supplyPartnerId === 'string' &&
45
- ( typeof bid . params [ 'rtbEndpoint' ] === 'undefined' || typeof bid . params [ 'rtbEndpoint' ] === 'string' ) &&
46
- ( typeof bid . params . bidfloor === 'undefined' || typeof bid . params . bidfloor === 'number' ) &&
47
- ( typeof bid . params [ 'adpos' ] === 'undefined' || typeof bid . params [ 'adpos' ] === 'number' ) &&
48
- ( typeof bid . params [ 'protocols' ] === 'undefined' || Array . isArray ( bid . params [ 'protocols' ] ) ) &&
49
- ( typeof bid . params . instl === 'undefined' || bid . params . instl === 0 || bid . params . instl === 1 ) ;
47
+ ( typeof bid . params [ 'rtbEndpoint' ] === 'undefined' || typeof bid . params [ 'rtbEndpoint' ] === 'string' ) &&
48
+ ( typeof bid . params . bidfloor === 'undefined' || typeof bid . params . bidfloor === 'number' ) &&
49
+ ( typeof bid . params [ 'adpos' ] === 'undefined' || typeof bid . params [ 'adpos' ] === 'number' ) &&
50
+ ( typeof bid . params [ 'protocols' ] === 'undefined' || Array . isArray ( bid . params [ 'protocols' ] ) ) &&
51
+ ( typeof bid . params . instl === 'undefined' || bid . params . instl === 0 || bid . params . instl === 1 ) ;
50
52
} ,
51
53
52
- buildRequests : function ( validBidRequests , bidderRequest ) {
54
+ buildRequests : function ( validBidRequests , bidderRequest ) {
53
55
return validBidRequests . map ( bidRequest => {
54
- const { adUnitCode, auctionId, mediaTypes, params, sizes, transactionId } = bidRequest ;
55
- const baseEndpoint = params [ 'rtbEndpoint' ] || 'https://rtb.gambid .io' ;
56
+ const { adUnitCode, auctionId, mediaTypes, params, sizes, transactionId} = bidRequest ;
57
+ const baseEndpoint = params [ 'rtbEndpoint' ] || 'https://rtb.gamoshi .io' ;
56
58
const rtbEndpoint = `${ baseEndpoint } /r/${ params . supplyPartnerId } /bidr?rformat=open_rtb&reqformat=rtb_json&bidder=prebid` + ( params . query ? '&' + params . query : '' ) ;
59
+ let referer = bidderRequest && bidderRequest . refererInfo && bidderRequest . refererInfo . referer ;
60
+ let url = config . getConfig ( 'pageUrl' ) || referer || utils . getTopWindowUrl ( ) ;
61
+
57
62
const rtbBidRequest = {
58
63
'id' : auctionId ,
59
64
'site' : {
60
- 'domain' : getTopWindowDomain ( ) ,
61
- 'page' : config . getConfig ( 'pageUrl' ) || utils . getTopWindowUrl ( ) ,
62
- 'ref' : getTopWindowReferer ( )
65
+ 'domain' : helper . getTopWindowDomain ( url ) ,
66
+ 'page' : url ,
67
+ 'ref' : helper . getTopWindowReferer ( )
63
68
} ,
64
69
'device' : {
65
70
'ua' : navigator . userAgent
@@ -80,33 +85,33 @@ export const spec = {
80
85
'tagid' : adUnitCode ,
81
86
'bidfloor' : params . bidfloor || 0 ,
82
87
'bidfloorcur' : 'USD' ,
83
- 'secure' : startsWith ( utils . getTopWindowUrl ( ) . toLowerCase ( ) , 'http://' ) ? 0 : 1
88
+ 'secure' : helper . startsWith ( utils . getTopWindowUrl ( ) . toLowerCase ( ) , 'http://' ) ? 0 : 1
84
89
} ;
85
90
86
91
if ( ! mediaTypes || mediaTypes . banner ) {
87
92
imp . banner = {
88
- w : sizes . length ? sizes [ 0 ] [ 0 ] : 300 ,
89
- h : sizes . length ? sizes [ 0 ] [ 1 ] : 250 ,
93
+ w : sizes . length ? sizes [ 0 ] [ 0 ] : 300 ,
94
+ h : sizes . length ? sizes [ 0 ] [ 1 ] : 250 ,
90
95
pos : params . pos || 0 ,
91
- topframe : getTopFrame ( )
96
+ topframe : helper . getTopFrame ( )
92
97
} ;
93
98
} else if ( mediaTypes . video ) {
94
99
imp . video = {
95
- w : sizes . length ? sizes [ 0 ] [ 0 ] : 300 ,
96
- h : sizes . length ? sizes [ 0 ] [ 1 ] : 250 ,
100
+ w : sizes . length ? sizes [ 0 ] [ 0 ] : 300 ,
101
+ h : sizes . length ? sizes [ 0 ] [ 1 ] : 250 ,
97
102
protocols : params . protocols || [ 1 , 2 , 3 , 4 , 5 , 6 ] ,
98
103
pos : params . pos || 0 ,
99
- topframe : getTopFrame ( )
104
+ topframe : helper . getTopFrame ( )
100
105
} ;
101
106
} else {
102
107
return ;
103
108
}
104
109
rtbBidRequest . imp . push ( imp ) ;
105
- return { method : 'POST' , url : rtbEndpoint , data : rtbBidRequest , bidRequest } ;
110
+ return { method : 'POST' , url : rtbEndpoint , data : rtbBidRequest , bidRequest} ;
106
111
} ) ;
107
112
} ,
108
113
109
- interpretResponse : function ( serverResponse , bidRequest ) {
114
+ interpretResponse : function ( serverResponse , bidRequest ) {
110
115
const response = serverResponse && serverResponse . body ;
111
116
if ( ! response ) {
112
117
utils . logError ( 'empty response' ) ;
@@ -127,7 +132,7 @@ export const spec = {
127
132
currency : bid . cur || response . cur
128
133
} ;
129
134
if ( ! bidRequest . bidRequest . mediaTypes || bidRequest . bidRequest . mediaTypes . banner ) {
130
- outBids . push ( Object . assign ( { } , outBid , { mediaType : 'banner' , ad : bid . adm } ) ) ;
135
+ outBids . push ( Object . assign ( { } , outBid , { mediaType : 'banner' , ad : bid . adm } ) ) ;
131
136
} else if ( bidRequest . bidRequest . mediaTypes . video ) {
132
137
const context = utils . deepAccess ( bidRequest . bidRequest , 'mediaTypes.video.context' ) ;
133
138
outBids . push ( Object . assign ( { } , outBid , {
@@ -141,27 +146,27 @@ export const spec = {
141
146
return outBids ;
142
147
} ,
143
148
144
- getUserSyncs : function ( syncOptions , serverResponses , gdprConsent ) {
149
+ getUserSyncs : function ( syncOptions , serverResponses , gdprConsent ) {
145
150
const syncs = [ ] ;
146
151
const gdprApplies = gdprConsent && ( typeof gdprConsent . gdprApplies === 'boolean' ) ? gdprConsent . gdprApplies : false ;
147
152
const suffix = gdprApplies ? 'gc=' + encodeURIComponent ( gdprConsent . consentString ) : 'gc=missing' ;
148
153
serverResponses . forEach ( resp => {
149
154
if ( resp . body ) {
150
155
const bidResponse = resp . body ;
151
- if ( bidResponse . ext && Array . isArray ( bidResponse . ext [ 'utrk' ] ) ) {
152
- bidResponse . ext [ 'utrk' ] . forEach ( pixel => {
156
+ if ( bidResponse . ext && Array . isArray ( bidResponse . ext [ 'utrk' ] ) ) {
157
+ bidResponse . ext [ 'utrk' ] . forEach ( pixel => {
153
158
const url = pixel . url + ( pixel . url . indexOf ( '?' ) > 0 ? '&' + suffix : '?' + suffix ) ;
154
- return syncs . push ( { type : pixel . type , url } ) ;
159
+ return syncs . push ( { type : pixel . type , url} ) ;
155
160
} ) ;
156
161
}
157
162
if ( Array . isArray ( bidResponse . seatbid ) ) {
158
163
bidResponse . seatbid . forEach ( seatBid => {
159
164
if ( Array . isArray ( seatBid . bid ) ) {
160
165
seatBid . bid . forEach ( bid => {
161
- if ( bid . ext && Array . isArray ( bid . ext [ 'utrk' ] ) ) {
162
- bid . ext [ 'utrk' ] . forEach ( pixel => {
166
+ if ( bid . ext && Array . isArray ( bid . ext [ 'utrk' ] ) ) {
167
+ bid . ext [ 'utrk' ] . forEach ( pixel => {
163
168
const url = pixel . url + ( pixel . url . indexOf ( '?' ) > 0 ? '&' + suffix : '?' + suffix ) ;
164
- return syncs . push ( { type : pixel . type , url } ) ;
169
+ return syncs . push ( { type : pixel . type , url} ) ;
165
170
} ) ;
166
171
}
167
172
} ) ;
0 commit comments