User Tracking

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.

Checkout Usage and Analytics section for more details.

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
}

Last updated

Was this helpful?