Analytics Components

5 Components

Pre-built React components for displaying analytics data, tracking events, and visualizing metrics in your application.

AnalyticsDashboard

Full-featured analytics dashboard with multiple widgets

EventViewer

Real-time event stream viewer with filtering

StatsCard

Single metric display with trend indicator

StatsGrid

Grid layout for multiple stats cards

SimpleChart

Lightweight chart for line, bar, and area graphs

Installation

All analytics components are included in the SDK. Import them from @sylphx/platform-sdk/react.

AnalyticsDashboard

A comprehensive, customizable analytics dashboard that displays key metrics, charts, and event data. Supports real-time updates and custom date range selection.

Basic Usage

app/dashboard/page.tsx
import { AnalyticsDashboard } from '@sylphx/platform-sdk/react'

export default function DashboardPage() {
  return (
    <AnalyticsDashboard
      title="App Analytics"
      dateRange="last_7_days"
    />
  )
}

Props

PropertyTypeDescription
titlestring= "Analytics"Dashboard title displayed at the top
dateRangeDateRange= "last_7_days"Initial date range for data
widgetsWidget[]Custom widgets to display
refreshIntervalnumber= 30000Auto-refresh interval in milliseconds
showDatePickerboolean= trueShow date range picker
showExportboolean= trueShow export button for CSV/JSON
eventsstring[]Filter to specific event types
userIdstringFilter to specific user
onDateRangeChange(range: DateRange) => voidCallback when date range changes
classNamestringAdditional CSS classes

Advanced Configuration

Custom widgets
import { AnalyticsDashboard, type Widget } from '@sylphx/platform-sdk/react'

const customWidgets: Widget[] = [
  {
    id: 'total-users',
    type: 'stat',
    title: 'Total Users',
    metric: 'users.total',
    size: 'sm',
  },
  {
    id: 'revenue',
    type: 'stat',
    title: 'Revenue',
    metric: 'billing.revenue',
    format: 'currency',
    size: 'sm',
  },
  {
    id: 'signups-chart',
    type: 'chart',
    title: 'Daily Signups',
    metric: 'users.signups',
    chartType: 'area',
    size: 'lg',
  },
  {
    id: 'top-events',
    type: 'table',
    title: 'Top Events',
    metric: 'events.top',
    size: 'md',
  },
]

<AnalyticsDashboard
  title="Business Metrics"
  widgets={customWidgets}
  dateRange="last_30_days"
/>

EventViewer

A real-time event stream viewer that displays tracked events as they happen. Includes filtering, search, and detailed event inspection.

Basic Usage

components/event-viewer.tsx
import { EventViewer } from '@sylphx/platform-sdk/react'

export function RecentEvents() {
  return (
    <EventViewer
      title="Recent Events"
      limit={50}
    />
  )
}

Props

PropertyTypeDescription
titlestring= "Events"Title displayed above the event list
limitnumber= 100Maximum number of events to display
eventsstring[]Filter to specific event types
userIdstringFilter to events from specific user
realtimeboolean= trueEnable real-time event streaming
showFiltersboolean= trueShow filter controls
showSearchboolean= trueShow search input
showTimestampboolean= trueShow event timestamps
showPropertiesboolean= trueShow event properties in expanded view
onEventClick(event: AnalyticsEvent) => voidCallback when event is clicked
emptyMessagestring= "No events found"Message when no events found
classNamestringAdditional CSS classes

Advanced Usage

Filtered events
import { EventViewer } from '@sylphx/platform-sdk/react'

// Filter to specific event types
<EventViewer
  title="Purchase Events"
  events={['checkout_started', 'payment_submitted', 'order_completed']}
  limit={25}
/>

// Filter to specific user
<EventViewer
  title="User Activity"
  userId={userId}
  showFilters={false}
/>

Performance

For high-volume event streams, consider limiting the number of displayed events and using filters to reduce data transfer.

StatsCard

A compact card displaying a single metric with optional trend indicator, comparison values, and visual styling. Perfect for KPI displays and metric highlights.

Basic Usage

import { StatsCard } from '@sylphx/platform-sdk/react'

<StatsCard
  title="Total Users"
  value={12847}
  change={12.5}
  changeLabel="vs last month"
/>

Props

PropertyTypeDescription
titlerequiredstringLabel for the metric
valuerequirednumber | stringThe primary metric value
changenumberPercentage change (positive or negative)
changeLabelstring= "vs previous period"Label for the change value
trend"up" | "down" | "neutral"Force trend direction (auto-detected from change)
format"number" | "currency" | "percent" | "compact"= "number"Value formatting
currencystring= "USD"Currency code for currency format
iconReactNodeIcon to display in the card
loadingboolean= falseShow loading skeleton
hrefstringLink to detailed view
variant"default" | "primary" | "success" | "warning" | "danger"= "default"Visual variant
size"sm" | "md" | "lg"= "md"Card size
classNamestringAdditional CSS classes

Examples

With icons
import { StatsCard } from '@sylphx/platform-sdk/react'
import { Users, DollarSign, ShoppingCart, TrendingUp } from 'lucide-react'

<div className="grid grid-cols-4 gap-4">
  <StatsCard
    icon={<Users className="w-5 h-5" />}
    title="Total Users"
    value={12847}
    change={12.5}
    variant="primary"
  />

  <StatsCard
    icon={<DollarSign className="w-5 h-5" />}
    title="Revenue"
    value={84329}
    format="currency"
    change={8.2}
    variant="success"
  />

  <StatsCard
    icon={<ShoppingCart className="w-5 h-5" />}
    title="Orders"
    value={1429}
    change={-3.1}
    variant="warning"
  />

  <StatsCard
    icon={<TrendingUp className="w-5 h-5" />}
    title="Conversion"
    value={3.24}
    format="percent"
    change={0.5}
  />
</div>

StatsGrid

A responsive grid layout for displaying multiple StatsCards. Handles layout, spacing, and loading states for a collection of metrics.

Basic Usage

import { StatsGrid } from '@sylphx/platform-sdk/react'

const stats = [
  { title: 'Total Users', value: 12847, change: 12.5 },
  { title: 'Active Today', value: 1429, change: -3.1 },
  { title: 'Revenue', value: 84329, format: 'currency', change: 8.2 },
  { title: 'Conversion', value: 3.24, format: 'percent', change: 0.5 },
]

<StatsGrid stats={stats} />

Props

PropertyTypeDescription
statsrequiredStatConfig[]Array of stat configurations
columns1 | 2 | 3 | 4 | 5 | 6= 4Number of columns in grid
gap"sm" | "md" | "lg"= "md"Gap between cards
loadingboolean= falseShow loading state for all cards
variantStatsCard variantDefault variant for all cards
sizeStatsCard size= "md"Default size for all cards
classNamestringAdditional CSS classes

StatConfig Type

interface StatConfig {
  title: string
  value: number | string
  change?: number
  changeLabel?: string
  format?: 'number' | 'currency' | 'percent' | 'compact'
  currency?: string
  icon?: ReactNode
  variant?: 'default' | 'primary' | 'success' | 'warning' | 'danger'
  href?: string
}

Examples

With icons
import { StatsGrid } from '@sylphx/platform-sdk/react'
import { Users, DollarSign, ShoppingCart, Eye } from 'lucide-react'

const stats = [
  {
    icon: <Users className="w-5 h-5" />,
    title: 'Total Users',
    value: 12847,
    change: 12.5,
    variant: 'primary',
  },
  {
    icon: <DollarSign className="w-5 h-5" />,
    title: 'Revenue',
    value: 84329,
    format: 'currency',
    change: 8.2,
    variant: 'success',
  },
  {
    icon: <ShoppingCart className="w-5 h-5" />,
    title: 'Orders',
    value: 1429,
    change: -3.1,
    variant: 'warning',
  },
  {
    icon: <Eye className="w-5 h-5" />,
    title: 'Page Views',
    value: 284739,
    format: 'compact',
    change: 24.8,
  },
]

<StatsGrid stats={stats} columns={4} />

SimpleChart

A lightweight, performant chart component for displaying time-series data. Supports line, bar, and area chart types with minimal configuration.

Basic Usage

import { SimpleChart } from '@sylphx/platform-sdk/react'

const data = [
  { date: '2024-01-01', value: 100 },
  { date: '2024-01-02', value: 120 },
  { date: '2024-01-03', value: 115 },
  { date: '2024-01-04', value: 140 },
  { date: '2024-01-05', value: 135 },
  { date: '2024-01-06', value: 160 },
  { date: '2024-01-07', value: 175 },
]

<SimpleChart
  data={data}
  type="line"
  title="Daily Active Users"
/>

Props

PropertyTypeDescription
datarequiredChartDataPoint[]Array of data points with date and value
type"line" | "bar" | "area"= "line"Chart type
titlestringChart title
subtitlestringSubtitle or description
heightnumber= 300Chart height in pixels
colorstring= "primary"Primary color for the chart
gradientboolean= trueEnable gradient fill for area charts
showGridboolean= trueShow grid lines
showXAxisboolean= trueShow X axis labels
showYAxisboolean= trueShow Y axis labels
showTooltipboolean= trueShow tooltip on hover
showLegendboolean= falseShow chart legend
xAxisKeystring= "date"Key for X axis values
yAxisKeystring= "value"Key for Y axis values
formatValue(value: number) => stringCustom value formatter
formatDate(date: string) => stringCustom date formatter
loadingboolean= falseShow loading skeleton
emptyMessagestring= "No data available"Message when no data
classNamestringAdditional CSS classes

ChartDataPoint Type

interface ChartDataPoint {
  date: string      // ISO date string or formatted date
  value: number     // Primary metric value
  [key: string]: any // Additional data for multi-series charts
}

Chart Types

Line chart
import { SimpleChart } from '@sylphx/platform-sdk/react'

<SimpleChart
  data={data}
  type="line"
  title="User Growth"
  color="#6366f1"
  showGrid={true}
  height={350}
/>

Multi-Series Charts

import { SimpleChart } from '@sylphx/platform-sdk/react'

const multiSeriesData = [
  { date: '2024-01-01', pageViews: 1200, uniqueVisitors: 450 },
  { date: '2024-01-02', pageViews: 1350, uniqueVisitors: 520 },
  { date: '2024-01-03', pageViews: 1180, uniqueVisitors: 480 },
  { date: '2024-01-04', pageViews: 1420, uniqueVisitors: 590 },
  { date: '2024-01-05', pageViews: 1560, uniqueVisitors: 640 },
]

<SimpleChart
  data={multiSeriesData}
  type="line"
  title="Traffic Overview"
  series={[
    { key: 'pageViews', label: 'Page Views', color: '#6366f1' },
    { key: 'uniqueVisitors', label: 'Unique Visitors', color: '#10b981' },
  ]}
  showLegend={true}
/>

Performance

SimpleChart is optimized for up to 1,000 data points. For larger datasets, consider aggregating data server-side or using the @sylphx/charts package for more advanced visualization needs.

Complete Example

Here is a complete example combining multiple analytics components into a dashboard:

app/admin/analytics/page.tsx
'use client'

import {
  AnalyticsDashboard,
  StatsGrid,
  SimpleChart,
  EventViewer,
} from '@sylphx/platform-sdk/react'
import { useAnalytics } from '@sylphx/platform-sdk/react'
import { Users, DollarSign, Activity, TrendingUp } from 'lucide-react'

export default function AnalyticsPage() {
  const { data, loading } = useAnalytics({
    metrics: ['users.total', 'revenue.total', 'events.count', 'conversion.rate'],
    dateRange: 'last_7_days',
  })

  const stats = [
    {
      icon: <Users className="w-5 h-5" />,
      title: 'Total Users',
      value: data?.users?.total ?? 0,
      change: data?.users?.change ?? 0,
      variant: 'primary' as const,
    },
    {
      icon: <DollarSign className="w-5 h-5" />,
      title: 'Revenue',
      value: data?.revenue?.total ?? 0,
      format: 'currency' as const,
      change: data?.revenue?.change ?? 0,
      variant: 'success' as const,
    },
    {
      icon: <Activity className="w-5 h-5" />,
      title: 'Events',
      value: data?.events?.count ?? 0,
      format: 'compact' as const,
      change: data?.events?.change ?? 0,
    },
    {
      icon: <TrendingUp className="w-5 h-5" />,
      title: 'Conversion',
      value: data?.conversion?.rate ?? 0,
      format: 'percent' as const,
      change: data?.conversion?.change ?? 0,
    },
  ]

  return (
    <div className="space-y-8 p-6">
      <h1 className="text-3xl font-bold">Analytics Dashboard</h1>

      {/* Key Metrics */}
      <StatsGrid stats={stats} loading={loading} columns={4} />

      {/* Charts */}
      <div className="grid grid-cols-2 gap-6">
        <SimpleChart
          data={data?.userGrowth ?? []}
          type="area"
          title="User Growth"
          color="#6366f1"
          height={300}
          loading={loading}
        />

        <SimpleChart
          data={data?.revenue ?? []}
          type="bar"
          title="Daily Revenue"
          color="#10b981"
          formatValue={(v) => `$${v.toLocaleString()}`}
          height={300}
          loading={loading}
        />
      </div>

      {/* Event Stream */}
      <EventViewer
        title="Recent Events"
        limit={25}
        showFilters={true}
        realtime={true}
      />
    </div>
  )
}

Theming

All analytics components inherit theming from the SylphxProvider or can be customized individually:

import { SylphxProvider, StatsCard, SimpleChart } from '@sylphx/platform-sdk/react'

// Global theming via provider
<SylphxProvider
  theme={{
    colorPrimary: '#6366f1',
    colorSuccess: '#10b981',
    colorWarning: '#f59e0b',
    colorDanger: '#ef4444',
    borderRadius: '0.75rem',
  }}
>
  <StatsCard title="Revenue" value={12500} />
  <SimpleChart data={data} type="line" />
</SylphxProvider>

// Individual component styling
<StatsCard
  title="Custom Card"
  value={100}
  className="bg-gradient-to-br from-purple-500/10 to-pink-500/10"
/>

<SimpleChart
  data={data}
  type="area"
  color="#8b5cf6"
  className="rounded-2xl shadow-lg"
/>

Need more charts?

For advanced visualization needs like pie charts, scatter plots, or real-time streaming charts, check out the @sylphx/charts package which provides a comprehensive charting library built on top of these primitives.