Documentation

Analytics

The widget supports sending analytics events through the widgetAnalytics event. When a widgetAnalytics event is triggered, the widget will invoke the specified analytics callback from the DG_CHAT_WIDGET_CONFIG configuration, if one is defined. This enables you to capture and record events in your preferred analytics platform.

Example Event Payload

Here's a sample payload for a widgetAnalytics event:

{
  "type": "widgetAnalytics",
  "payload": {
    "type": "quickReplySelected",
    "value": "some value"
  }
}

Configuration Example

To set up the analytics callback, you can configure your DG_CHAT_WIDGET_CONFIG like this:

window.DG_CHAT_WIDGET_CONFIG = {
  env: 'eu',
  flowId: 'xxxxx-xxxxx-xxxxx-xxxxxxx',
  externalAccountKey: 'abc123',
  callbacks: {
    // Other callbacks...
    analytics: (message) => {
      if (message.type === 'quickReplySelected') {
        // Trigger an analytics event to record which quick reply was selected
        // Your analytics logic goes here
      }
    }
  }
}

How It Works

  1. Event Trigger: When a specific event occurs, such as a user selecting a quick reply, the widget sends a widgetAnalytics event.
  2. Callback Execution: If defined, the analytics callback in your configuration will be called with the event message.
  3. Analytics Integration: You can then implement the necessary logic to log this event to your analytics platform.