Advanced Use Cases

Track Chatbot Usage At Real-time

If you wish to restrict your chatbot access to subscribed users and deduct message credits post-chat, follow these steps:


Setup Process

Step 1: Mandate the Leads Form to Track User Information

Require users to complete the leads form upon initiating their first message. This ensures all user interactions with your chatbot are preceded by their details being logged as shown in the screen below (note the settings in the red box). Mandate Leads Form This configuration allows our chatbot to relay real-time data such as email, phone number, and name from the leads when they converse with your bot.

Step 2: Implement a Webhook to Monitor Messages

Set up webhooks as per the Webhook Setup Guide. Following this, you will receive chat events, which help track a specific user's chatbot interactions. Here is an example payload:

{
  "messages": [
    {
      "role": "assistant",
      "content": "👋 Hello there! I'm Chat Data AI, your go-to source for all things about Chat Data!"
    },
    {
      "role": "assistant",
      "content": "By the way, you can create a chatbot like me for your website! 😮"
    },
    {
      "role": "user",
      "content": "How to integrate with Discord?"
    }
  ],
  "answer": {
    "role": "assistant",
    "content": "You can follow the [guide](https://www.chat-data.com/api-reference#section/Chat-Data-Website-Guide/Discord-Bot-Integration) to integrate your chatbot with Discord.",
    "score": 0.8503905227042547
  },
  "client_ip": "xx.xx.xx.xx",
  "chatbot_id": "654aee418bc9a33b0e50d0ad",
  "source": "widget",
  "cost_credits": 20,
  "conversation_id": "dbf24043-83a6-47fb-b241-9865de3877c9",
  "lead": {
    "uuid": "28239132-671d-4b1f-9d43-1c7b70985ede",
    "email": "[email protected]",
    "name": "User"
  }
}

Frequently Asked Questions

What is the first step to tracking chatbot usage in real time for specific users?

You should require the leads form on the user's first message so each conversation is tied to lead information such as email, phone number, and name.

How do webhooks help with real-time chatbot usage tracking?

After setting up webhooks, you receive chat events for each conversation, which lets you monitor a specific user's interactions with the chatbot in real time.

What data is included in the real-time chat webhook payload?

The example payload includes the conversation messages, the assistant answer, client IP, chatbot ID, source, cost_credits, conversation_id, and lead information such as email and name.

Why does the guide recommend mandating the leads form?

Because it ensures the chatbot can send real-time user details alongside chat activity, which is useful if you want to restrict access to subscribed users or deduct credits after chats.

Previous
Logged-in User Experience