Getting Started
Learn how to integrate Trackcel analytics into your React or Next.js application in just a few simple steps.
Choose your setup:
Select your framework and language preference. All code examples will be customized for your choice.
Installation
Install Trackcel using your preferred package manager. Trackcel works seamlessly with React and Next.js applications.
Select package manager:
Current: npmGet Your Credentials
Navigate to your project dashboard to generate the required credentials for your application.
Project ID
Public identifier for your project
cm8j08uk40304tf4wd33yy07mAPI Key
Secret key for authentication
••••••••••••••••••••••••••••••••Environment Setup
Create an environment file to securely store your Trackcel credentials. The environment variable names differ between Next.js and React/Vite.
Environment File for Next.js + TypeScript
# Trackcel Configuration for Next.js
NEXT_PUBLIC_TRACKCEL_PROJECT_ID=cm8j08uk40304tf4wd33yy07m
NEXT_PUBLIC_TRACKCEL_API_KEY=sk_live_875c2bdf439b42b58ab52b8b4175c8c3
# Note: NEXT_PUBLIC_ prefix makes these variables available in the browser
# Only use this for public credentials that are safe to expose client-sideSetup Instructions:
Create a .env.local file in your project root directory
Copy the environment variables from above and replace the values with your actual credentials
Environment variables are loaded at startup, so restart your dev server after creating the file
Create Analytics Provider
Create a provider component for Next.js + TypeScript. This component reads from environment variables and initializes Trackcel analytics.
Provider Component for Next.js + TypeScript
"use client";
import { Analytics } from "trackcel";
export default function AnalyticsProvider(): JSX.Element {
return (
<Analytics
projectId={process.env.NEXT_PUBLIC_TRACKCEL_PROJECT_ID!}
apiKey={process.env.NEXT_PUBLIC_TRACKCEL_API_KEY!}
debug={true}
disableInDevelopment={true}
/>
);
}Configuration Options
debugEnable console logging for debugging purposes
disableInDevelopmentDisable tracking in development mode to avoid test data
Add to Your Layout
Import and add your analytics provider to your root layout to enable automatic page tracking across your entire application.
Integration for Next.js + TypeScript
import AnalyticsProvider from "./providers/analytics";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}): JSX.Element {
return (
<html lang="en">
<body>
{children}
<AnalyticsProvider />
</body>
</html>
);
}Integration Comparison
| Framework | File Location | Auto Routing | SSR Support |
|---|---|---|---|
Next.jsApp Router | app/layout.tsx | ||
ReactSPA | src/main.tsx | Manual* | Client-side |
* React SPA requires manual route tracking with React Router integration
Verify Installation
Your Next.js + TypeScript application is now configured to track visitor data. Here's how to verify everything is working correctly:
Check Environment Variables
Ensure your .env.local file is in the project root and your development server has been restarted.
Check Browser Console
With debug mode enabled, you should see Trackcel logs in your browser's developer console.
Visit Your Dashboard
Navigate through your application, then check your project dashboard for real-time analytics data.
Test Page Navigation
Navigate between different pages to ensure automatic page view tracking is working.
Common Issues for Next.js + TypeScript:
🎉 You're all set with Next.js + TypeScript!
Trackcel is now securely configured with environment variables and tracking your Next.js application.