Google Analytics 4 Integration
Google Analytics 4 (GA4) is the latest version of Google Analytics. It is a free and powerful analytics tool that allows you to track your website’s traffic and behavior.
To manage GA4 and other tools, Google provides a unified platform called Google Tag Manager (GTM). It is recommended to use Google Tag Manager to manage your website’s analytics including GA4.
Google Tag Manager Setup
To setup Google Tag Manager, you need the GTM container ID.
- Go to Google Tag Manager and create a new Web Container.
- After creation, you’ll get two code snippets. No need to copy them. Just copy the GTM container ID like
GTM-XXXXXXX. - Paste the GTM container ID into the
GTM_IDenvironment variable in your.env.localfile.
GTM_ID=GTM-XXXXXXXGA4 Setup
Get Your GA4 Measurement ID
- Go to Google Analytics .
- Navigate to Admin → Data Streams → Web.
- Copy your Measurement ID — it looks like
G-XXXXXXXXXX.
You’ll use this in Google Tag Manager (GTM) later.
Add Google Tag Manager to Your Site
Set up GTM in your site according to the instructions above.
Create a GA4 Configuration Tag in GTM
- In GTM, go to Tags → New → Tag Configuration → Google Analytics: GA4 Configuration.
- Paste your Measurement ID from Step 1.
- Enable “Send a page view event when this configuration loads”.
- Set the Triggering to All Pages.
- Click Save.
Preview, Publish & Verify
- In GTM, click Preview to open Tag Assistant .
- Visit your site and confirm the tag fires on page load.
- Click Submit → Publish to make it live.
- Go to GA4 → Reports → Realtime — you should see your visit show up within seconds.
Last updated on