1
1
import { registerBidder } from '../src/adapters/bidderFactory.js' ;
2
2
import { BANNER , VIDEO } from '../src/mediaTypes.js' ;
3
- import { Renderer } from '../src/Renderer.js' ;
4
- import { getWindowFromDocument , logWarn } from '../src/utils.js' ;
5
3
6
- const ADAPTER_VERSION = '1.1 .0' ;
4
+ const BIDDER_VERSION = '1.0 .0' ;
7
5
const BIDDER_CODE = 'displayio' ;
6
+ const GVLID = 999 ;
8
7
const BID_TTL = 300 ;
9
8
const SUPPORTED_AD_TYPES = [ BANNER , VIDEO ] ;
10
9
const DEFAULT_CURRENCY = 'USD' ;
11
10
12
11
export const spec = {
13
12
code : BIDDER_CODE ,
13
+ gvlid : GVLID ,
14
14
supportedMediaTypes : SUPPORTED_AD_TYPES ,
15
15
isBidRequestValid : function ( bid ) {
16
16
return ! ! ( bid . params && bid . params . placementId && bid . params . siteId &&
@@ -20,7 +20,7 @@ export const spec = {
20
20
return bidRequests . map ( bid => {
21
21
let url = '//' + bid . params . adsSrvDomain + '/srv?method=getPlacement&app=' +
22
22
bid . params . siteId + '&placement=' + bid . params . placementId ;
23
- const data = getPayload ( bid , bidderRequest ) ;
23
+ const data = this . _getPayload ( bid , bidderRequest ) ;
24
24
return {
25
25
method : 'POST' ,
26
26
headers : { 'Content-Type' : 'application/json;charset=utf-8' } ,
@@ -42,112 +42,117 @@ export const spec = {
42
42
height : adData . h ,
43
43
netRevenue : true ,
44
44
ttl : BID_TTL ,
45
- creativeId : adData . adId || 1 ,
46
- currency : adData . cur || DEFAULT_CURRENCY ,
45
+ creativeId : adData . adId || 0 ,
46
+ currency : DEFAULT_CURRENCY ,
47
47
referrer : data . data . ref ,
48
- mediaType : ads [ 0 ] . ad . subtype === 'videoVast' ? VIDEO : BANNER ,
48
+ mediaType : ads [ 0 ] . ad . subtype ,
49
49
ad : adData . markup ,
50
- adUnitCode : data . adUnitCode ,
51
- renderURL : data . renderURL ,
50
+ placement : data . placement ,
52
51
adData : adData
53
52
} ;
54
-
55
- if ( bidResponse . mediaType === VIDEO ) {
56
- bidResponse . vastUrl = adData . videos [ 0 ] && adData . videos [ 0 ] . url
57
- }
58
-
59
- if ( bidResponse . renderURL ) {
60
- bidResponse . renderer = newRenderer ( bidResponse ) ;
53
+ if ( bidResponse . vastUrl === 'videoVast' ) {
54
+ bidResponse . vastUrl = adData . videos [ 0 ] . url
61
55
}
62
56
bidResponses . push ( bidResponse ) ;
63
57
}
64
58
return bidResponses ;
65
- }
66
- } ;
67
-
68
- function getPayload ( bid , bidderRequest ) {
69
- const connection = navigator . connection || navigator . mozConnection || navigator . webkitConnection ;
70
- const userSession = 'us_web_xxxxxxxxxxxx' . replace ( / [ x ] / g, c => {
71
- let r = Math . random ( ) * 16 | 0 ;
72
- let v = c === 'x' ? r : ( r & 0x3 | 0x8 ) ;
73
- return v . toString ( 16 ) ;
74
- } ) ;
75
- const { params, adUnitCode, bidId } = bid ;
76
- const { siteId, placementId, renderURL, pageCategory, keywords } = params ;
77
- const { refererInfo, uspConsent, gdprConsent } = bidderRequest ;
78
- const mediation = { consent : '-1' , gdpr : '-1' } ;
79
- if ( gdprConsent && 'gdprApplies' in gdprConsent ) {
80
- if ( gdprConsent . consentString !== undefined ) {
81
- mediation . consent = gdprConsent . consentString ;
82
- }
83
- if ( gdprConsent . gdprApplies !== undefined ) {
84
- mediation . gdpr = gdprConsent . gdprApplies ? '1' : '0' ;
59
+ } ,
60
+ _getPayload : function ( bid , bidderRequest ) {
61
+ const connection = navigator . connection || navigator . mozConnection || navigator . webkitConnection ;
62
+ const userSession = 'us_web_xxxxxxxxxxxx' . replace ( / [ x ] / g, c => {
63
+ let r = Math . random ( ) * 16 | 0 ;
64
+ let v = c === 'x' ? r : ( r & 0x3 | 0x8 ) ;
65
+ return v . toString ( 16 ) ;
66
+ } ) ;
67
+ const { params } = bid ;
68
+ const { siteId, placementId } = params ;
69
+ const { refererInfo, uspConsent, gdprConsent } = bidderRequest ;
70
+ const mediation = { consent : '-1' , gdpr : '-1' } ;
71
+ if ( gdprConsent ) {
72
+ if ( gdprConsent . consentString !== undefined ) {
73
+ mediation . consent = gdprConsent . consentString ;
74
+ }
75
+ if ( gdprConsent . gdprApplies !== undefined ) {
76
+ mediation . gdpr = gdprConsent . gdprApplies ? '1' : '0' ;
77
+ }
85
78
}
86
- }
87
- return {
88
- userSession,
89
- data : {
90
- id : bidId ,
91
- action : 'getPlacement' ,
92
- app : siteId ,
93
- placement : placementId ,
94
- adUnitCode,
95
- renderURL,
79
+ const payload = {
80
+ userSession,
96
81
data : {
97
- pagecat : pageCategory ? pageCategory . split ( ',' ) . map ( k => k . trim ( ) ) : [ ] ,
98
- keywords : keywords ? keywords . split ( ',' ) . map ( k => k . trim ( ) ) : [ ] ,
99
- lang_content : document . documentElement . lang ,
100
- lang : window . navigator . language ,
101
- domain : refererInfo . domain ,
102
- page : refererInfo . page ,
103
- ref : refererInfo . referer ,
104
- userids : bid . userIdAsEids || { } ,
105
- geo : '' ,
106
- } ,
107
- complianceData : {
108
- child : '-1' ,
109
- us_privacy : uspConsent ,
110
- dnt : window . doNotTrack === '1' || window . navigator . doNotTrack === '1' || false ,
111
- iabConsent : { } ,
112
- mediation : {
113
- consent : mediation . consent ,
114
- gdpr : mediation . gdpr ,
82
+ id : bid . bidId ,
83
+ action : 'getPlacement' ,
84
+ app : siteId ,
85
+ placement : placementId ,
86
+ data : {
87
+ pagecat : params . pageCategory ? params . pageCategory . split ( ',' ) . map ( k => k . trim ( ) ) : [ ] ,
88
+ keywords : params . keywords ? params . keywords . split ( ',' ) . map ( k => k . trim ( ) ) : [ ] ,
89
+ lang_content : document . documentElement . lang ,
90
+ lang : window . navigator . language ,
91
+ // TODO: are these the correct refererInfo values?
92
+ domain : refererInfo . domain ,
93
+ page : refererInfo . page ,
94
+ ref : refererInfo . ref ,
95
+ userids : _getUserIDs ( ) ,
96
+ geo : '' ,
97
+ } ,
98
+ complianceData : {
99
+ child : '-1' ,
100
+ us_privacy : uspConsent ,
101
+ dnt : window . navigator . doNotTrack ,
102
+ iabConsent : { } ,
103
+ mediation : {
104
+ consent : mediation . consent ,
105
+ gdpr : mediation . gdpr ,
106
+ }
107
+ } ,
108
+ integration : 'JS' ,
109
+ omidpn : 'Displayio' ,
110
+ mediationPlatform : 0 ,
111
+ prebidVersion : BIDDER_VERSION ,
112
+ device : {
113
+ w : window . screen . width ,
114
+ h : window . screen . height ,
115
+ connection_type : connection ? connection . effectiveType : '' ,
115
116
}
116
- } ,
117
- integration : 'JS' ,
118
- omidpn : 'Displayio' ,
119
- mediationPlatform : 0 ,
120
- prebidVersion : ADAPTER_VERSION ,
121
- device : {
122
- w : window . screen . width ,
123
- h : window . screen . height ,
124
- connection_type : connection ? connection . effectiveType : '' ,
125
117
}
126
118
}
119
+ if ( navigator . permissions ) {
120
+ navigator . permissions . query ( { name : 'geolocation' } )
121
+ . then ( ( result ) => {
122
+ if ( result . state === 'granted' ) {
123
+ payload . data . data . geo = _getGeoData ( ) ;
124
+ }
125
+ } ) ;
126
+ }
127
+ return payload
127
128
}
128
- }
129
-
130
- function newRenderer ( bid ) {
131
- const renderer = Renderer . install ( {
132
- id : bid . requestId ,
133
- url : bid . renderURL ,
134
- adUnitCode : bid . adUnitCode
135
- } ) ;
129
+ } ;
136
130
131
+ function _getUserIDs ( ) {
132
+ let ids = { } ;
137
133
try {
138
- renderer . setRender ( webisRender ) ;
139
- } catch ( err ) {
140
- logWarn ( 'Prebid Error calling setRender on renderer' , err ) ;
141
- }
142
-
143
- return renderer ;
134
+ ids = window . owpbjs . getUserIdsAsEids ( ) ;
135
+ } catch ( e ) { }
136
+ return ids ;
144
137
}
145
138
146
- function webisRender ( bid , doc ) {
147
- bid . renderer . push ( ( ) => {
148
- const win = getWindowFromDocument ( doc ) || window ;
149
- win . webis . init ( bid . adData , bid . adUnitCode , bid . params ) ;
150
- } )
139
+ async function _getGeoData ( ) {
140
+ let geoData = null ;
141
+ const getCurrentPosition = ( ) => {
142
+ return new Promise ( ( resolve , reject ) =>
143
+ navigator . geolocation . getCurrentPosition ( resolve , reject )
144
+ ) ;
145
+ }
146
+ try {
147
+ const position = await getCurrentPosition ( ) ;
148
+ let { latitude, longitude, accuracy} = position . coords ;
149
+ geoData = {
150
+ 'lat' : latitude ,
151
+ 'lng' : longitude ,
152
+ 'precision' : accuracy
153
+ } ;
154
+ } catch ( e ) { }
155
+ return geoData
151
156
}
152
157
153
158
registerBidder ( spec ) ;
0 commit comments