Analytics
I mentioned my top choices for analytics tools (Pirsch & Plausible), but feel free to integrate any other tool you prefer and place it in the <head>
of the layout.tsx
file.
Google Analytics
Setup
Complete these steps to add Google Analytics to your website.
Step 1
On the Google Analytics dashboard, pick your project, click on the Analytics tab, and then click Enable. Copy the GA-XYZ
ID.
Step 2
Add the @next/third-parties
package to your project using your preferred package manager.
Step 3
Add this component to the root layout. It wraps around the tracking script to integrate smoothly with Next.js.
Step 4
Add the GOOGLE_ANALYTICS_ID
to the .env
file.
Step 5
Deploy your app to see the analytics in action.
Google Analytics
Setup
Complete these steps to add Google Analytics to your website.
Step 1
On the Google Analytics dashboard, pick your project, click on the Analytics tab, and then click Enable. Copy the GA-XYZ
ID.
Step 2
Add the @next/third-parties
package to your project using your preferred package manager.
Step 3
Add this component to the root layout. It wraps around the tracking script to integrate smoothly with Next.js.
Step 4
Add the GOOGLE_ANALYTICS_ID
to the .env
file.
Step 5
Deploy your app to see the analytics in action.
Pirsch Analytics
Setup
Complete these steps to add Pirsch Analytics to your website. Simple like that.
Step 1
Create a new site on Pirsch and get the ID.
Step 2
Some browsers and ad-blockers might block the requests to the Pirsch JavaScript file. To solve this add a rule in next.config.js that reroutes requests to the correct Pirsch Analytics file.
Step 3
Get insights into your website traffic with Pirsch Analytics. You can copy the tracking script from the dashboard and add it to your website.
Paste the script in the <head>
tag of the layout.tsx
file of your website.
Step 4
Add the PIRSCH_ID
to the .env
file.
Events
Pirsch lets you track specific events on your webpage. Check the documentation for more details.
Plausible Analytics
Setup
Complete these steps to add Plausible Analytics to your website.
Step 1
Create a new site on Plausible and get the domain.
Step 2
Add the next-plausible
package to your project using your preferred package manager.
Step 3
Get insights into your website traffic with Plausible Analytics.
Step 4
Add the NEXT_PUBLIC_PLAUSIBLE_DOMAIN
to the .env
file.
Events
Here’s how to track form button submit events with custom event goals in Plausible: Custom Event Goals Documentation.
PostHog Analytics
Setup
Complete these steps to add PostHog Analytics to your website.
Step 1
Create a new site on PostHog and get the key.
Step 2
Add the posthog-js
package to your project using your preferred package manager. See the PostHog documentation for more details.
Step 3
After installing the package, you just need to add the token to the .env
file.
Step 4
Create a new provider component and wrap your app with it.
Step 5
Deploy your app to see the analytics in action.
Events
PostHog lets you track specific events on your webpage. Check the documentation for more details.
Simple Analytics
Setup
Complete these steps to add Simple Analytics to your website.
Step 1
Create a new site on Simple Analytics.
Step 2
Some browsers and ad-blockers might prevent the Simple Analytics JavaScript file from loading. To solve this add a rule in next.config.js that reroutes requests to the correct Simple Analytics file.
Step 3
Get insights into your website traffic with Simple Analytics. You can copy the tracking script from the dashboard and add it to your website.
Place the script in the providers component under the Analytics section. Import the Script
component from next/script
.
Step 4
Deploy your app to see the analytics in action.
Events
Here’s how to track form button submit events with custom event goals in Plausible: Custom Event Goals Documentation.
Vercel Analytics
Setup
Complete these steps to add Vercel Analytics to your website.
Step 1
On the Vercel dashboard, pick your project, click on the Analytics tab, and then click Enable.
Step 2
Add the @vercel/analytics
package to your project using your preferred package manager.
Step 3
Add this component to the providers component under the Analytics section.
Step 4
Deploy your app to Vercel to see the analytics in the dashboard.
Events
Here’s how to track form button submit events with custom event goals in Plausible: Custom Event Goals Documentation.
After Adding the Script
After adding the script, you can view the analytics in the dashboard. You can see the number of visitors, page views, and referrers. You can also see the number of visitors per country and the most visited pages.
If you need more analytics documentations or have any questions, feel free to ask in the Discord community or contact us here.