@@ -49,6 +49,14 @@ const initEmbeddedMessaging = (
4949 window . embeddedservice_bootstrap &&
5050 window . embeddedservice_bootstrap . settings
5151 ) {
52+ console . log ( 'Initializing Embedded Messaging with:' , {
53+ salesforceOrgId,
54+ embeddedServiceDeploymentName,
55+ embeddedServiceDeploymentUrl,
56+ scrt2Url,
57+ locale
58+ } )
59+
5260 window . embeddedservice_bootstrap . settings . language = locale
5361 window . embeddedservice_bootstrap . settings . disableStreamingResponses = true
5462 window . embeddedservice_bootstrap . init (
@@ -59,6 +67,12 @@ const initEmbeddedMessaging = (
5967 scrt2URL : scrt2Url
6068 }
6169 )
70+ } else {
71+ console . warn ( 'Embedded Messaging not ready:' , {
72+ onClient,
73+ hasBootstrap : ! ! window . embeddedservice_bootstrap ,
74+ hasSettings : ! ! window . embeddedservice_bootstrap ?. settings
75+ } )
6276 }
6377 } catch ( err ) {
6478 console . error ( 'Error initializing Embedded Messaging: ' , err )
@@ -92,7 +106,7 @@ function useMiaw(
92106 locale
93107) {
94108 useEffect ( ( ) => {
95- // Check if the embedded messaging script has been loaded and is available
109+ // Only initialize if the script is already loaded
96110 if ( onClient && window . embeddedservice_bootstrap ) {
97111 initEmbeddedMessaging (
98112 salesforceOrgId ,
@@ -188,7 +202,7 @@ const ShopperAgentWindow = ({commerceAgentConfiguration, locale, basketId}) => {
188202 handleEmbeddedMessagingWindowMaximized
189203 )
190204 }
191- } , [ commerceAgentConfiguration , usid , theme . zIndices . sticky ] )
205+ } , [ siteId , locale , commerceOrgId , usid , theme . zIndices . sticky ] )
192206
193207 /**
194208 * Updates basket ID in pre-chat fields when basket changes.
@@ -228,6 +242,18 @@ const ShopperAgentWindow = ({commerceAgentConfiguration, locale, basketId}) => {
228242 src = { scriptSourceUrl }
229243 async
230244 type = "text/javascript"
245+ onLoad = { ( ) => {
246+ // Trigger initialization when script loads
247+ if ( window . embeddedservice_bootstrap ) {
248+ initEmbeddedMessaging (
249+ salesforceOrgId ,
250+ embeddedServiceName ,
251+ embeddedServiceEndpoint ,
252+ scrt2Url ,
253+ locale
254+ )
255+ }
256+ } }
231257 />
232258 </ Helmet >
233259 )
@@ -267,10 +293,21 @@ ShopperAgentWindow.propTypes = {
267293function ShopperAgent ( { commerceAgentConfiguration, basketId, locale, basketDoneLoading} ) {
268294 const { enabled} = commerceAgentConfiguration
269295 const isShopperAgentEnabled = isEnabled ( enabled )
296+ const isConfigValid = validateCommerceAgentSettings ( commerceAgentConfiguration )
297+
298+ // Debug logging
299+ if ( onClient ) {
300+ console . log ( 'ShopperAgent render conditions:' , {
301+ isShopperAgentEnabled,
302+ basketDoneLoading,
303+ isConfigValid,
304+ enabled,
305+ basketId,
306+ locale
307+ } )
308+ }
270309
271- return isShopperAgentEnabled &&
272- basketDoneLoading &&
273- validateCommerceAgentSettings ( commerceAgentConfiguration ) ? (
310+ return isShopperAgentEnabled && basketDoneLoading && isConfigValid ? (
274311 < ShopperAgentWindow
275312 commerceAgentConfiguration = { commerceAgentConfiguration }
276313 locale = { locale }
0 commit comments