Skip to main content

Overview

This example shows how to build a custom analytics dashboard that fetches data from the Grain Query API and displays it in a beautiful, interactive interface. We’ll use React, Next.js, and Chart.js to create a dashboard that rivals the built-in Grain dashboard.
This example assumes you have a Builder plan or higher and have created an API key with Query API permissions.

Project Setup

1. Create Next.js Project

2. Install Dependencies

3. Environment Variables

Create .env.local:

Core API Client

First, let’s create a client for interacting with the Query API:

Dashboard Components

1. Metric Card Component

2. Event Timeline Chart

3. Top Events Table

4. User Activity Chart

Main Dashboard Page

API Routes for Server-Side Data

For better performance and security, create API routes to proxy requests:

Real-time Updates

Add real-time updates using polling:

Error Handling and Loading States

Deployment

1. Build the Project

2. Deploy to Vercel

3. Set Environment Variables

In your Vercel dashboard, add:
  • GRAIN_TENANT_ID
  • GRAIN_API_KEY

Custom Plans

Building a high-traffic dashboard? We offer custom plans with:
  • Higher rate limits: Custom requests per minute/day limits for real-time dashboards
  • Dedicated support: Priority support and SLA guarantees
  • Custom features: Tailored analytics features and integrations
  • Volume discounts: Competitive pricing for high-volume usage
Contact us at support@grainql.com to discuss your dashboard requirements.

Next Steps

Data Export

Learn how to export data for analysis

Query API Reference

Complete API documentation

Filter Reference

All filter operators and examples

Grain Dashboard

Built-in analytics dashboard