How to Change Google Analytics Tracking Code

Cody Schneider8 min read

So, you need to change your Google Analytics tracking code. Whether you're finally making the full switch to Google Analytics 4, migrating your website to a new platform, or fixing an old, broken implementation, swapping out that snippet of code is a critical step. This guide provides a straightforward walkthrough of how to find your new code and implement it correctly across popular platforms like WordPress and Shopify, as well as with Google Tag Manager.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Why and When You Need to Change Your Tracking Code

While it might feel like a technical chore, changing your GA tracking code is usually a positive step forward for your data collection. Most systems today fall into one of these categories:

  • Upgrading from Universal Analytics (UA) to GA4: This is the most common reason by far. Universal Analytics stopped processing new data in July 2023. If you haven't yet, you must replace your old UA tracking code (which starts with "UA-") with a new GA4 measurement ID (starting with "G-").
  • Migrating Your Website: Moving from Weebly to WordPress? Or Wix to Shopify? When you change your Content Management System (CMS) or e-commerce platform, you need to make sure your GA tracking code comes along for the ride. This often involves removing it from the old site's settings and adding it to the new one.
  • Fixing a Faulty Implementation: Sometimes, things just don't get set up right the first time. You might discover the tracking code was placed in the wrong file, added more than once, or is missing entirely from certain pages. A clean reinstall is often the easiest fix.
  • Switching Implementation Methods: You might choose to move from placing the code directly on your site to managing it with a tool like Google Tag Manager (GTM). This is a smart move that gives you more control, and it requires removing the old code and redeploying it via GTM.
GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Step 1: Find Your GA4 Tracking Code (Measurement ID)

Before you can add the new code, you have to find it. In the world of GA4, the full code snippet is often referred to as the "Google tag," and the unique identifier is called the "Measurement ID."

Here’s how to locate it in your GA4 property:

  1. Log in to your Google Analytics account and navigate to the correct GA4 property.
  2. Click on the Admin gear icon in the bottom-left corner of your screen.
  3. In the Property column, click on Data Streams.
  4. You will see a list of your data streams (typically one for your website). Click on yours to open the stream details.
  5. On the next screen, you’ll find your Measurement ID in the top-right corner. It will look something like G-XXXXXXXXXX. This is the ID you'll need for most plugins and platform integrations.
  6. If you need the full script for a manual installation, click on View tag instructions under the "Google tag" section. This will open a new pane with detailed installation steps, including the full JavaScript snippet to copy.

Now that you have your code, it's time to put it on your site.

Step 2: Install the New Tracking Code

Where and how you add the new code depends entirely on your website's platform. It's also crucial that you remove the old Universal Analytics code to avoid collecting duplicate data or other tracking conflicts.

For WordPress Websites

For most WordPress users, using a plugin is the easiest and safest method since tampering with your theme's code can break your site if you're not careful.

Method 1: Using a Plugin (Recommended)

  1. From your WordPress dashboard, go to Plugins > Add New.
  2. Search for the official "Google Site Kit" plugin. Other popular options include "MonsterInsights" or "GA Google Analytics."
  3. Install and activate the plugin of your choice.
  4. Follow the plugin’s setup instructions. It will usually prompt you to connect your Google account. Authenticate your account, and the plugin will automatically fetch your GA4 property and place the tracking code on every page of your site.
  5. Important: If you had an older plugin or system for Universal Analytics, be sure to deactivate and delete it to remove the old tracking code.

Method 2: Editing Your Theme Files (Advanced)

This method should only be used if you are comfortable editing PHP files and have a child theme set up to prevent losing your changes during a theme update.

  1. First, find and remove your old UA tracking script. It was likely in the same file.
  2. Copy the full Google tag script from your GA4 Data Stream instructions.
  3. In your WordPress dashboard, navigate to Appearance > Theme File Editor.
  4. On the right, find and click on the header.php file.
  5. Carefully paste your new GA4 Google tag snippet right after the opening <head> tag.
  6. Click Update File to save your changes.
GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

For Shopify Stores

Shopify makes it incredibly easy to add your GA4 tag. They have a dedicated section for it in the settings.

  1. From your Shopify Admin dashboard, go to Online Store > Preferences.
  2. Scroll down to the Google Analytics section. If you see an old "UA-" code there, delete it.
  3. Click on Manage pixel here. This will take you to your sales channel settings.
  4. Click the Connect button next to your Google sales channel, or add the channel if you haven’t already. Authenticate with your Google account.
  5. During setup, Shopify will guide you to select the correct GA4 Measurement ID ("G-...") from a dropdown. It will automatically detect the properties linked to your account.
  6. Once connected, Shopify handles the rest, including adding e-commerce event tracking.

Using Google Tag Manager (The Most Flexible Method)

Google Tag Manager (GTM) acts as a container for all your marketing and analytics tags. If you are already using GTM, updating to GA4 is much simpler and doesn't require touching your website's code.

  1. Log in to your Google Tag Manager account and select your website’s container.
  2. Navigate to the Tags section. Find your old "Universal Analytics" pageview tag. Click on it, and in the top-right corner, click the three-dot menu and select Pause (or Delete if you're sure you are done with it).
  3. Click New to create a new tag. Name it something clear, like "GA4 - Pageview Tag."
  4. Click inside the Tag Configuration box and choose Google Analytics: GA4 Configuration.
  5. In the Measurement ID field, paste the "G-" ID you copied from your GA4 property.
  6. Leave the "Send a page view event when this configuration loads" box checked.
  7. Next, click inside the Triggers box and select the All Pages trigger. This ensures the tag fires on every page load.
  8. Save the tag.
  9. Finally, click the blue Submit button in the top-right corner of GTM. Add a version name (e.g., "Added GA4 Config Tag") and click Publish. Your changes are now live.

For Other Platforms or Custom-Coded Sites

If your website is built on another platform (Squarespace, Wix, custom HTML/CSS), the general steps remain the same:

  1. Find the Old Code: Locate where the old "UA-" tracking script was pasted. Common places include a dedicated "Marketing Integrations" or "Custom Code" section in your site's settings, or hardcoded into the <head> section of your site's template files.
  2. Remove It: Delete the entire old script block.
  3. Add the New Code: Copy the full GA4 Google tag (the entire <script> block) and paste it in the same general area, preferably immediately after the opening <head> tag on every page you want to track.

Step 3: Verify Your Setup is Working Correctly

You’ve changed the code, but how do you know it’s working? The GA4 Realtime report is your best friend here.

  1. Go to your GA4 property in Google Analytics.
  2. On the left-hand navigation, click Reports > Realtime.
  3. In a new browser window or tab, open your website and browse a few pages. If you can use a different device, like your phone (not connected to wifi), it can make it easier to spot your visit.
  4. Switch back to the GA4 Realtime report. Within about 30-60 seconds, you should see your visit appear. You'll see a spike in the "Users in Last 30 Minutes" chart and a dot on the world map showing your location.

If you see your activity, congratulations! You've successfully changed your tracking code. Data will now start flowing into your new GA4 property.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Final Thoughts

Changing your Google Analytics tracking code is a standard task, especially with the industry-wide shift to GA4. By following the right method for your platform - be it a WordPress plugin, your Shopify settings, or Google Tag Manager - and verifying the setup with the Realtime report, you can ensure a smooth transition and maintain the accuracy of your website data.

Once your analytics data is flowing in correctly, the next challenge is making sense of it all. Instead of spending hours trying to wrangle GA4's interface to answer your questions, we built Graphed to do the heavy lifting for you. We allow you to connect your Google Analytics account in just a few clicks and start asking questions in plain English — like "create a report showing sessions by channel for the last 90 days" or "which landing page has the best conversion rate?" — and get dashboards and reports built instantly. It removes the friction from data analysis, so you can get back to taking action.

Related Articles