To fix this easily, this is to avoid manually managing the WebSocket lifecycle for analytics events. The Genesys Cloud JS SDK provides a built-in Subscription class that handles reconnection, token refresh, and heartbeat logic automatically. Using raw ws instances bypasses the SDK’s internal state management, leading to the 401 errors you are seeing when the underlying token expires or the server closes the connection for maintenance.
Warning: Do not mix manual WebSocket connections with SDK subscriptions for the same resource. It causes race conditions during token refresh and may trigger rate limiting due to excessive connection attempts.