← Back to Blog·March 5, 2026·10 min read
Tutorial

How to Set Up Google Analytics for Any Website (2026 Guide)

A complete, step-by-step walkthrough for setting up Google Analytics 4 on WordPress, Wix, Squarespace, Next.js, Drupal, and any other platform — plus when a simpler alternative might be the better choice.

Setup Google Analytics Website article hero illustration

At a Glance

  • • Google Analytics 4 (GA4) is the current version — Universal Analytics was sunset in 2024
  • • Setup requires a Google account, a GA4 property, and a tracking snippet pasted into your site
  • • Platform-specific instructions cover WordPress, Wix, Squarespace, Next.js, Drupal, and static HTML
  • • GA4 uses cookies and requires a consent banner in the EU under GDPR
  • • For sites that need simpler, privacy-first analytics, cookie-free alternatives exist

What Is Google Analytics 4?

Google Analytics 4 (GA4) is Google's current web analytics platform. It replaced Universal Analytics in July 2023 and introduced an event-based data model, cross-platform tracking, and machine-learning-powered insights.

If you want to set up Google Analytics for your website in 2026, GA4 is the only option Google offers. The good news: setup is straightforward once you know the steps. The less-good news: GA4's interface is more complex than its predecessor, and the learning curve is real.

This guide walks you through every step — from creating your account to verifying data collection — on every major platform.

Step 1: Create a Google Analytics Account

Before you add tracking code to your site, you need a GA4 property. Here's how to create one:

  1. Go to analytics.google.com and sign in with your Google account
  2. Click Start measuring (or Admin → Create Account if you already have GA)
  3. Enter an Account name (e.g., your business name)
  4. Enter a Property name (e.g., “My Website”) and set your time zone and currency
  5. Select your industry category and business size
  6. Choose Web as the platform
  7. Enter your website URL and give the stream a name
  8. Click Create stream

After creating the stream, Google will show you a Measurement ID that looks like G-XXXXXXXXXX. Copy it — you'll need it in the next step.

Google will also display the Google tag (gtag.js) snippet. This is the JavaScript code you paste into your website.

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>

Important

GA4 sets cookies on your visitors' browsers. If your site serves users in the EU, you'll need a cookie consent banner to comply with GDPR. Visitors who decline cookies won't be tracked at all, which can result in 30–40% of your traffic going unrecorded.

Step 2: Add the Tracking Code to Your Website

The process for setting up Google Analytics on your website depends on your platform. Find yours below.

WordPress

WordPress offers two approaches — a plugin (easier) and a manual method (no plugin dependency).

Plugin method (recommended):

  1. Install the Site Kit by Google plugin from Plugins → Add New
  2. Activate the plugin and click Start Setup
  3. Sign in with your Google account and grant permissions
  4. Select your GA4 property (or let Site Kit create one)
  5. Complete the wizard — the plugin inserts the tracking code automatically

Manual method:

  1. Copy the gtag.js snippet from your GA4 property
  2. Go to Appearance → Theme Editor and open header.php
  3. Paste the snippet just before the closing </head> tag
  4. Save changes

Alternatively, use a “header/footer scripts” plugin like Insert Headers and Footers to avoid editing theme files directly.

Wix

Google Analytics on Wix is straightforward since Wix has a built-in integration:

  1. In the Wix dashboard, go to Marketing & SEO → Marketing Integrations
  2. Find Google Analytics and click Connect
  3. Paste your Measurement ID (G-XXXXXXXXXX)
  4. Click Save

Alternatively, go to Settings → Custom Code, click + Add Custom Code, paste the full gtag.js snippet, set it to load on All Pages in the Head, and publish.

Squarespace

Google Analytics on Squarespace takes about two minutes:

  1. Go to Settings → Advanced → Code Injection
  2. Paste the gtag.js snippet into the Header field
  3. Click Save

Squarespace applies code injection site-wide, so every page will be tracked automatically.

Next.js / React

For Next.js and React projects, use the next/script component in your root layout:

import Script from 'next/script';
// In your root layout or _app.tsx:
<Script
src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"
strategy="afterInteractive"
/>
<Script id="gtag-init" strategy="afterInteractive">
{` window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXXXXX'); `}
</Script>

The afterInteractive strategy ensures the script loads after the page becomes interactive, minimizing performance impact.

Drupal

For Drupal Google Analytics setup:

  1. Install the Google Analytics module from drupal.org
  2. Enable it at Extend → Google Analytics
  3. Go to Configuration → System → Google Analytics
  4. Enter your Measurement ID (G-XXXXXXXXXX)
  5. Save the configuration

Google Sites

Google Analytics for Google Sites uses the built-in integration:

  1. Open your site in the Google Sites editor
  2. Click the Settings gear icon
  3. Select Analytics
  4. Paste your Measurement ID and click Save

Static HTML Sites

For plain HTML sites, paste the gtag.js snippet into the <head> section of every page. If you use a templating system or a shared header include, add it there once.

Pro Tip

After adding your tracking code, test it immediately using the Real-Time report in GA4. Open your website in a new tab, then check the Real-Time section in your GA4 dashboard — you should see yourself as an active user within 30 seconds.

Step 3: Verify Your Installation Works

A surprising number of GA4 installations have silent configuration errors. Here's how to make sure yours is working correctly:

  1. Real-Time report: In GA4, go to Reports → Real-Time. Visit your website in another tab — you should see an active user appear within 30 seconds.
  2. Google Tag Assistant: Install the Google Tag Assistant Chrome extension. Visit your site, and it will confirm whether the tag is firing correctly.
  3. Browser DevTools: Open DevTools (F12), go to the Network tab, and filter for “collect”. You should see requests going to google-analytics.com/g/collect.
  4. DebugView: In GA4, go to Admin → DebugView. Enable debug mode by adding ?debug_mode=true to your URL, and watch events arrive in real time.

If nothing appears, check the troubleshooting section below.

Want Simpler Analytics?

Copper Analytics gives you the traffic insights you need without cookies, consent banners, or a 30-minute setup. One script tag, two minutes, done.

Try Copper Analytics Free

Step 4: Essential First Configurations

Once data is flowing, configure these settings right away to avoid data quality issues later:

Set Up Conversions (Key Events)

GA4 calls these key events (formerly “conversions”). Mark the events that matter most to your business:

  • Form submissions
  • Purchases or sign-ups
  • File downloads
  • Outbound link clicks to key pages

Go to Admin → Events, find the event, and toggle Mark as key event.

Filter Internal Traffic

Exclude your own visits so they don't inflate your data:

  1. Go to Admin → Data Streams → [your stream] → Configure tag settings
  2. Click Define internal traffic
  3. Add your office or home IP address
  4. Go to Admin → Data Settings → Data Filters and activate the internal traffic filter

Enable Enhanced Measurement

GA4 can automatically track scrolls, outbound clicks, site search, video engagement, and file downloads. Check that Enhanced Measurement is turned on in your Data Stream settings.

Connecting Search Console gives you organic search query data directly inside GA4:

  1. Go to Admin → Product Links → Search Console Links
  2. Click Link and select your Search Console property
  3. Complete the linking wizard

Common Setup Mistakes (and How to Avoid Them)

These are the errors that cause the most data headaches down the road:

  • Duplicate tracking code: If you add the snippet manually and via a plugin, every pageview gets counted twice. Pick one method and stick with it.
  • Wrong Measurement ID: Double-check that the ID in your code matches the one in GA4 → Admin → Data Streams. A single wrong character means zero data.
  • Not filtering internal traffic: Your own visits will skew bounce rates, session duration, and pageview counts — especially on low-traffic sites.
  • Ignoring consent requirements: Deploying GA4 without a cookie consent mechanism in the EU can result in GDPR fines. Use Google Consent Mode or a consent management platform.
  • Forgetting to publish: On Wix, Squarespace, and other hosted platforms, saving code in the editor isn't enough — you must click Publish for changes to go live.

Did You Know?

Studies estimate that roughly 30% of Google Analytics installations have at least one configuration error — from duplicate tags to missing filters. Taking 10 minutes to verify your setup now can save months of unreliable data.

Google Analytics Privacy Considerations

If you serve visitors in the EU, California, or other privacy-regulated regions, be aware of these requirements:

  • GDPR: GA4 sets cookies and transfers data to US-based Google servers. Several EU data protection authorities have flagged standard GA implementations as non-compliant. You'll need a consent banner that blocks GA until the visitor opts in.
  • Google Consent Mode v2: Google's recommended approach. It loads gtag.js but restricts data collection until consent is granted, then adjusts modeling to fill in gaps.
  • Data retention: GA4 lets you set retention to 2 or 14 months. Shorter retention limits your historical analysis but aligns better with data minimization principles.
  • IP anonymization: GA4 anonymizes IP addresses by default, but the data still passes through Google's infrastructure.
  • Ad blockers: 30–40% of visitors use ad blockers that block Google Analytics entirely. This traffic goes unrecorded regardless of consent settings.

For many site owners, these requirements add real overhead: consent banner setup, cookie policy updates, legal review, and ongoing compliance monitoring.

When Google Analytics Is Overkill

GA4 is a powerful platform designed for complex marketing operations, multi-channel attribution, and enterprise-scale data analysis. But most websites don't need that level of complexity.

If any of these describe your situation, a simpler analytics tool might be a better fit:

  • You mainly want to know how many visitors you get, where they come from, and which pages they view
  • You don't want to deal with cookie consent banners
  • You find GA4's interface confusing or overwhelming
  • Your site is a blog, portfolio, documentation site, or small business website
  • You care about page load speed and want the lightest possible tracking script
  • You want GDPR compliance without extra work

Copper Analytics is one such alternative. It gives you pageviews, visitors, referrers, top pages, device and browser breakdowns, and geographic data — all without cookies, consent banners, or complex configuration. Setup takes about two minutes: paste a single <script> tag and you're done.

You can read our full comparison of Google Analytics alternatives for a deeper look at your options, or check out our 5-minute analytics setup guide if you want to get started right away.

Want Analytics Without the Complexity?

Copper Analytics gives you the metrics that matter — no cookies, no consent banners, no 30-step setup. Free for small sites.

Try Copper Analytics Free