Skip to content
Marketing

How to install Google Analytics on WordPress

Three ways to add Google Analytics 4 to WordPress: Site Kit, a header snippet or Tag Manager, plus consent, testing and common mistakes.

By WP24×7 engineers5 min readPublished November 29, 2019Updated November 29, 2026

At a glance

To track visitors, add a Google Analytics 4 property to your site and connect it with a plugin or a tag. Site Kit by Google is the simplest route, a Tag Manager container is the most flexible and a small snippet in a site plugin suits a site that needs only analytics. Pick one method, test in the Realtime report and handle consent where it applies to you.

Updated November 29, 2026 · For WordPress site owners and marketers

  • For owners adding Google Analytics 4 to a WordPress site
  • Needs a GA4 property and web data stream with a Measurement ID starting G-
  • Methods Site Kit by Google, a small snippet, or Google Tag Manager
  • Test private window, then the Realtime report within a minute or two
  • Retired Universal Analytics (UA- IDs) no longer processes data
  • Privacy consent rules depend on your visitors' location; check what applies to you
  • Help WooCommerce tracking audit through WordPress support

To track visitors, add a Google Analytics 4 property to your site and connect it with a plugin or a tag. Site Kit is the simplest route, a Tag Manager container is the most flexible, and a small snippet suits a site that needs only analytics.

What do I need before I start?

  • A Google account, and a Google Analytics 4 property with a web data stream for your domain. The stream gives a Measurement ID beginning G-.
  • Administrator access to WordPress.
  • A decision about consent: whether you need a banner before loading analytics.

Universal Analytics, with IDs starting UA-, has been shut down, so ignore guides that tell you to paste one.

Which method should I pick?

Your situationSuggested method
You want reports inside WordPress and little setupSite Kit
You want only the tag and nothing elseSmall snippet in a site plugin
Several marketing tags, or a marketing team that changes themTag Manager
A shop that needs purchase trackingTag Manager or an e-commerce analytics plugin, then test with an order

Pick one method and remove the others, because stacking them is the usual cause of double counting.

How do I install it?

Site Kit is Google's own plugin and connects Analytics, Search Console, Tag Manager and other services from the dashboard.

  1. Install and activate Site Kit by Google from Plugins, Add New.
  2. Follow the set-up screens and sign in with the account that owns the property.
  3. Connect Analytics and select your GA4 property and data stream.
  4. Watch what it adds: it can place the tag itself, or you may already have a tag from another plugin.

It brings reports into the dashboard. The trade-off is another plugin and permissions to your Google data, so remove access when you stop using it.

How do I test that it works?

  1. Open your site

    in a private window with ad blockers off.

  2. Check Realtime

    In Analytics open Reports, Realtime; your visit should show within a minute or two.

  3. Use DebugView

    under Admin, DebugView for events.

  4. Use Preview

    in Tag Manager to see which tags fire.

  5. Search the page source

    for your G- ID. If it appears twice you have two installations and are double counting.

Analytics sets identifiers and collects data about visitors, which privacy laws in many places regulate. Whether you need a banner, and what must happen before the tag loads, depends on your visitors' location and your configuration. This is a legal question, so check the rules that apply to you, update your privacy policy and use a consent management plugin if needed. Google offers a Consent Mode setting that adjusts how tags behave based on a visitor's choice.

What mistakes are common?

MistakeEffectFix
Two installations at onceInflated numbersKeep one source of the tag
Optimizer delays JavaScriptShort visits unrecordedTest with your optimizer on
Counting yourselfDistorted reportsExclude editors or filter internal traffic
Wrong propertyData in the wrong placeMatch the ID to your domain's data stream
No key eventsA visit count alone is not usefulMark form submissions or purchases as key events

What should I set up after the tag works?

  • Data retention: the default is short; extend it in the property's data settings.
  • Internal traffic: define your office address and filter it out.
  • Key events: mark actions such as a form submission, a phone-number click or a purchase.
  • Search Console link to see which queries bring visits.
  • Cross-domain: if checkout is on another domain, configure it or sessions break there.

Enhanced measurement can record scrolls, outbound clicks and file downloads automatically. Review what it records and switch off anything you do not need.

A worked example, and WooCommerce

A local business wants to know whether its contact form generates leads. After installing the tag, the owner submits a test enquiry and watches Realtime. The form shows a thank-you page at its own address, so the owner records a key event when that page loads. If the page is also reachable by direct link, the count includes those visits, so the owner makes it non-indexable and does not link to it.

Store tracking needs more than the basic tag: view item, add to cart and purchase events. Test with a real order, then compare the purchase event with WooCommerce's order list. If numbers differ, see our WooCommerce experts or WordPress support for a tracking audit.

How do I remove or replace the tag later?

Search the page source for the old ID and find which plugin or snippet adds it before deleting anything. Remove it from the one place that inserts it, test the source again and confirm Realtime shows no traffic from the old property. If you switch methods, do it in one step: install the new one, remove the old one, test.

Need tracking set up properly?

Our engineers can install, test and audit it.

FAQ

Questions people ask

12 answers. Can't find yours? Ask an engineer.

Is Universal Analytics still available?

No. Google stopped processing Universal Analytics data in 2023. Google Analytics 4 is the current version, and its measurement IDs start with G-.

Link to this answer
How do I know it is working?

Open your site in a private window, then check the Realtime report in Google Analytics. Your visit should appear within a minute or two.

Link to this answer
Which method should I choose?

Site Kit if you want reports inside WordPress and little setup, a small snippet if you want only the tag, and Tag Manager if several marketing tags or a marketing team change them. Pick one and remove the others.

Link to this answer
Why are my numbers doubled?

Two installations are probably running, such as a theme option, a plugin and Tag Manager all inserting the tag. View the page source and search for your G- ID: if it appears twice, remove one.

Link to this answer
Where should I paste the Analytics code?

In a small site plugin or a header-scripts plugin, not the parent theme's header.php, since a theme update erases it.

Link to this answer
Can I stop counting my own visits?

Yes. Exclude logged-in editors in the snippet, or define your office address as internal traffic and filter it in Analytics.

Link to this answer
Why do short visits go unrecorded?

Caching and optimization plugins with a Delay JavaScript setting can postpone the tag so much that short visits are missed. Test with your optimizer on.

Link to this answer
What should I set up after the tag works?

Extend data retention if needed, filter internal traffic, mark key events such as form submissions or purchases, link Search Console and configure cross-domain tracking if checkout is on another domain.

Link to this answer
Can Analytics track WooCommerce sales?

Store tracking needs view item, add to cart and purchase events, which plugins from Google and others send. Test with a real order and compare the purchase event with WooCommerce's order list.

Link to this answer
How do I remove or replace the tag later?

Search the page source for the old ID, find which plugin or snippet inserts it and remove it from that one place. Switch in one step: install the new one, remove the old one, test.

Link to this answer
Does the Measurement ID have to match my domain?

Yes. Check the ID matches the data stream for your domain, since a wrong property sends data to the wrong place.

Link to this answer

Keep reading

Want an engineer on it?

Tell us what is wrong in plain words. A person reads it, today.