Google announced that Universal Analytics is going away. There is little to do if you use it as your primary analytics solution. You should switch from Universal Analytics to Google Analytics 4 as soon as possible.
There are at least a few ways how to do it. Therefore, I recommend you to look at my other post, “How to upgrade to Google Analytics 4”, where I mentioned all of them.
In this article, I will guide you on upgrading to Google Analytics 4 using your existing analytics.js setup.
What’s analytics.js, and how to check if you are using it?
Analytics.js is a Google Analytics javascript library that sends the behaviour information from your website into Google Analytics 3 (Universal Analytics).
It was created a while ago and used before GTAG.js, the current primary Google tag solution. If you set up Universal Analytics before the 2018 year and you didn’t use Google Tag Manager, most likely, you are using Analytics.js.
If you want to check if it’s true. You should visit your website and check the source code of the page and see if the page has the following code.
<!-- 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 it has, you are using Analytics.js library. If you don’t see it, I recommend you look at my other post, “How to upgrade to Google Analytics 4”, since most likely you are using another solution for Universal Analytics, and this article is not entirely relevant to you.
So, now, after we are on the same page that you are using it, let’s discuss how to use analytics.js library to migrate to Google Analytics 4.
How to migrate to GA4 using Analytics.js
First of all, you should know there is no possibility to transit your analytics.js setup into Google Analytics 4 fully. GA4 allows you to track only the following UA hits:
- custom events
- timing
- exception calls.
Therefore, you will need anyway to change your pageview tag into a custom event, or you will need to add gtag.js library for the page view tag on your website.
So, for instance, if you have analytics.js code for pageview like that below,
<!-- 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', ‘UA-ID’, 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics —>
You can change it to 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', ‘GA4_Measurement_ID');
</script>
However, all your Analytics.js tags in the following format will reach your GA4 property.
So, for instance, I have this code to track the UA event.
ga('send', 'event', event_category, event_action, event_label, 1);
Google Analytics 4 will automatically detect this code and send it to the right GA4 property.
There is just one crucial step that we should do to activate Analytics.js event tracking in GA4. We should go to:
- GA4 -> Admin -> Data Streams -> Web Data Stream Details -> Configure Tag Settings -> click on “Show all”
- Activate “Collect Universal Analytics events”.
After we activate this, all events that you send into Universal Analytics using Analytics.js library will be automatically sent to the right GA4 property. Yes, it’s so easy and so fast!
You can see my UA event in Universal Analytics and Google Analytics 4. GA4 reads the analytics.js library and uses event action as the name for the event, and event category, event label and event value as the event properties.
If you want to use these properties, you should set them up as a custom dimension or metric in Google Analytics 4.
Final Word
If you use Analytics.js library for Universal Analytics, there is a way to transit 99% of your setup into Google Analytics 4 using one of the GA4 features. In this article, I walked you through each and every step. If you found this article helpful or have a question, please don’t hesitate to comment below.
Yes, it’s possible to migrate almost 99% of all your Analytics.js setup to Google Analytics 4. You should activate “Collect Universal Analytics events” feature in GA4.
You Might Also Like
Written By
Ihar Vakulski
With over 8 years of experience working with SaaS, iGaming, and eCommerce companies, Ihar shares expert insights on building and scaling businesses for sustainable growth and success.
KEEP LEARNING
Achieving 100% Accurate Booking Reporting in GA4 After sGTM Migration – The Q Train
The following is a glimpse into the success stories of our clients. Ready to see how we can empower your business? Reach out to us
Feature Adoption Metrics: Boost Your Product’s Performance
One of the key factors that can make or break a product’s success is the user experience, which largely depends on how a user interacts
Leave a Comment
Your email address will not be published. Required fields are marked *
Stay Updated About Every New GA4 Feature
Subscribe to this newsletter to learn more about new Google Analytics 4 features and adjustments.
No SPAM and only relevant content guaranteed!