
November 22, 2023
How to Migrate a Basic Website to Google Analytics 4
With the processing of Universal Analytics (UA) data ending on July 1, 2023, it is imperative to migrate any of your existing UA properties to Google Analytics 4 (GA4). While data is still being processed in Universal Analytics for 360 customers, UA360 will no longer process data after July 1, 2024.
The sooner you migrate to Google Analytics 4, the sooner you familiarize yourself with the new UI and tools available!
This tutorial will cover why you should migrate to Google Analytics 4 and the steps you need to take to migrate from Universal Analytics to GA4 for a very basic setup, including some configurations in the GA4 interface.
Table of Contents
Here’s what you will learn in this article
- Why do I need to migrate to Google Analytics 4?
- Benefits of migrating to Google Analytics 4
- Different options for installing Universal Analytics (UA)
- How to migrate each of the options
- Removing Universal Analytics
- Final Words
Video Tutorial
If you prefer video content, then check out our YouTube channel!
Why do I need to migrate to Google Analytics 4?
For the free version of Universal Analytics, data stopped being processed on July 1, 2023. If you opted out of having your Universal Analytics properties automatically migrated to GA4, then you need to manually migrate your properties to continue collecting data on your site.
If you have Universal Analytics 360, then you have till July 1, 2024, to migrate your Universal Analytics properties to Google Analytics 4, as that’s when Universal Analytics will sunset and all data will be deleted.
There are many benefits to Google Analytics 4, so even if you have Universal Analytics 360, it is still recommended that you migrate to Google Analytics 4 as soon as you can.
Benefits of migrating to Google Analytics 4
While you will no longer have a choice about using Google Analytics 4 come July 1, 2024, there are many benefits to the updated platform, including Explorations, ad-hoc funnels, and a BigQuery integration for no extra cost.
Check out the article on the top 23 benefits of Google Analytics 4 to learn more about what you can expect after you complete the migration!
The earlier you make the migration, the more time you have to familiarize yourself with the updated platform before being obligated to use it solely for data analysis.

Different options for installing Universal Analytics
There are three different options for how Universal Analytics (GA3) could have been installed on your site.
- analytics.js
- gtag.js
- Google Tag Manager (GTM)
If the code in your site’s source code looks something like what’s shown below (with ga), then Universal Analytics was set up using analytics.js. This is no longer an option for Google Analytics 4, so you must set up your site with a different method.
<!-- Google Analytics --> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'TAG_ID', 'auto'); ga('send', 'pageview'); </script> <!-- End Google Analytics -->
If, in the source code, you see code that looks like what is posted below (with gtag), then Universal Analytics was implemented using gtag.js.
<!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'TAG_ID'); </script>
Lastly, if Universal Analytics was implemented with Google Tag Manager, you will see something like what is shown below in your source code (with googletagmanager). In this case, you will also find a configuration tag within your Google Tag Manager container.
<!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-XXXXXXXX');</script> <!-- End Google Tag Manager -->
In Google Analytics 4, you can only use two of these methods for your setup: gtag.js or Google Tag Manager.
How to migrate each of the options
Since using analytics.js is not a valid option for implementing Google Analytics 4 on your site, you must switch to either gtag.js or Google Tag Manager. If you currently use gtag.js on your site, you can either continue to use this option or switch to Google Tag Manager, which is the recommended method.
If you currently have Universal Analytics implemented with Google Tag Manager, then you will continue with this option for Google Analytics 4.
When choosing which option to migrate to Google Analytics 4, you only need to pick one path from the original method used to implement Universal Analytics.
After you have decided which option to proceed with, follow the relevant steps below! It’s important to note that the Google Analytics 4 interface changes frequently, so the location of certain aspects of the platform could change or look different from the time this article was written.
Step 1: Create a new Google Analytics 4 property
At this point, the migration to Google Analytics 4 is the equivalent of creating an entirely new property in your GA4 Account. Regardless of the method you use to migrate to Google Analytics 4, the first step will be to create a new property.
Log into Google Analytics and select the account where your current Universal Analytics property is located.
To create a new property, click “Admin” at the bottom of the left-hand navigation and click “Create”. Select “Property”.
Choose a new property name, such as the name of your business, and set the timezone.
You will be prompted to provide details about your business and objectives. Pick the options that best describe your site.
Once the property has been created, you must add at least one data stream. Select “Web” for the platform.
Enter the website URL and the same of your stream. Then, click on “Create stream”.
Now that your new Google Analytics 4 property is ready, you can move on to installing GA4 on your site!
Step 2: Install Google Analytics 4
Depending on how you currently have Universal Analytics installed on your site, the steps you take to migrate to Google Analytics 4 will differ. You can either use gtag.js or Google Tag Manager.
If you’re unsure which method would be best for you, read more about the comparison between gtag.js and Google Tag Manager.
Below, you can find step-by-step instructions for migrating to Google Analytics 4, depending on the method you used to install Universal Analytics. Choose one option that applies to your situation.
Step #2.1. If Universal Analytics is installed with analytics.js
If you currently have analytics.js, then you have two options:
- Use gtag.js to install GA4
- Or use Google Tag Manager to install Google Analytics 4.
Choose one. Not sure which one? Read this article.
Option #1 to install GA4: gtag.js
The first option is to install the Google tag manually with gtag.js.
Add gtag.js to the site’s source code
To find the Google tag for your new GA4 property, go to Admin and click on “Data Streams” under Data collection and modification.
Click on the data stream you need the Google tag for and navigate to the bottom of the screen. Under the Google Tag section, click on “View tag instructions”.
There will be two options: Install with a website builder or CMS or Install manually. The option you proceed with will be dependent on your site. If you use a common website builder, like GoDaddy or Shopify, then there are available integrations for installing your Google tag without the need for a developer.
If you choose to install the Google tag manually, you will need to provide the tracking code to a developer to install into the source code of your site. It is recommended to add it immediately after the <head> element.
Check out this Google guide on how to migrate from analytics.js to gtag.js if you need more guidance.
Check that gtag.js code was installed properly
It is very important to ensure that after the Google tag has been added to your site’s source code, it’s working properly. You can right-click on a page of your site, click on “View Page Source” and look for the Google tag (hint: you can click control-f and search for “gtag”).
Additionally, you can download the Google Analytics Debugger Chrome extension. Once the extension is downloaded, click on it to turn it on.
Once the extension is activated, you can go to the DebugView in Google Analytics 4 and ensure that there is data incoming. Read more about how to check if Google Analytics is working here.
Once you have confirmed that data is being collected, then you can move on to Step 3: Configure GA4 property.
Option #2 to install GA4: Google Tag Manager
The recommended option is to install Google Analytics 4 with Google Tag Manager. GTM provides you with more freedom and options when it comes to event tracking. After the initial installation, you can create new tags without having to rely on developers.
Create a new GTM account and container
If you have never used Google Tag Manager before, you must create a new account and a new container. To set up a new account, check out the Google Tag Manager tutorial for beginners (go to the “Create a Google Tag Manager Account” section).
Once you have created your GTM account and container, you can find the tracking code by clicking on the container ID on the Overview page.
You can provide this code to your developer to install it in the <head> of the source code for your site.
Create a Google Tag
To create the data flow from your site to Google Analytics 4, you need to create a Google Tag in your container.
In the left-hand menu, click on “Tags” and then “New”.
From here, click on “Tag Configuration”, then “Google Analytics” and then “Google Tag”.
Create a constant variable for Tag ID
To keep your container more organized, you will want to create a new Constant variable to hold the Tag ID. Click to add a new variable.
Then, click on the plus in the top right to create a new variable.
Click on Variable Configuration and select “Constant” as the variable type.
From the Admin section of the Google Analytics 4 property you created above, go to Data Streams and click on the stream to see the details, including the Measurement ID.
In the stream details, you will find the Measurement ID.
Copy the Measurement ID and paste it into the Value of the constant variable. Save your new variable as “Constant – G-XXXXXXXXXX” (or whatever makes sense to you). Read this blog post to learn more about the constant variable in Google Analytics 4.
Add trigger
Next, you should set up a trigger so that the Google Tag is loaded on each page of your site. Click “Triggering” at the bottom of the tab, and then click “Initialization – All Pages” to ensure the Google Tag is fired before all other triggers.
Now, you can name and save the Google Tag!
Check that GTM was installed properly
To check that the code was installed correctly, you can Preview your Google Tag Manager container to confirm that the tracking is in place using Tag Assistant.
Once you have entered your site and Tag Assistant has loaded, click on “Initialization” and confirm that the Google tag has fired.
You can also go to Debugview in Google Analytics 4 to confirm that there is incoming data.
Now that you have confirmed that the Google Tag has been correctly implemented, you can publish the container in Google Tag Manager to save your changes!
Step #2.2. If Universal Analytics is installed with gtag.js
If you currently have Universal Analytics installed with gtag.js and want to continue with this method, then you must replace the UA tracking ID in your site’s code with the new GA4 measurement ID.
The two lines of code you should update:
src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script> gtag('config', 'G-XXXXXXXXXX')
If you have Universal Analytics 360, you can keep the Universal Analytics tracking ID in the code to continue collecting data until July 1, 2024. Otherwise, you can remove the UA tracking ID.
To find the GA4 Measurement ID, go to the Admin section of the Google Analytics 4 property you created above, then Data Streams, and click on the stream to see the details, including the Measurement ID.
Copy the Measurement ID from the stream details.
The updated gtag.js code will be:
<!-- Google tag (gtag.js) --> <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>
Once the code has been updated, jump to this step Check the gtag.js code was installed properly above to see how to check that data is coming through.
If you want to migrate to Google Tag Manager too (the recommended method) rather than use gtag.js, follow the steps in this section: Install GA4 with Google Tag Manager above.
Step #2.3. If Universal Analytics is installed with Google Tag Manager
If you already use Google Tag Manager for Universal Analytics, jump to the section Create Google Tag and continue from there. You will not need to create any new container in GTM or install any new code.
In short, you will need to (1) create a new Google Tag for Google Analytics 4 and (2) test the container to ensure that the Google Tag was created correctly (which are detailed above).
Depending on whether your Universal Analytics property is still collecting data or not, you can keep or delete the UA configuration tag and any UA tags in your container.
Step 3: Configure GA4 Property
Lastly, to complete the basic setup of Google Analytics 4, there are some configurations that you want to update in your GA4 property.
Data Retention
The data retention in Google Analytics 4 is defaulted to two months, so you need to go into the Data Retention settings under Data collection and modification in the Admin settings to update this.
For each of your properties, you will need to ensure that the data retention for user-level data is set to 14 months, or else your data will not be available in GA4 after two months of its collection.
Data Filters
In the same section of the Admin settings, you can also find the Data Filters.
There is certain traffic that you can exclude from your data, including internal traffic (your own traffic) and developer traffic. It is recommended to exclude internal traffic in the basic setup for GA4.
To exclude internal traffic, Google Analytics 4 excludes any IP addresses that you have set to be associated with internal traffic. To learn more about how to do this, follow the steps outlined by Google to filter out internal traffic.
Setup Assistant
Lastly, under the Setup Assistant, which can be found in the Admin section, you can mark all tasks as complete to avoid GA4 updating anything within your property (beyond the basic setup).
Congratulations! You have successfully migrated from Universal Analytics to Google Analytics 4 and can begin exploring all the new features!
Removing Universal Analytics
You may or may not want to keep Universal Analytics on your site, depending on whether you are a GA360 customer. If you are not, you should remove Universal Analytics from your site once you have migrated to Google Analytics 4.
As a GA360 customer, you may want to keep your Universal Analytics properties running until July 1, 2024. After this date, you will also need to remove Universal Analytics from your site since data will no longer be collected.
The process to remove Universal Analytics on the method used to install UA and the option chosen for migrating to Google Analytics 4:
- If Universal Analytics was installed with analytics.js, you should remove the analytics.js code from the site after migrating to Google Analytics 4 using either gtag.js or Google Tag Manager.
- If both Universal Analytics and Google Analytics 4 are installed with gtag.js, then you need to remove any mentions of the UA tracking ID in the gtag.js code (since you just need to update the code to be used for GA4).
- If Universal Analytics was installed with gtag.js and Google Analytics 4 was installed with Google Tag Manager, you will need to remove the gtag.js code from your site.
- If Universal Analytics and Google Analytics 4 are installed with Google Tag Manager, you should remove the UA Configuration tag and any UA events from the GTM container.
How to migrate a basic website to Google Analytics 4: Final Words
Hopefully, this tutorial has provided all the information needed to complete a basic migration from Universal Analytics to Google Analytics 4. It is important to note that while using analytics.js to install UA was possible, it is no longer a viable method to install GA4.
To migrate to Google Analytics 4, you must either install the gtag.js code into your site’s source code or use Google Tag Manager (the recommended method). Both of these methods will require the help of a developer (unless you use a common website builder, which may have a built-in feature for GA4).
If you see yourself needing a more flexible solution for your site tracking needs, then it may be worthwhile to take this opportunity and switch to Google Tag Manager while migrating to Google Analytics 4.
If you are ready to go beyond the basic setup for Google Analytics 4, check out the Google Analytics 4 Course where you will learn how to get more insights from your data!
0 COMMENTS