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.
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
Jump to section
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:
- Go to analytics.google.com and sign in with your Google account
- Click Start measuring (or Admin → Create Account if you already have GA)
- Enter an Account name (e.g., your business name)
- Enter a Property name (e.g., “My Website”) and set your time zone and currency
- Select your industry category and business size
- Choose Web as the platform
- Enter your website URL and give the stream a name
- 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.
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):
- Install the Site Kit by Google plugin from Plugins → Add New
- Activate the plugin and click Start Setup
- Sign in with your Google account and grant permissions
- Select your GA4 property (or let Site Kit create one)
- Complete the wizard — the plugin inserts the tracking code automatically
Manual method:
- Copy the gtag.js snippet from your GA4 property
- Go to Appearance → Theme Editor and open
header.php - Paste the snippet just before the closing
</head>tag - 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:
- In the Wix dashboard, go to Marketing & SEO → Marketing Integrations
- Find Google Analytics and click Connect
- Paste your Measurement ID (
G-XXXXXXXXXX) - 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:
- Go to Settings → Advanced → Code Injection
- Paste the gtag.js snippet into the Header field
- 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:
The afterInteractive strategy ensures the script loads after the page becomes interactive, minimizing performance impact.
Drupal
For Drupal Google Analytics setup:
- Install the Google Analytics module from drupal.org
- Enable it at Extend → Google Analytics
- Go to Configuration → System → Google Analytics
- Enter your Measurement ID (
G-XXXXXXXXXX) - Save the configuration
Google Sites
Google Analytics for Google Sites uses the built-in integration:
- Open your site in the Google Sites editor
- Click the Settings gear icon
- Select Analytics
- 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:
- 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.
- Google Tag Assistant: Install the Google Tag Assistant Chrome extension. Visit your site, and it will confirm whether the tag is firing correctly.
- 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. - DebugView: In GA4, go to Admin → DebugView. Enable debug mode by adding
?debug_mode=trueto 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 FreeStep 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:
- Go to Admin → Data Streams → [your stream] → Configure tag settings
- Click Define internal traffic
- Add your office or home IP address
- 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.
Link Google Search Console
Connecting Search Console gives you organic search query data directly inside GA4:
- Go to Admin → Product Links → Search Console Links
- Click Link and select your Search Console property
- 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