Skip to main content
Triggered after the view state changes. This event enables post-change logic such as analytics, UI updates, or side effects.

Event properties

type
string
required
Always 'view:change'.
reason
string
required
The reason for the view change.
oldViewState
object
required
The previous view state.
oldViewState.launcher
boolean
Whether the launcher was visible.
oldViewState.mainWindow
boolean
Whether the main window was visible.
newViewState
object
required
The new view state.
newViewState.launcher
boolean
Whether the launcher is now visible.
newViewState.mainWindow
boolean
Whether the main window is now visible.

Example

instance.on('view:change', (event, instance) => {
    console.log('View changed:', {
        reason: event.reason,
        from: event.oldViewState,
        to: event.newViewState
    });
    
    // Remove transition CSS class
    document.body.classList.remove('chat-view-changing');
    
    // Track analytics
    if (event.newViewState.mainWindow && !event.oldViewState.mainWindow) {
        analytics.track('chat_opened', { reason: event.reason });
    }
    
    // Adjust page layout
    if (event.newViewState.mainWindow) {
        adjustPageLayout('chat-open');
    } else {
        adjustPageLayout('chat-closed');
    }
});

Do you need practical examples?

Learn how to apply the features available for embedded chat into your implementation with guidance and examples.