Guides

Safely adds events in window.iAdvizeCallbacks object

If you need to add iAdvize callbacks in different places in your code, you should always declare your callbacks like the following example to avoid overwriting a previous callback definition:

window.iAdvizeCallbacks = {
  ...window.iAdvizeCallbacks,
  
  onChatStarted() {
    // Do something
  },
  
  onChatEnded() {
    // Do something
  }
  
};

// Later in your code:
window.iAdvizeCallbacks = {
  ...window.iAdvizeCallbacks,
  
  onMessageReceived(context) {
    // Do something
  }
  
};

With this approach, iAdvize will see 3 callbacks: onChatStarted, onChatEnded et onMessageReceived.

Safely define a function for an event

If your code is splitted in multiple files or module, you may need to define several functions for the same event.

Here is a solution to avoid overwriting a previous function:

Track some Google Analytics events

Last updated

Was this helpful?