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.

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.
What you need
Step-by-step fix
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.
curl -s https://www.example.com/ | grep -oE "UA-[0-9]+-[0-9]+" | sort -u
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.
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.
<!-- 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>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.
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.
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.
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.
curl -s https://www.example.com/ | grep -cE "UA-[0-9]+-[0-9]+" # Expected output: 0
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 freeFAQ
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.
How to Fix a Missing Cookie Consent Banner for Tracking Tags
How to Fix Duplicate Analytics Tags (Google Tag Loaded Twice)
How to Set Up Google Consent Mode v2 Defaults on Your Site
How to Install Analytics on Every Page of Your Site
How to Enable HTTPS and Redirect Your Site from HTTP
How to Fix Old URLs That Redirect to the Homepage