Introducing Virtual MCP Servers
LogoLogo
GithubJoin SlackSignupBook a Demo
  • Documentation
  • Self Hosted
  • Integrations
  • Guides
  • Enterprise
  • Introduction to AI Gateway
  • Supported Models
  • Supported MCP Servers
  • Getting Started
    • Quick Start
    • Working with API
    • Working with Multiple Agents
    • Working with MCPs
    • Working with Headers
    • User Tracking
    • Using Parameters
  • Concepts
    • Thread
    • Trace
    • Run
    • Label
    • Message
    • Virtual Models
      • Routing with Virtual Model
    • Virtual MCP Servers
  • Features
    • Tracing
    • Routing
    • MCP Support
    • Publishing MCP Servers
    • Usage
    • Analytics
    • Guardrails
    • User Roles
    • Cost Control
  • Python SDK
    • Getting Started
  • API Reference
  • Postman Collection
Powered by GitBook
LogoLogo

Social

  • LinkedIn
  • X
  • Youtube
  • Github

Platform

  • Pricing
  • Documentation
  • Blog

Company

  • Home
  • About

Legal

  • Privacy Policy
  • Terms of Service

2025 LangDB. All rights reserved.

On this page
  • Example: Chatbot Analytics with User Tracking
  • User Tracking Fields
  • Fetching User Analytics & Usage Data

Was this helpful?

Export as PDF
  1. Getting Started

User Tracking

Track users in LangDB AI Gateway to analyze usage, optimize performance, and improve chatbot experiences.

LangDB AI enables user tracking to collect analytics and monitor usage patterns efficiently. By associating metadata with requests, developers can analyze interactions, optimize performance, and enhance user experience.

Example: Chatbot Analytics with User Tracking

For a chatbot service handling multiple users, tracking enables:

  • Recognizing returning users: Maintain conversation continuity.

  • Tracking usage trends: Identify common queries to improve responses.

  • User segmentation: Categorize users using tags (e.g., "websearch", "support").

  • Analytics: Identify heavy users and allocate resources efficiently.

curl 'https://api.us-east-1.langdb.ai/v1/chat/completions' \
-H 'authorization: Bearer LangDBApiKey' \
-H 'Content-Type: application/json' \
-d '{
  "model": "openai/gpt-4o-mini",
  "stream": true,
  "messages": [
    {
      "role": "user",
      "content": "Def bubbleSort()"
    }
  ],
  "extra": {
    "user": {
      "id": "7",
      "name": "mrunmay",
      "tags": ["coding", "software"]
    }  
  }
}'

User Tracking Fields

  • extra.user.id: Unique user identifier.

  • extra.user.name: User alias.

  • extra.user.tags: Custom tags to classify users (e.g., "coding", "software").

Fetching User Analytics & Usage Data

Once users are tracked, analytics and usage APIs can be used to retrieve insights based on id, name, or tags.

Example:

curl -L \
  --request POST \
  --url 'https://api.us-east-1.langdb.ai/analytics/summary' \
  --header 'Authorization: Bearer langDBAPIKey' \
  --header 'X-Project-Id: langDBProjectID' \
  --header 'Content-Type: application/json' \
  --data '{
    "user_id": "7",
    "user_name": "mrunmay",
    "user_tags": ["software", "code"]   
  }'

Example response:

{
  "summary": [
    {
      "total_cost": 0.00030366,
      "total_requests": 1,
      "total_duration": 6240.888,
      "avg_duration": 6240.9,
      "duration": 6240.9,
      "duration_p99": 6240.9,
      "duration_p95": 6240.9,
      "duration_p90": 6240.9,
      "duration_p50": 6240.9,
      "total_input_tokens": 1139,
      "total_output_tokens": 137,
      "avg_ttft": 6240.9,
      "ttft": 6240.9,
      "ttft_p99": 6240.9,
      "ttft_p95": 6240.9,
      "ttft_p90": 6240.9,
      "ttft_p50": 6240.9,
      "tps": 204.46,
      "tps_p99": 204.46,
      "tps_p95": 204.46,
      "tps_p90": 204.46,
      "tps_p50": 204.46,
      "tpot": 0.05,
      "tpot_p99": 0.05,
      "tpot_p95": 0.05,
      "tpot_p90": 0.05,
      "tpot_p50": 0.05,
      "error_rate": 0.0,
      "error_request_count": 0
    }
  ],
  "start_time_us": 1737547895565066,
  "end_time_us": 1740139895565066
}
PreviousWorking with HeadersNextUsing Parameters

Last updated 3 months ago

Was this helpful?

Checkout and section for more details.

Usage
Analytics