1
1
import { config } from '../src/config.js' ;
2
2
import { registerBidder } from '../src/adapters/bidderFactory.js' ;
3
3
import { BANNER } from '../src/mediaTypes.js' ;
4
- import { deepAccess , isArray , isFn , isPlainObject , inIframe , getDNT } from '../src/utils.js' ;
4
+ import { deepAccess , isArray , isFn , isPlainObject , inIframe , getDNT , generateUUID } from '../src/utils.js' ;
5
5
import { hasPurpose1Consent } from '../src/utils/gpdr.js' ;
6
6
import { getGlobal } from '../src/prebidGlobal.js' ;
7
+ import { getStorageManager } from '../src/storageManager.js' ;
7
8
8
9
const BIDDER_CODE = 'snigel' ;
9
10
const GVLID = 1076 ;
10
11
const DEFAULT_URL = 'https://adserv.snigelweb.com/bp/v1/prebid' ;
11
12
const DEFAULT_TTL = 60 ;
12
13
const DEFAULT_CURRENCIES = [ 'USD' ] ;
13
14
const FLOOR_MATCH_ALL_SIZES = '*' ;
15
+ const SESSION_ID_KEY = '_sn_session_pba' ;
14
16
15
17
const getConfig = config . getConfig ;
18
+ const storageManager = getStorageManager ( { bidderCode : BIDDER_CODE } ) ;
16
19
const refreshes = { } ;
20
+ const pageViewId = generateUUID ( ) ;
21
+ const pageViewStart = new Date ( ) . getTime ( ) ;
22
+ let auctionCounter = 0 ;
17
23
18
24
export const spec = {
19
25
code : BIDDER_CODE ,
@@ -33,6 +39,11 @@ export const spec = {
33
39
id : bidderRequest . auctionId ,
34
40
accountId : deepAccess ( bidRequests , '0.params.accountId' ) ,
35
41
site : deepAccess ( bidRequests , '0.params.site' ) ,
42
+ sessionId : getSessionId ( ) ,
43
+ counter : auctionCounter ++ ,
44
+ pageViewId : pageViewId ,
45
+ pageViewStart : pageViewStart ,
46
+ gdprConsent : gdprApplies === true ? hasFullGdprConsent ( deepAccess ( bidderRequest , 'gdprConsent' ) ) : false ,
36
47
cur : getCurrencies ( ) ,
37
48
test : getTestFlag ( ) ,
38
49
version : getGlobal ( ) . version ,
@@ -104,9 +115,7 @@ export const spec = {
104
115
registerBidder ( spec ) ;
105
116
106
117
function getPage ( bidderRequest ) {
107
- return (
108
- getConfig ( `${ BIDDER_CODE } .page` ) || deepAccess ( bidderRequest , 'refererInfo.page' ) || window . location . href
109
- ) ;
118
+ return getConfig ( `${ BIDDER_CODE } .page` ) || deepAccess ( bidderRequest , 'refererInfo.page' ) || window . location . href ;
110
119
}
111
120
112
121
function getEndpoint ( ) {
@@ -193,6 +202,19 @@ function hasSyncConsent(gdprConsent, uspConsent, gppConsent) {
193
202
return hasPurpose1Consent ( gdprConsent ) && hasUspConsent ( uspConsent ) && hasGppConsent ( gppConsent ) ;
194
203
}
195
204
205
+ function hasFullGdprConsent ( gdprConsent ) {
206
+ try {
207
+ const purposeConsents = Object . values ( gdprConsent . vendorData . purpose . consents ) ;
208
+ return (
209
+ purposeConsents . length > 0 &&
210
+ purposeConsents . every ( ( value ) => value === true ) &&
211
+ gdprConsent . vendorData . vendor . consents [ GVLID ] === true
212
+ ) ;
213
+ } catch ( e ) {
214
+ return false ;
215
+ }
216
+ }
217
+
196
218
function getSyncUrl ( responses ) {
197
219
return getConfig ( `${ BIDDER_CODE } .syncUrl` ) || deepAccess ( responses [ 0 ] , 'body.syncUrl' ) ;
198
220
}
@@ -202,3 +224,20 @@ function getSyncEndpoint(url, gdprConsent) {
202
224
gdprConsent ?. consentString || ''
203
225
) } `;
204
226
}
227
+
228
+ function getSessionId ( ) {
229
+ try {
230
+ if ( storageManager . localStorageIsEnabled ( ) ) {
231
+ let sessionId = storageManager . getDataFromLocalStorage ( SESSION_ID_KEY ) ;
232
+ if ( sessionId == null ) {
233
+ sessionId = generateUUID ( ) ;
234
+ storageManager . setDataInLocalStorage ( SESSION_ID_KEY , sessionId ) ;
235
+ }
236
+ return sessionId ;
237
+ } else {
238
+ return undefined ;
239
+ }
240
+ } catch ( e ) {
241
+ return undefined ;
242
+ }
243
+ }
0 commit comments