Overview

aSaaSin integrates Google Analytics (GA4) out of the box using the official Next.js package @next/third-parties/google.

This means you only need to set your Measurement ID in .env - no manual script tags are required.

Get your Measurement ID

  1. Sign in to Google Analytics.
  2. Create or open a GA4 property.
  3. Go to Admin → Data collection and modification → Data streams.
  4. Select your Web data stream.
  5. Copy the Measurement ID (format: G-XXXXXXXXXX).

Add to .env

# Google Analytics
NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX

How it works

The RootLayout includes the built-in Next.js component:

import { GoogleAnalytics } from '@next/third-parties/google';

<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GA_ID as string} />

This automatically injects the required GA4 tracking script when the app runs, using the Measurement ID from your environment variables.

No extra setup is needed — as long as NEXT_PUBLIC_GA_ID is set, Google Analytics starts tracking page views and events.

Verify tracking

  • Open your site and check Realtime in Google Analytics.
  • In browser DevTools Network tab, you should see requests to collect.
  • Analytics usually only initializes in production. If you don’t see events locally, test on a deployed preview build.