Vibe Coding with Replit -- May 4, 2026

How to Add Google Analytics to a Replit Site

By Arjita SethiMay 4, 20265 min read
Direct Answer

Add Google Analytics to a Replit site by creating a GA4 property in your Google Analytics account, copying the Measurement ID (starts with G-), and asking Claude to add the GA4 tracking script to all pages in your app. For an Express app, Claude adds it to the HTML template or layout file so it appears on every page automatically. Total setup time: 15 minutes.

Why Analytics Matters From Day One

You cannot improve what you cannot measure. Adding Google Analytics before you drive any traffic means you will have data from the first visitor -- who they are, where they came from, what page they landed on, how long they stayed. This data makes every future marketing decision more accurate.

The most important metric to watch on a new landing page: bounce rate by traffic source. If visitors from one source are leaving immediately and visitors from another are staying, that tells you where to focus your traffic efforts.

Step 1: Create a GA4 Property

Go to analytics.google.com. Create a new property for your site. Choose Web as the platform. Enter your Replit app URL. GA4 will generate a Measurement ID that looks like G-XXXXXXXXXX. Copy this.

Step 2: Ask Claude to Add the Script

Prompt: "Add Google Analytics 4 tracking to my Replit Express app. My Measurement ID is [G-XXXXXXXXXX]. Add the GA4 tracking script to every page so all page views are tracked automatically."

For Express apps, Claude will add it to the HTML layout or template that wraps all pages -- this way it appears on every route without adding it manually to each page.

Step 3: Verify It Is Working

After deploying, open your site in a browser, then check the Realtime report in Google Analytics. If your visit appears, tracking is working. If not, ask Claude to check the implementation -- usually the script is in the wrong location or the Measurement ID has a typo.

Frequently Asked Questions

How do I add Google Analytics to a Replit site?
Create a GA4 property, copy the Measurement ID (G-XXXXXXXXXX), and ask Claude to add the tracking script to all pages in your Express app. Total setup time: 15 minutes.
What is GA4?
Google Analytics 4 is the current version of Google Analytics. It tracks page views, user sessions, events, and conversion goals. It replaces the older Universal Analytics.
How do I know if Google Analytics is working?
Open your site in a browser, then check the Realtime report in Google Analytics. Your visit should appear within a minute if tracking is working correctly.
Can Google Analytics track form submissions in Replit?
Yes. Ask Claude to add event tracking to your form submission -- Claude will add GA4 event code that fires when the form is submitted successfully. You can then see form submission events in your GA4 Events report.
Is Google Analytics free?
Yes. Google Analytics 4 is free for most sites. Google Analytics 360 is a paid enterprise version. Free GA4 is appropriate for virtually all non-enterprise use cases.
Build With AI

Build and Track Your First App

The Vibe Coding track at Build with AI covers the complete build-to-analytics process.

Explore the University