This React + Next.js demo showcases how to build a user-facing analytics dashboard using Trench. You can see a live demo of it on https://demo.trench.dev.
-
Copy
.env.example
to.env.local
in the root directory of your project and add your Trench server URL, public API key, and private API key. -
Install the dependencies:
pnpm install
- Then, start the development server:
pnpm run dev
- Visit http://localhost:3000 in your browser to view the dashboard.
The most important files are:
src/data/trench.ts
- Wrapper around thetrench-js
client.src/app/page.tsx
- The main page of the dashboard.src/app/_components/VisitorsChart.tsx
- The chart on the main page.
Note: This example uses React Server Components to allow fetching data from the Trench API on the server. If copying code to a non-RSC React project, you should make sure never to expose your private API key in the client bundle.
For a deeper understanding of the technologies used in this template, check out the resources listed below:
- Trench - Trench.dev documentation and website
- Tremor Raw - Tremor Raw documentation
- Tailwind CSS - A utility-first CSS framework
- Next.js - Next.js documentation
- Radix UI - Radix UI Website
- Recharts - Recharts documentation and website