Home / Fix guides / Analytics, cookies and GDPR

How to remove old Universal Analytics code and replace it with GA4

Universal Analytics (the tracking code with an ID starting UA-) stopped processing data in 2023, so any of it still on your site is dead weight. Find it, make sure GA4 (an ID starting G-) is installed once, then delete the old code and check that it is gone.

Universal Analytics (UA) was the old version of Google Analytics. Google stopped processing data in standard UA properties on 1 July 2023 and replaced it with Google Analytics 4 (GA4). If your site still loads the old UA code, it collects nothing useful, but it may still load an extra script, set cookies and confuse anyone who looks at your setup later.

What the problem looks like

Most people only find out when someone checks. Typical signs:

  • Your analytics reports have been empty or frozen since mid 2023.
  • Someone set up GA4 but never removed the old snippet, so both are on the page.
  • The page source contains an ID that starts with UA- followed by numbers.
  • Your cookie banner or cookie list still mentions analytics cookies you thought you had retired.
  • An old theme, plugin or developer snippet adds the code to every page without anyone remembering.

Why it matters

  • Nothing is being measured. If UA is your only tag, you have had no visitor data since the shutdown, and any decisions about marketing or content are based on nothing.
  • Wasted loading time. The old script is an extra request on every page. The cost is small, but it buys you nothing.
  • Privacy and trust. Old code can still set cookies. If it runs before a visitor consents, that is a GDPR problem, and your privacy and cookie policies should describe what your site really does.
  • Mess and duplicates. Leftover tags make it easy to end up counting visits twice later. See GA4 duplicate tracking for that case.

How to check if your site has it

All of these are free.

  1. Open your site, right click and choose View page source. Press Ctrl+F (Cmd+F on Mac) and search for UA-, analytics.js, ga.js and google-analytics.com. Also search for G- and gtag/js to see whether GA4 is there.
  2. Open your browser developer tools (F12), go to the Network tab, reload the page and type analytics in the filter box. A request for analytics.js means old code is loading.
  3. Use Google's free Tag Assistant (tagassistant.google.com). Enter your address and it lists the Google tags it finds.
  4. If you use Google Tag Manager, open the container and look at the Tags list for any tag of type Universal Analytics or any tag using a UA- ID.
  5. Check a few different pages. Code is sometimes only in one template, such as the checkout or thank you page.

How to fix it in general

The order matters, so you do not end up with no tracking at all.

  1. Confirm a GA4 property exists in your Google Analytics account and note its Measurement ID (it starts with G-).
  2. Install GA4 using one method only: a plugin or built in setting, a Google Tag Manager tag, or code in the page head. Not several.
  3. Find every place the old code lives: theme header or footer files, analytics plugin settings, a custom code or header and footer box, Tag Manager, and scripts added by apps or by your checkout.
  4. Delete the old code. Copy it somewhere safe first so you can undo a mistake.
  5. Clear your site cache and any CDN cache, otherwise visitors may keep getting the old page.
  6. Update your cookie consent tool and cookie list so they match what is now on the site.

The old snippet usually looks like one of these:

<script async src="https://www.google-analytics.com/analytics.js"></script>
<script>ga('create', 'UA-12345678-1', 'auto'); ga('send', 'pageview');</script>

or, in the newer style, a line such as gtag('config', 'UA-12345678-1');. If your page loads Google's gtag.js, you can often just change the ID in that snippet to your G- ID. Do not delete other Google tags (such as Google Ads) unless you know what they do.

Common platforms

Menu names change between versions and themes, so treat these as places to look, not exact paths. We have a full guide for WordPress and one for Google Tag Manager, and guides for Shopify, Wix, Squarespace, Magento and Drupal live under the same /fix/universal-analytics-still-installed/ address.

PlatformWhere the old code usually is
WordPressAn analytics plugin's settings, a header and footer scripts setting, theme options, or the theme's header file
Google Tag ManagerThe Tags list: a Universal Analytics tag to delete or pause, then publish the container
ShopifyOnline Store preferences (older stores), custom pixels under customer events, the theme's theme.liquid, or an installed Google app
WixThe marketing integrations or tracking tools area, and any custom code under settings
SquarespaceCode injection under developer or advanced settings, and older Google Analytics fields in the settings
MagentoGoogle API configuration under Stores, Configuration, Sales, and custom HTML in the head under Content, Design
DrupalThe Google Analytics module settings, or code in a theme template or custom block

How to confirm the fix worked

  • Reload your site with a hard refresh, view the source again and search for UA- and analytics.js. Neither should appear.
  • Check the Network tab again. There should be no request for analytics.js.
  • Open GA4 and look at the Realtime report while you visit the site. Your visit should appear. If it does not, see GA4 not showing data.
  • Check that GA4 loads only once, not twice, on each page.
  • In developer tools, under Application then Cookies, the cookies _gid and _gat belong to the old setup. GA4 uses _ga and cookies starting _ga_. Test in a fresh private window and note that consent settings can change what appears.

How to stop it coming back

  • Decide who owns tracking and write down where it lives (plugin, Tag Manager or code). One place only.
  • Check for old analytics code before and after a redesign, a theme change or a move to a new host.
  • Be careful with old plugins, copied theme folders and staging sites that get pushed live, since they can bring old snippets back.
  • Recheck after any new app or marketing tool is added, because many add their own tracking.
  • Week 38 of SiteMonday is an analytics setup check that looks for this and lists it in your report. It only finds and explains the problem. Removing the code is up to you or your developer. More on that week is on the week 38 page.

Step by step for your platform

Questions

Does Universal Analytics still collect data?

No. Google stopped processing data in standard Universal Analytics properties on 1 July 2023, so the old code gives you no usable reports.

Can I just leave the old UA code on my site?

You can, but it adds an extra script, may set cookies and hides the fact that you have no working tracking. It is better to remove it once GA4 is working.

Can I change my UA ID to a GA4 ID?

Only in some cases. If your snippet uses Google's `gtag.js`, swapping in a `G-` Measurement ID often works, but the old `analytics.js` code cannot be converted and should be replaced.

Will removing the old code delete my historical data?

Removing code from your website does not delete anything in your Google account. Access to old UA reports is controlled by Google, so export anything you still need if it is available to you.

Do I need to tell visitors about the change?

If your cookies or tracking tools change, your cookie policy and consent banner should match what the site now does. Check them after the fix.

Who should do this, me or a developer?

If you have access to your site settings or Tag Manager, many owners can do it in under an hour. If the code is hard coded in a theme, ask your developer.

Related problems