Developer Platform
  • Home
  • Getting Started
    • General Information
    • Features Overview
    • Security
  • APPs
    • Public Apps
      • Shopify
      • Salesforce
      • Zendesk
      • Google Analytics
    • Build your App
      • Getting started
      • My Apps
      • App information
      • App Parameters
      • App Plugins
      • Add Webhooks
      • Submit your Apps
      • App security
      • Developer Policy
  • Use Cases
    • Copilots
      • Product Catalog sync through API
      • FAQ sync through API
    • Visitor experience
      • Integrating custom buttons into your site
      • Check availability before escalating to iAdvize
      • Authenticated Messaging
        • Introduction
        • Web client-side implementation
          • Authenticated Messaging overview
          • Brief timeline of the integration process
          • How to enable authenticated mode in the administration portal?
          • How to implement the customer authentication backend (token provider)?
          • How to authenticate with iAdvize in client's website?
          • How to deal with activation success or failure?
          • How to logout?
          • Compatibility with Mobile SDK
          • FAQ
        • Web backend implementation
          • Important information and recommendations
          • Signature and Encryption Detailed Process
          • Technical backend implementation
          • FAQ
      • Cross-domain Conversation Continuity
      • Customize replies with Markdown
    • Agent workspace
      • Custom App example and step-by-step tutorial
        • Get Started
        • Work with the Desk
        • Intent / Trigger
        • JWT
        • References
    • Administration
      • Users
        • SAML SSO Authentication - Implementation Guide
        • Create, update and delete users via API
        • Manage the availability of your users with the iAdvize API
        • Integrate the iAdvize conversation panel into an existing tool
    • Data & Analytics
      • Anonymize a conversation or visitor data
      • Create a custom dashboard
      • Find contact data using GraphQL
      • Retrieve conversations data
      • Retrieve messages exchanged within a conversation
  • Technologies
    • GraphQL API
      • Terminology
      • Reference
      • Authentication
      • Schema lifecycle
      • Error Management
      • Pagination
    • REST API (deprecated)
      • Statistic (deprecated)
      • Group (deprecated)
      • Call meeting (deprecated)
      • Operator (deprecated)
      • Skill (deprecated)
      • Transaction (deprecated)
      • Visitor (deprecated)
    • Webhooks
      • Reference
      • Guides
    • Desk events
      • Reference
    • Web & Mobile SDK
      • Javascript Web SDK
        • Reference
      • Javascript Callbacks
        • Reference
        • Guides
      • Mobile SDK
        • Fourme (latest)
        • Epoisses
        • Dauphin
        • Cantal
        • 🤝Support Policy
        • 🤔Frequently Asked Questions
    • Custom App
    • External Bot
      • Implementation
        • Configuration flow
        • Conversation flow
        • Conversation objects
      • Configuration
      • FAQ
      • Best practices
Powered by GitBook
On this page
  • Safely adds events in window.iAdvizeCallbacks object
  • Safely define a function for an event
  • Track some Google Analytics events

Was this helpful?

  1. Technologies
  2. Web & Mobile SDK
  3. Javascript Callbacks

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:

var tempOnChatStarted = window.iAdvizeCallbacks.onChatStarted || () => {};

window.iAdvizeCallbacks = {
  ...window.iAdvizeCallbacks,
  
  onChatStarted(context) {

    // Call the possible already defined callback
    tempOnChatStarted(context);

    // Your new custom code here
    // ...
    
  }
  
};

Track some Google Analytics events

window.iAdvizeCallbacks = {

  ...window.iAdvizeCallbacks,
  
  // Chat conversation starts
  onChatStarted(context) {
    _gaq.push(['_trackEvent', 'iAdvize', 'Chat Start', context.startedBy]);
  },
  
  // Chat conversation ends
  onChatEnded(context) {
    _gaq.push(['_trackEvent', 'iAdvize', 'Chat End', context.startedBy]);
  },
  
  // Call conversation starts
  onCallStarted() {
    _gaq.push(['_trackEvent', 'iAdvize', 'Call Start']);
  },
  
  // Call conversation ends
  onCallEnded() {
    _gaq.push(['_trackEvent', 'iAdvize', 'Call End']);
  }

};
PreviousReferenceNextMobile SDK

Last updated 1 year ago

Was this helpful?