@@ -4,6 +4,7 @@ import { BANNER, VIDEO } from '../src/mediaTypes.js';
44import { config } from '../src/config.js' ;
55import { Renderer } from '../src/Renderer.js' ;
66import { userSync } from '../src/userSync.js' ;
7+ import { bidderSettings } from '../src/bidderSettings.js' ;
78const BIDDER_CODE = 'sonobi' ;
89const STR_ENDPOINT = 'https://apex.go.sonobi.com/trinity.json' ;
910const PAGEVIEW_ID = generateUUID ( ) ;
@@ -49,6 +50,7 @@ export const spec = {
4950
5051 return true ;
5152 } ,
53+
5254 /**
5355 * Make a server request from the list of BidRequests.
5456 *
@@ -93,7 +95,7 @@ export const spec = {
9395 'lib_name' : 'prebid' ,
9496 'lib_v' : '$prebid.version$' ,
9597 'us' : 0 ,
96-
98+ 'iqid' : bidderSettings . get ( BIDDER_CODE , 'storageAllowed' ) ? JSON . stringify ( loadOrCreateFirstPartyData ( ) ) : null ,
9799 } ;
98100
99101 const fpd = bidderRequest . ortb2 ;
@@ -388,6 +390,67 @@ export function _getPlatform(context = window) {
388390 }
389391 return 'desktop' ;
390392}
393+ /**
394+ * Check for local storage
395+ * Generate a UUID for the user if one does not exist in local storage
396+ * Store the UUID in local storage for future use
397+ * @return {object } firstPartyData - Data object containing first party information
398+ */
399+ function loadOrCreateFirstPartyData ( ) {
400+ var localStorageEnabled ;
401+
402+ var FIRST_PARTY_KEY = '_iiq_fdata' ;
403+ var tryParse = function ( data ) {
404+ try {
405+ return JSON . parse ( data ) ;
406+ } catch ( err ) {
407+ return null ;
408+ }
409+ } ;
410+ var readData = function ( key ) {
411+ if ( hasLocalStorage ( ) ) {
412+ return window . localStorage . getItem ( key ) ;
413+ }
414+ return null ;
415+ } ;
416+ var hasLocalStorage = function ( ) {
417+ if ( typeof localStorageEnabled != 'undefined' ) { return localStorageEnabled ; } else {
418+ try {
419+ localStorageEnabled = ! ! window . localStorage ;
420+ return localStorageEnabled ;
421+ } catch ( e ) {
422+ localStorageEnabled = false ;
423+ }
424+ }
425+ return false ;
426+ } ;
427+ var generateGUID = function ( ) {
428+ var d = new Date ( ) . getTime ( ) ;
429+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
430+ var r = ( d + Math . random ( ) * 16 ) % 16 | 0 ;
431+ d = Math . floor ( d / 16 ) ;
432+ return ( c === 'x' ? r : ( r & 0x3 ) | 0x8 ) . toString ( 16 ) ;
433+ } ) ;
434+ } ;
435+ var storeData = function ( key , value ) {
436+ try {
437+ if ( hasLocalStorage ( ) ) {
438+ window . localStorage . setItem ( key , value ) ;
439+ }
440+ } catch ( error ) {
441+ return null ;
442+ }
443+ } ;
444+ var firstPartyData = tryParse ( readData ( FIRST_PARTY_KEY ) ) ;
445+ if ( ! firstPartyData || ! firstPartyData . pcid ) {
446+ var firstPartyId = generateGUID ( ) ;
447+ firstPartyData = { pcid : firstPartyId , pcidDate : Date . now ( ) } ;
448+ } else if ( firstPartyData && ! firstPartyData . pcidDate ) {
449+ firstPartyData . pcidDate = Date . now ( ) ;
450+ }
451+ storeData ( FIRST_PARTY_KEY , JSON . stringify ( firstPartyData ) ) ;
452+ return firstPartyData ;
453+ } ;
391454
392455function newRenderer ( adUnitCode , bid , rendererOptions = { } ) {
393456 const renderer = Renderer . install ( {
0 commit comments