How to Fix Legacy Universal Analytics (UA-) Tracking Code

Universal Analytics stopped processing data on July 1, 2023 (July 1, 2024 for GA 360), yet many sites still load snippets that reference UA- property IDs. This guide shows you how to find every UA- ID in your pages, remove it from hardcoded snippets, plugins, apps and tag managers, and confirm that only your GA4 (G-) tag remains.

By Updated ⏱ 20 minutes🎯 Beginner● Low impactTechnical
Illustration: Legacy Universal Analytics code fix guide
TECHNICAL · FIX GUIDE Legacy Universal Analytics code IMPACTEFFORT TIME20 minutes LEVELBeginner

Why it matters

A UA- tag sends hits to a property Google no longer processes, so it collects nothing while still adding script requests and, on older analytics.js or ga.js setups, extra JavaScript to every page. It also creates false confidence that tracking is working, clutters consent and privacy reviews with a tracker that has no purpose, and signals an unmaintained setup to anyone auditing the site. The SEO impact is small, but the fix takes minutes and leaves a cleaner, faster, easier-to-audit tag setup.

✕BeforePage source contains ga('create','UA-1234567-1', 'auto') orgtag('config', 'UA-1234567-1')✓AfterPage source contains onlygtag('config', 'G-XXXXXXXXXX') and nostring matching UA-#######-#.

What you need

Admin access to your CMS, theme files or code repository
Access to your GA4 property to look up the G- Measurement ID
Google Tag Manager access if your site uses a GTM container
Ability to purge your site and CDN cache

Step-by-step fix

1

List every UA- ID and the pages that load it

Start with the IDs and URLs from your audit report, then confirm them yourself. Run the command below against a few templates (home, blog post, product, checkout or contact page), because different templates often load different header code. Note each UA- ID and which page types contain it.

text
curl -s https://www.example.com/ | grep -oE "UA-[0-9]+-[0-9]+" | sort -u
Pro tip: In a browser, open View Source (Ctrl+U / Cmd+Option+U) and search for "UA-". IDs inside HTML comments or JSON config blobs still count, so remove those too.
2

Confirm your GA4 Measurement ID

Before deleting anything, make sure GA4 is collecting data so you don't end up with no analytics at all. In Google Analytics go to Admin > Data collection and modification > Data streams, open your web stream and copy the Measurement ID (starts with G-). If you have no GA4 property yet, create one under Admin > Create > Property first.

Pro tip: If the page already has a G- tag, check that its ID matches the stream in your GA4 property; old sites sometimes carry a GA4 ID from a test property.
3

Remove hardcoded UA snippets from your templates

Search your theme or codebase for UA-, analytics.js, ga.js, _gaq and ga('create'. Legacy snippets come in three forms:

  • ga.js: a script using _gaq.push(['_setAccount','UA-…'])
  • analytics.js: a script that loads google-analytics.com/analytics.js and calls ga('create','UA-…')
  • gtag.js: a gtag('config','UA-…') line, often sitting next to a GA4 config line

Delete the first two snippets entirely. For gtag.js, delete only the UA config line and keep the loader and GA4 config, as shown below.

html
<!-- Google tag (GA4 only) -->
<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>
Pro tip: If the gtag.js loader URL itself contains ?id=UA-…, change it to your G- ID. Otherwise the UA- ID stays in the source even after you remove the config line.
4

Clear UA IDs from plugins, apps and site settings

Many UA tags are injected by an integration rather than the theme. Check every place where an analytics ID can be pasted, such as SEO plugins, header/footer script plugins, built-in Google Analytics fields, and e-commerce apps. Replace any UA- value with your G- ID or clear the field.

If GA4 is already set elsewhere, leave it empty to avoid double tracking. See the platform notes for exact menu paths.

Pro tip: Check environment variables too (for example NEXT_PUBLIC_GA_ID or GA_TRACKING_ID). A UA- value stored there will be rendered into every page.
5

Delete Universal Analytics tags in Google Tag Manager

com and go to Tags. Filter by type and delete any tag of type Google Analytics: Universal Analytics. Then open Variables and delete any Google Analytics Settings variables that hold a UA- ID.

Make sure a Google Tag with your G- ID fires on Initialization - All Pages, then click Submit > Publish.

Pro tip: Tags inside GTM don't appear in raw page source, so cleaning GTM may not change the audit result. Do it anyway: those tags still fire in visitors' browsers.
6

Purge caches and redeploy

Page caches and CDNs can keep serving the old HTML for hours or days. Purge your caching plugin, your hosting cache and your CDN (for example in Cloudflare: Caching > Configuration > Purge Everything). For static or framework sites, rebuild and redeploy so the generated HTML no longer contains the UA- string.

7

Verify the UA- IDs are gone and GA4 still works

Run the curl command from step 1 again on every template you noted. It should return nothing. Then open GA4 Reports > Realtime overview, visit your site in another tab, and confirm your visit appears.

Finally, re-run the site audit so the check reports no UA- tags.

text
curl -s https://www.example.com/ | grep -cE "UA-[0-9]+-[0-9]+"
# Expected output: 0
Pro tip: Use Google Tag Assistant (tagassistant.google.com) to confirm that only the G- tag fires and that it fires once per page.

Platform-specific notes

WordPress

Check the plugins that inject analytics: Site Kit (Site Kit > Settings > Connected Services > Analytics), MonsterInsights, GA Google Analytics, and header/footer plugins such as WPCode (Code Snippets > Header & Footer). Also check Appearance > Theme File Editor > header.php, or the child theme's functions.php, for a hardcoded snippet. Purge your caching plugin (WP Rocket, LiteSpeed Cache, W3 Total Cache) afterwards.

Shopify

Open Online Store > Themes > … > Edit code and search theme.liquid and any snippets for UA-. Check Settings > Customer events for custom pixels that reference UA-, and remove any legacy ID left in Online Store > Preferences. Run GA4 through the Google & YouTube app, or a single custom pixel, rather than through theme code.

Webflow

Check Site settings > Apps & integrations > Google Analytics and clear any UA- ID. Then check Site settings > Custom code (Head and Footer) and the page-level custom code on individual pages. Publish the site so the change goes live.

Next.js

Run grep -rn "UA-" app pages src components .env* to find the ID. Replace custom next/script snippets with GA4. With @next/third-parties, use <GoogleAnalytics gaId="G-XXXXXXXXXX" /> in the root layout. Update the env variable in your hosting dashboard (for example Vercel > Settings > Environment Variables) and redeploy, because statically generated pages keep the old ID until they are rebuilt.

Cloudflare

If you used Cloudflare Zaraz, open Zaraz > Tools Configuration and remove any Universal Analytics tool. After the origin fix, purge the cache under Caching > Configuration > Purge Everything.

Check that it worked

✅ How to verify

  • Run curl -s https://www.example.com/ | grep -oE "UA-[0-9]+-[0-9]+" on each page template and confirm it returns no output.
  • In Chrome DevTools > Network, filter by "collect". Confirm requests go to /g/collect with tid=G-… and that none go to /collect with tid=UA-….
  • Open GA4 Reports > Realtime overview and confirm your own visit is recorded.
  • Re-run the site audit and confirm the check reports no Universal Analytics (UA-) tags.

⚠️ Common mistakes

  • Deleting the whole gtag.js block when it also contained the GA4 config, which leaves the site with no analytics at all.
  • Removing the gtag('config','UA-…') line but leaving the UA- ID in the gtag.js loader URL or in an HTML comment, so the ID still appears in the source.
  • Cleaning the theme while a plugin, app, GTM tag or environment variable keeps injecting the UA- ID.
  • Forgetting to purge page and CDN caches, then assuming the fix failed because the old HTML is still being served.

Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.

Check my site free

FAQ

Is Universal Analytics still collecting data?

No. Standard Universal Analytics properties stopped processing new hits on July 1, 2023, and GA 360 properties stopped on July 1, 2024. Google has since removed access to UA properties and their data, so a UA- tag on your site collects nothing.

Will removing the UA code break my Google Analytics 4 tracking?

Not if you keep the GA4 tag. GA4 uses its own G- Measurement ID and does not depend on the UA snippet. Only remove the UA- parts, then confirm in GA4 Realtime that visits are still recorded.

Can I still get my old Universal Analytics data?

Generally no. Google deleted UA property data during 2024, and removing the tag from your site has no effect on historical data either way. If you exported reports or used BigQuery before the shutdown, those copies are your only remaining record.

Why does my site still show a UA- ID after I removed the tag?

The usual causes are a cached page, a plugin or app injecting the ID, a theme section you didn't edit (such as a separate header file or a checkout template), or the ID remaining in the gtag.js loader URL or an HTML comment. Purge all caches, search the full page source for UA-, and check each integration listed in the platform notes.