Overview
The Analytics system in Ai Studio provides comprehensive insights into your AI-powered assistants’ performance. Monitor customer interactions, track conversion rates, and analyze chat histories for both the Slice web chatbot and WhatsApp bot.Analytics data is collected automatically as customers interact with your AI assistants. All metrics are calculated in real-time and synced to Firebase.
Accessing Analytics
Analytics are accessed through the Bots Panel in the admin dashboard:- Navigate to Bots in the left sidebar
- Click Ver Detalles on any bot card to view detailed metrics
- Switch between Slice and WhatsApp bot analytics
Slice Bot Metrics
The Slice web assistant tracks comprehensive interaction data defined intypes.ts:267-273:
Key Performance Indicators
Customers Served
distinctCustomersTracks unique chat sessions initiated by customers. Each new chat session increments this counter.
Total Messages
totalMessagesCumulative count of all messages (user + bot) exchanged across all chat sessions.
Tokens Used
totalTokensUsedEstimated AI processing tokens consumed. Based on ~4 characters per token calculation.
Orders Placed
ordersMadeNumber of successful orders created through the Slice chatbot interface.
Reservations Made
reservationsMadeNumber of successful reservations booked via the Slice assistant.
Metrics Dashboard View
When viewing Slice bot details, metrics are displayed in color-coded cards:- Customer Metrics
- Message Volume
- Token Usage
- Conversion Metrics
Clientes Atendidos - Blue iconShows the total number of unique customers who have initiated chat sessions with Slice. This metric helps understand reach and customer engagement.
Token Estimation
Token usage is estimated using a simple calculation insliceBotMetricsService.ts:13-15:
Token estimation is approximate and based on the industry standard of ~4 characters per token. Actual API token usage may vary.
WhatsApp Bot Metrics
The WhatsApp assistant tracks similar metrics without token counting (defined intypes.ts:275-280):
Key Differences from Slice Bot
No Token Tracking
WhatsApp metrics don’t include token usage since it’s an external platform integration
Phone-Based Sessions
Sessions are grouped by customer phone number (from field) rather than session IDs
Metrics Calculation
WhatsApp metrics are calculated from theWhatsappsHistory sheet (whatsappBotMetricsService.ts:73-84):
WhatsApp metrics are fetched from Google Sheets via API and cached locally for performance.
Chat History
Both bots maintain detailed chat history for analysis and review.Chat Session Structure
Each chat session is stored with the following structure (types.ts:282-289):
Message Structure
Session Outcomes
Chat sessions can have three outcome types:- Order
- Reservation
- Inconcluso (Incomplete)
outcome: ‘order’The conversation resulted in a successful order placement. The
ordersMade metric is incremented.This outcome is logged when a customer completes the order flow through the chatbot.Viewing Chat History
Slice Bot Chat History
Slice bot sessions are displayed in an expandable list format:View Session Summary
Each session displays:
- Session start time (es-AR format)
- Outcome (Pedido, Reserva, or Inconcluso)
- Token usage estimate
- Message count
WhatsApp Bot Chat History
WhatsApp sessions are displayed with customer phone numbers:Review Session Info
Each entry shows:
- Customer phone number
- Outcome (if any)
- Message count
- Last activity timestamp
Chat History Limits
The system maintains a maximum of 100 chat sessions per bot (sliceBotMetricsService.ts:6):
When the 101st session is created, the oldest session is automatically removed from the history cache. This keeps storage usage manageable while preserving recent interactions.
Session Lifecycle
Slice Bot Session Flow
Session Start
When a customer opens the Slice chatbot, a new session is created:
- Generates unique session ID:
SESSION-{timestamp}-{random} - Increments
distinctCustomerscounter - Initializes empty message array
- Sets
outcometo null
Message Logging
Each message (user or bot) is logged:
- Adds message to session
- Estimates and adds token usage
- Increments
totalMessagescounter - Updates
lastActivitytimestamp
WhatsApp Bot Session Flow
WhatsApp sessions are reconstructed from message history:- Fetch History: Retrieve all WhatsApp messages from Google Sheets
- Group by Customer: Messages grouped by phone number (
fromfield) - Build Sessions: Create session objects with all messages from that customer
- Determine Outcome: Check if customer has orders/reservations created via WhatsApp
- Sort by Activity: Display sessions ordered by last activity timestamp
Data Storage and Sync
Firebase Collections
Analytics data is stored in Firebase:- Slice Metrics
- Chat History
Collection:
SliceBotMetricsDocument: mainStores the aggregated metrics object. Real-time listener updates dashboard when metrics change.Local Caching
Metrics and chat history are cached in localStorage for offline access and performance: Slice Bot Cache Key:pizzeria-slice-bot-metrics
WhatsApp Bot Cache Key: pizzeria-whatsapp-bot-metrics
Cache structure:
Real-Time Updates
The admin dashboard uses Firebase listeners to sync metrics in real-time (AdminDashboard.tsx:153-158):
Any changes to bot metrics are instantly reflected across all connected admin sessions without requiring page refresh.
Bot Status Tracking
Connection Time Tracking
Both bots track their connection uptime:Slice Bot
Tracks connection time when status is
activeDisplayed as live uptime counter in bot detailsWhatsApp Bot
Tracks connection time from QR code scan completionPersisted in localStorage for session persistence
Last Update Timestamp
Each bot shows when its status was last refreshed:- Slice: Updated when status changes or manual refresh
- WhatsApp: Updated via polling (15s when viewing, 30s in background)
Metrics Dashboard Interface
Grid View
The main Bots panel shows bot cards in a 2-column grid with:- Bot icon and name
- Connection status indicator (colored dot)
- Uptime timer (if active)
- Last update timestamp
- Action buttons (Connect/Disconnect, Ver Detalles)
Details View
Clicking “Ver Detalles” switches to a full-screen metrics view with:- Header: Bot name with close button
- Metrics Grid: Color-coded KPI cards
- Chat History Section: Scrollable list of sessions
- Expandable Sessions: Click to view message threads
Analyzing Bot Performance
Conversion Rate
Calculate bot effectiveness:Engagement Metrics
Analyze customer engagement:Token Efficiency (Slice Bot)
Monitor AI usage costs:Monitor token usage to estimate API costs and optimize bot prompt efficiency.
Outcome Tracking
Understand conversation results by analyzing outcome distribution:- High Order Rate: Bot effectively assists with purchases
- High Reservation Rate: Bot successfully handles bookings
- High Inconcluso Rate: May indicate need for bot training improvements
Best Practices
Regular Review
Check bot metrics daily to identify trends and issues early
Analyze Inconclusive Chats
Review conversations without outcomes to improve bot responses
Monitor Token Usage
Track token consumption to manage API costs effectively
Compare Bot Performance
Compare Slice vs WhatsApp metrics to optimize channel strategy
Troubleshooting
Metrics Not Updating
- Check Firebase connection status in dashboard header
- Verify bot is active and processing messages
- Refresh the page to force cache reload
- Check browser console for sync errors
Missing Chat History
- Verify session limit hasn’t been exceeded (100 max)
- Check that messages are being logged in real-time
- Ensure Firebase permissions allow read access
Incorrect Token Counts
- Remember token estimates are approximate (~4 chars/token)
- Long messages may show higher token usage
- Special characters may affect estimation accuracy
Export and Reporting
While the dashboard doesn’t currently support direct export, metrics can be:- Viewed in Firebase Console for raw data access
- Monitored through Firebase Analytics integration
- Extracted via Firebase Admin SDK for custom reports
Related Documentation
Learn how to manage bot activation and configuration in the Dashboard Overview under the Bots Panel section.
