Skip to main content

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:
  1. Navigate to Bots in the left sidebar
  2. Click Ver Detalles on any bot card to view detailed metrics
  3. Switch between Slice and WhatsApp bot analytics

Slice Bot Metrics

The Slice web assistant tracks comprehensive interaction data defined in types.ts:267-273:
interface SliceBotMetrics {
    distinctCustomers: number;    // Unique customers served
    totalMessages: number;        // Total messages exchanged
    totalTokensUsed: number;      // Estimated AI tokens consumed
    ordersMade: number;           // Orders placed via chatbot
    reservationsMade: number;     // Reservations made via chatbot
}

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:
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 in sliceBotMetricsService.ts:13-15:
const estimateTokens = (text: string): number => {
    return Math.ceil((text || '').length / 4);
};
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 in types.ts:275-280):
interface WhatsAppBotMetrics {
    distinctCustomers: number;    // Unique phone numbers
    totalMessages: number;        // Total messages in/out
    ordersMade: number;           // Orders via WhatsApp
    reservationsMade: number;     // Reservations via WhatsApp
}

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 the WhatsappsHistory sheet (whatsappBotMetricsService.ts:73-84):
const distinctCustomers = new Set(history.map(msg => msg.from)).size;
const totalMessages = history.length;
const ordersMade = orders.filter(o => 
    o.createdBy === CreatedBy.WHATSAPP_ASSISTANT
).length;
const reservationsMade = reservations.filter(r => 
    r.createdBy === CreatedBy.WHATSAPP_ASSISTANT
).length;
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):
interface ChatHistorySession {
    id: string;                           // Session or customer identifier
    startTime: string;                    // ISO timestamp of first message
    messages: ChatMessage[];              // Array of message objects
    outcome: 'order' | 'reservation' | null; // Conversation result
    tokensUsed: number;                   // Tokens for this session (Slice only)
    lastActivity: string;                 // ISO timestamp of last message
}

Message Structure

interface ChatMessage {
    sender: MessageSender;  // 'user' or 'bot'
    text: string;           // Message content
}

Session Outcomes

Chat sessions can have three outcome types:
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:
1

Access Slice Details

Navigate to Bots panel and click Ver Detalles on the Slice bot card
2

Scroll to History Section

The chat history section shows “Historial de Chats (Últimos 100)”
3

View Session Summary

Each session displays:
  • Session start time (es-AR format)
  • Outcome (Pedido, Reserva, or Inconcluso)
  • Token usage estimate
  • Message count
4

Expand Session

Click any session to expand and view full message thread with:
  • User messages (right-aligned, primary color background)
  • Bot messages (left-aligned, gray background)
  • User and bot icons for visual distinction

WhatsApp Bot Chat History

WhatsApp sessions are displayed with customer phone numbers:
1

Access WhatsApp Details

Navigate to Bots panel and click Ver Detalles on the WhatsApp bot card
2

View Customer List

Sessions are grouped by customer phone number (the from field)
3

Review Session Info

Each entry shows:
  • Customer phone number
  • Outcome (if any)
  • Message count
  • Last activity timestamp
4

Open Chat Modal

Click a session to open a modal with the full conversation thread

Chat History Limits

The system maintains a maximum of 100 chat sessions per bot (sliceBotMetricsService.ts:6):
const MAX_HISTORY_SESSIONS = 100;
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

1

Session Start

When a customer opens the Slice chatbot, a new session is created:
startSession(): string
  • Generates unique session ID: SESSION-{timestamp}-{random}
  • Increments distinctCustomers counter
  • Initializes empty message array
  • Sets outcome to null
2

Message Logging

Each message (user or bot) is logged:
logMessage(sessionId: string, message: ChatMessage)
  • Adds message to session
  • Estimates and adds token usage
  • Increments totalMessages counter
  • Updates lastActivity timestamp
3

Outcome Recording

When order/reservation is completed:
logOutcome(sessionId: string, outcome: 'order' | 'reservation')
  • Sets session outcome (only once per session)
  • Increments corresponding metric counter
  • Updates lastActivity timestamp

WhatsApp Bot Session Flow

WhatsApp sessions are reconstructed from message history:
  1. Fetch History: Retrieve all WhatsApp messages from Google Sheets
  2. Group by Customer: Messages grouped by phone number (from field)
  3. Build Sessions: Create session objects with all messages from that customer
  4. Determine Outcome: Check if customer has orders/reservations created via WhatsApp
  5. Sort by Activity: Display sessions ordered by last activity timestamp

Data Storage and Sync

Firebase Collections

Analytics data is stored in Firebase:
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:
interface StoredData {
    metrics: BotMetrics;
    chatHistory: ChatHistorySession[];
}

Real-Time Updates

The admin dashboard uses Firebase listeners to sync metrics in real-time (AdminDashboard.tsx:153-158):
const unsubSliceMetrics = onSnapshot(sliceMetricsDocRef, (docSnap) => {
    if (docSnap.exists()) {
        updateMetricsCache(docSnap.data() as SliceBotMetrics);
        setDataTimestamp(Date.now());
    }
});
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 details

WhatsApp 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:
Conversion Rate = (ordersMade + reservationsMade) / distinctCustomers * 100
Higher conversion rates indicate the bot is effectively guiding customers to complete transactions.

Engagement Metrics

Analyze customer engagement:
Average Messages per Session = totalMessages / distinctCustomers
Higher message counts may indicate either strong engagement or confusion requiring more clarification.

Token Efficiency (Slice Bot)

Monitor AI usage costs:
Average Tokens per Customer = totalTokensUsed / distinctCustomers
Average Tokens per Message = totalTokensUsed / totalMessages
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.

Build docs developers (and LLMs) love