Next.js Quick Start
This tutorial demonstrates how to integrate Journium with your Next.js application.
Setup
Set up Journium for your Next.js application.
Install @journium/nextjs
The Journium Next.js SDK gives you access to pre-built hooks and components to help you generate events in your Next.js application and get insights from your data.
Run the following command to install the SDK:
npm i @journium/nextjsSet your Journium Publishable Key
-
Sign up for a Journium account for free at journium.app/signup
-
Create an application in your Journium dashboard
-
Copy your Publishable Key from the Developers | API Keys section
Dashboard URLs automatically navigate to your app - just click!
-
Create a
.env.localfile in your project root:touch .env.local -
Add your key to the
.env.localfile:.env.local NEXT_PUBLIC_JOURNIUM_PUBLISHABLE_KEY=your_publishable_key_here -
Verify your setup - check that the key is correctly saved:
cat .env.local # Should show: NEXT_PUBLIC_JOURNIUM_PUBLISHABLE_KEY=pk_test_...Development instances use
pk_test_keys. Production keys start withpk_live_.
Add <NextJourniumProvider> to your app
The <NextJourniumProvider> component provides session and user context to Journium's hooks.
It's recommended to wrap your entire app at the entry point with <NextJourniumProvider>
to make analytics globally accessible throughout your application.
import { NextJourniumProvider } from '@journium/nextjs';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en" suppressHydrationWarning>
<body>
<NextJourniumProvider>
{children}
</NextJourniumProvider>
</body>
</html>
);
}import type { AppProps } from 'next/app';
import { NextJourniumProvider } from '@journium/nextjs';
export default function App({ Component, pageProps }: AppProps) {
return (
<NextJourniumProvider>
<Component {...pageProps} />
</NextJourniumProvider>
);
}Run the Development Server
Start your application:
npm run devUsing a custom port? Next.js defaults to port 3000. To use a different port, set the PORT environment variable or use -p flag: npm run dev -- -p 3001
Verify Your Setup
Open http://localhost:3000 (or your custom port) in your browser to see the application running.
Send Events to Journium
Navigate around your app to automatically send events to Journium.
Then view your collected events at Developers | Events.
Success indicator: You should see events appearing in your dashboard within a few seconds.
Generate Your First Insight
When you create an app in Journium, a default Insight Tracker is automatically created. This tracker helps you test data ingestion and insight generation.
- Go to your Developers | Insight Trackers page
- Click the
Analyze nowbutton for the tracker titled "User Engagement" - Monitor the job status in Developers | Jobs
- Wait for the job to complete (usually takes 1-2 minutes)
- View your generated insights at Dashboard | Insights
Done
Congratulations! You've successfully created your first insight with Journium!
Troubleshooting
What's next?
Last updated on