This repository demonstrates Journium integration for Next.js Pages Router. Use this as a reference implementation for building your own Journium-powered applications with Next.js Pages Router.
Note
If you want to use Next.js App Router, please refer to the Next.js App Router example repository instead. For React + Vite, check out the React + Vite example repository.
A fully functional habit tracking app demonstrating:
- ✅ User authentication flow
- ✅ Event tracking with Journium
- ✅ Real-time insights generation
- ✅ Paywall integration
- ✅ Next.js Pages Router best practices
Time to complete: ~10 minutes
- Node.js 18+ installed
- npm, yarn, or pnpm package manager
git clone https://github.com/journium/nextjs-pages-router-example.git
cd nextjs-pages-router-examplenpm install
# or
yarn install
# or
pnpm install-
Sign up for a Journium account at https://journium.app/signup
-
Create an application named "Looply" in your Journium dashboard
-
Copy your Publishable Key from the Developers | API Keys section.
💡 Smart Links: Dashboard URLs automatically navigate to your app - just click!
-
Create a
.env.localfile in the project root:touch .env.local
-
Add your key to the
.env.localfile: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_...Important: Development instances use
pk_test_keys. Production keys start withpk_live_.
# Start the development server (default port 3000)
npm run dev
# or
yarn dev
# or
pnpm devThe server will start at http://localhost:3000
Using a custom port?
npm run dev -- -p 3001
pnpm dev -- -p 3001
yarn dev -p 3001 # Note: yarn doesn't use -- before flagsOpen http://localhost:3000 in your browser to see the Looply app running.
Navigate around the app to automatically send events to Journium:
- Sign up for a test account (use any email/password, e.g.,
test@example.com/password123- data is local only) - Create a habit (e.g., "Drink water")
- Log a habit entry
- Explore different pages (Home, Insights, Settings)
Then view your collected events at Developers | Events.
✅ Success indicator: You should see events appearing in your dashboard within a few seconds.
Note
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 | Overview
✅ Congratulations! You've successfully created your first insight with Journium!
- Verify your API key starts with
pk_and is correctly set in.env.local - Check browser console for errors (F12 → Console)
- Ensure you're interacting with the local Looply app at
localhost:3000(not the dashboard) - Restart the dev server after changing
.env.localfile
- Delete
node_modulesand.nextcache, then reinstall dependencies:rm -rf node_modules .next && npm install - Ensure Node.js version is 18+:
node --version
- Use a different port:
npm run dev -- -p 3001
- Or stop the process using port 3000:
lsof -ti:3000 | xargs kill -9
- Ensure the file is named exactly
.env.local(not.env.local.txtor.env) - Restart the development server after creating/modifying
.env.local - Check file location: it must be in the project root, not in the
pages/directory - Variable names must start with
NEXT_PUBLIC_to be accessible in the browser
- Explore the codebase to see how Journium is integrated
- Send your own custom events - see Journium Events Documentation
- Customize this example to build your own application
- Learn about Insight Trackers and create custom analytics
npm run dev- Start the development servernpm run build- Build the application for productionnpm run start- Start the production servernpm run lint- Run ESLint to check for code issues