Add Google Analytics to Any Website

Connect Google Analytics to your website, track real visitors and important actions, verify that data is being collected correctly, and avoid duplicate or broken tracking.

Roadmap & Resources

Check What Tracking Already Exists

Audit the Website First

Before adding Google Analytics, inspect the website first. AI-built projects sometimes already contain analytics code, a Google tag, Google Tag Manager, or tracking added by the hosting platform. Adding another copy can cause duplicate page views and inaccurate reports.

Google Analytics Audit

Identifies whether Google Analytics or Google Tag Manager is already installed, any existing Measurement ID, analytics libraries or custom helpers, existing page-view or event tracking, and any consent system that affects analytics — searches for duplicate implementations, exposes no credentials, and classifies the site as not installed, already correct, incomplete, or possibly duplicated.

Review this website specifically for adding Google Analytics correctly. Do not change anything yet. Identify: - the framework and project type - whether Google Analytics is already installed - whether Google Tag Manager is already installed - any existing Google tag or GA4 Measurement ID - any analytics libraries or packages - any custom analytics helper - any page-view tracking - any custom event tracking - any cookie/consent system that affects analytics - any analytics environment variables — names only - whether this is a traditional multi-page website or a client-side SPA Search for possible duplicate tracking implementations. Do not expose private credentials. Finish with: Analytics status: 1. Not installed 2. Already installed correctly 3. Installed but incomplete 4. Possible duplicate tracking If changes are required, recommend the smallest appropriate implementation for this project.

NOTE

If Analytics is already working correctly, do not install another copy.

Create Your Google Analytics Property

Create a GA4 Property & Web Stream

Open Google Analytics and create a GA4 property for the website if you do not already have one. Then create a Web data stream for your website, entering your website URL and business/site name.

Google Analytics

Create your GA4 property and Web data stream.

https://analytics.google.com

Google Analytics will provide a Measurement ID that looks similar to:

Example Measurement ID

G-XXXXXXXXXX

Keep this Measurement ID available for the next step.

Use the Correct Website

For a production website, use the real production domain whenever possible.

Use

https://example.com

rather than:

Not

http://localhost:3000

You can still test locally during implementation, but your main Analytics property should represent the real website you want to measure.

Keep the Setup Simple

For most beginner websites, you do not need:

Multiple Analytics properties Complicated custom dimensions Dozens of custom events A large Google Tag Manager setup

Start by collecting accurate basic traffic data. You can expand the tracking later when there is a real reason.

Connect Google Analytics to the Website

Connect GA4 to Your Project

Give your Measurement ID to your AI coding assistant.

Add Google Analytics 4

Adds GA4 using the existing project architecture and the audit's findings — the appropriate implementation for this framework, no duplicate or unnecessary GTM install, correct page-view and SPA route-change tracking, browser-only loading, and respect for any existing consent mechanism — then runs the production build, checks for errors, lists every changed file, and answers Google Analytics integration: READY or NOT READY.

Add Google Analytics 4 to this website using this Measurement ID: [YOUR GA4 MEASUREMENT ID] First use the existing project architecture and the analytics audit you already completed. Requirements: - use the appropriate GA4 implementation for this framework - do not install a second analytics implementation if one already exists - do not add Google Tag Manager unless this project already uses it or there is a clear reason - make sure page views are tracked correctly - if this is a client-side SPA, make sure navigation between routes is measured correctly - avoid duplicate page-view events - load Analytics only in the browser where appropriate - preserve the existing website design and functionality - respect any existing analytics-consent mechanism Keep the implementation simple. Do not add unnecessary tracking libraries. Do not track sensitive personal information. Do not deploy anything automatically. After implementation: - run the production build - check for browser/runtime errors - tell me exactly which files changed Finish with: Google Analytics integration: READY / NOT READY

Add Only Useful Events

Basic page views are enough to start. If your website has one important conversion action, it can also be useful to track it.

Contact form submitted Booking started Signup completed Purchase completed Important CTA clicked

NOTE

Do not track every button on the website just because you can.

Find the Events Worth Adding

Recommend 1–3 Conversion Events

Identifies the 1–3 most important user actions genuinely worth measuring — real business outcomes like a submitted form, completed signup, booking request, or purchase, never vanity clicks — and for each returns the event name, when it fires, and why it matters, without adding anything yet or including any personal information.

Review this website and identify the 1–3 most important user actions that would genuinely be useful to measure in Google Analytics. Do not add anything yet. Avoid vanity events such as tracking every ordinary click. Prioritize real business or product outcomes such as: - successful contact form submission - completed signup - booking request - checkout/purchase completion - another clearly important conversion already present in this website For each recommendation, tell me: - the event name - when it should fire - why it is useful Do not include personal information such as names, email addresses, phone numbers, passwords, or message contents in analytics events.

If one or two events are genuinely useful, let your AI coding assistant add them.

Verify Your Analytics Before Relying on the Data

Test Your Own Visit

Do not assume Analytics works simply because the tracking code exists. Open your website, visit several pages, then check the real-time reporting in Google Analytics and confirm that your visit appears. Test:

Homepage

Another important page

Navigation between pages

Your important tracked action, if you added one

Check for Duplicate Tracking

One visit should not unexpectedly create multiple identical page views because two Analytics implementations are running at the same time.

NOTE

Use your browser developer tools or Google's available tag-testing tools if something looks wrong.

Run the Final Analytics Audit

Final Google Analytics Audit

Verifies GA4 loads with the correct Measurement ID, is not installed twice, doesn't double-track between GTM and direct GA4, tracks page views and SPA route changes correctly, fires custom events only on success without duplicates, sends no personal information, keeps consent logic working, and has no console errors — then answers Analytics status: READY or NOT READY, listing exactly what to fix if not.

Run a final Google Analytics implementation audit for this website. Verify: - Google Analytics loads on the intended pages - the correct GA4 Measurement ID is being used - Analytics is not installed twice - Google Tag Manager and direct GA4 tracking are not duplicating the same tracking - page views work - SPA route changes are tracked correctly if this is a single-page application - important custom events fire only when the intended action succeeds - events are not firing multiple times accidentally - no names, email addresses, phone numbers, passwords, message content, or other sensitive personal information is being sent to Analytics - any existing consent logic still works - there are no important browser console errors - the production build succeeds Do not add additional tracking unless a real problem is found. Do not deploy anything automatically. Finish with: Analytics status: READY / NOT READY If NOT READY, list exactly what must be fixed.

After Deployment

Once the website is live:

Open the production website yourself. Browse several pages. Complete one important tracked action if applicable. Open Google Analytics. Confirm that the activity appears. Check again later after Analytics begins processing normal visitor data.

You now have a basic Analytics setup that can tell you where visitors are coming from, which pages they use, and whether they complete the actions that matter.