@@ -520,7 +520,8 @@ if (typeof window.settings === 'undefined') {
520520 try {
521521 // Only control initialization when explicitly enabled and required config is present
522522 if (
523- mainconfigTmp ?. settings ?. pega_chat ?. UsePrivateSessionControl !== true ||
523+ mainconfigTmp ?. settings ?. pega_chat ?. UsePrivateSessionControl !==
524+ true ||
524525 ! mainconfigTmp ?. settings ?. pega_chat ?. DMMURL ||
525526 ! mainconfigTmp ?. settings ?. pega_chat ?. DMMSecret
526527 ) {
@@ -529,16 +530,25 @@ if (typeof window.settings === 'undefined') {
529530
530531 // Extract widgetId and origin from the widget script URL
531532 // Example DMMURL: https://widget.use1.chat.pega.digital/<widgetId>/widget.js
532- const widgetScriptUrl = new URL ( mainconfigTmp . settings . pega_chat . DMMURL ) ;
533+ const widgetScriptUrl = new URL (
534+ mainconfigTmp . settings . pega_chat . DMMURL ,
535+ ) ;
533536 const pathParts = widgetScriptUrl . pathname . split ( '/' ) . filter ( Boolean ) ;
534537 const widgetId = pathParts [ 0 ] ;
535538 const widgetOrigin = widgetScriptUrl . origin ; // https://widget.<region>.chat.pega.digital
536539
537540 // Pick a stable customer identifier if available
538- const customerId =
539- window . PegaCSWSS ?. UserName ||
540- window . PegaCSWSS ?. UserID ||
541- `guest-${ Date . now ( ) } ` ;
541+ const privateData = {
542+ authenticated : mainconfigTmp . userId !== - 1 ,
543+ ContactID : window . PegaCSWSS . ContactID ,
544+ AccountNumber : window . PegaCSWSS . AccountNumber ,
545+ UserName : window . PegaCSWSS . UserName ,
546+ UserID : window . PegaCSWSS . UserID ,
547+ customerId :
548+ window . PegaCSWSS ?. UserName ||
549+ window . PegaCSWSS ?. UserID ||
550+ `guest-${ Date . now ( ) } ` ,
551+ } ;
542552
543553 // JWT for create must use iss = widgetId
544554 const jwtForCreate = generateJWTKey (
@@ -553,7 +563,7 @@ if (typeof window.settings === 'undefined') {
553563 'Content-Type' : 'application/json' ,
554564 authorization : `Bearer ${ jwtForCreate } ` ,
555565 } ,
556- body : JSON . stringify ( { customerId } ) ,
566+ body : JSON . stringify ( privateData ) ,
557567 } ) ;
558568
559569 if ( ! res . ok ) {
@@ -565,7 +575,9 @@ if (typeof window.settings === 'undefined') {
565575 const payload = await res . json ( ) . catch ( ( ) => ( { } ) ) ;
566576 const { sessionId } = payload || { } ;
567577 if ( sessionId ) {
568- try { localStorage . setItem ( 'sessionId' , sessionId ) ; } catch {
578+ try {
579+ localStorage . setItem ( 'sessionId' , sessionId ) ;
580+ } catch {
569581 /* ignore */
570582 }
571583 return sessionId ;
@@ -580,9 +592,11 @@ if (typeof window.settings === 'undefined') {
580592 // This callback will be invoked every time a new chat session is started
581593 window . PegaUnifiedChatWidget . onSessionInitialized = ( sessionId ) => {
582594 window . PegaCSWSS . DMMSessionID = sessionId ;
583- try { localStorage . setItem ( 'sessionId' , sessionId ) ; } catch {
584- /* ignore */
585- }
595+ try {
596+ localStorage . setItem ( 'sessionId' , sessionId ) ;
597+ } catch {
598+ /* ignore */
599+ }
586600
587601 console . log ( `PegaUnifiedChatWidget onSessionInitialized=${ sessionId } ` ) ;
588602 /* bump z-index for the iframe chat widget */
@@ -593,7 +607,6 @@ if (typeof window.settings === 'undefined') {
593607 sendClickStreamEvent ( mainconfigTmp , 'PageView' , 'Chat' , window . loadPage ) ;
594608 if (
595609 mainconfigTmp . settings . pega_chat . DMMSecret !== '' &&
596- mainconfigTmp . settings . pega_chat . UsePrivateSessionControl !== false &&
597610 mainconfigTmp . userId !== - 1
598611 ) {
599612 const privateData = {
0 commit comments