From analytics.js to GA4: How Web Measurement Has Changed in Google Analytics
For many years, analytics.js was one of the most important components in the Google Analytics ecosystem. For those who worked with Universal Analytics, this script was the connection point between a website and Google’s measurement servers. Its main function was to load the tracking library, create a tracker, identify sessions, read or set cookies, and send hits such as pageviews, events, or transactions.
However, referring to analytics.js as the core of Google Analytics is no longer accurate. Today, modern web measurement is built around Google Analytics 4, the Google tag, gtag.js, Google Tag Manager, and, in more advanced projects, server-side implementations or the Measurement Protocol.
This change is not only technical. It also represents a shift in how digital analytics is understood: we moved from a model mainly based on sessions, pageviews, and hits to a model centered on events, users, consent, privacy, and integrated signals across websites, apps, and advertising platforms.
01What Was analytics.js?analytics.js was the JavaScript library used by Universal Analytics to collect information from a website and send it to Google Analytics...
What Was analytics.js?
analytics.js was the JavaScript library used by Universal Analytics to collect information from a website and send it to Google Analytics. A classic implementation looked like this:
In simpler terms, this code did three main things:
- Loaded the
analytics.jslibrary asynchronously. - Created a tracker associated with a Universal Analytics property.
- Sent a pageview when the user loaded the website.
The most representative line was this one:
This created a tracker using a property identifier such as UA-XXXXX-Y. The auto parameter instructed Google Analytics to automatically configure the cookie domain, which was useful when measuring a main website and its subdomains under the same session logic.
Then came this instruction:
This line sent a pageview hit. In Universal Analytics, a hit was a unit of information sent to Google Analytics. It could be a pageview, an event, a transaction, a social interaction, timing data, or another type of interaction.
02Why analytics.js Should No Longer Be Used as the Basis for a New ImplementationThe issue is not that analytics.js was a bad technology. On the contrary, it was an essential part of web analytics for many years. The i...
Why analytics.js Should No Longer Be Used as the Basis for a New Implementation
The issue is not that analytics.js was a bad technology. On the contrary, it was an essential part of web analytics for many years. The issue is that it belongs to Universal Analytics, a model that has already been replaced by Google Analytics 4.
Therefore, if you are currently building a website, online store, blog, landing page, or digital measurement strategy, you should not start with analytics.js or with properties that use the UA-XXXXX-Y format.
A modern implementation should start with a GA4 property, whose measurement ID usually follows this format:
A direct installation with the Google tag looks like this:
This snippet no longer uses ga(). Instead, it uses gtag(). That difference is important because it reflects the transition from Universal Analytics to Google’s current tagging platform.
03What Is gtag.js?gtag.js is the JavaScript framework that allows Google tags to be added directly to a website. Its purpose is to send data to products su...
What Is gtag.js?
gtag.js is the JavaScript framework that allows Google tags to be added directly to a website. Its purpose is to send data to products such as Google Analytics 4 and Google Ads.
One of its advantages is that it allows you to install a single Google tag and send information to different destinations within Google’s ecosystem. For example, it can be used to measure visits, events, conversions, and advertising performance.
However, gtag.js requires more technical intervention. If you need to customize events, parameters, conversions, or advanced configurations, you usually have to modify the website code directly. For this reason, although gtag.js is valid, many projects benefit from using Google Tag Manager instead.
04Google Tag Manager: A More Flexible Option for Marketing and MeasurementGoogle Tag Manager is a tag management system that allows you to install, modify, and control measurement scripts from a web interface wi...
Google Tag Manager: A More Flexible Option for Marketing and Measurement
Google Tag Manager is a tag management system that allows you to install, modify, and control measurement scripts from a web interface without editing the website code every time.
This is especially useful for marketing teams, agencies, digital analysts, and businesses that manage several platforms at the same time: Google Analytics, Google Ads, Meta Pixel, TikTok Pixel, LinkedIn Insight Tag, heatmap tools, forms, custom conversions, and third-party scripts.
With Tag Manager, you can manage:
- Tags.
- Triggers.
- Variables.
- Custom events.
- Conversions.
- Advertising pixels.
- Consent implementations.
- Client-side and server-side tagging.
In practical terms, if a website only needs to measure basic visits, it can work with the Google tag installed directly. But if the project needs a serious measurement strategy, remarketing, conversions, ecommerce tracking, or paid campaign tracking, Google Tag Manager is usually the better option.
05The Most Important Change: From Hits to EventsOne of the biggest differences between Universal Analytics and GA4 is the data model.Universal Analytics was based on hit types. For exam...
The Most Important Change: From Hits to Events
One of the biggest differences between Universal Analytics and GA4 is the data model.
Universal Analytics was based on hit types. For example:
GA4, on the other hand, organizes measurement around events. Almost everything can be an event:
This allows for more flexible measurement, but it also requires better organization. In GA4, it is not enough to “measure everything.” The correct approach is to define an event architecture aligned with business objectives.
For example, for a blog you could measure:
For an online store, you could measure:
For a landing page, you could measure:
The key is that every event should have analytical intent. An event should help answer business questions, not simply fill reports with unnecessary data.
06Automatic, Recommended, and Custom EventsIn GA4, there are different levels of events.Automatic events are collected when the tag is correctly installed. Examples include first_v...
Automatic, Recommended, and Custom Events
In GA4, there are different levels of events.
Automatic events are collected when the tag is correctly installed. Examples include first_visit, session_start, and user_engagement.
Enhanced measurement can capture common interactions such as scrolls, outbound clicks, internal site searches, file downloads, or video engagement, depending on the data stream configuration.
Recommended events are event names suggested by Google for common business cases. Examples include purchase, login, sign_up, generate_lead, view_item, and add_to_cart.
Custom events are events you define when there is no automatic or recommended event that accurately represents the action you want to measure.
This structure requires a more strategic approach to analytics. Before creating custom events, it is better to check whether a recommended event already exists. This helps maintain cleaner measurement and better compatibility with GA4 reports.
07What Happened to Cookies?Cookies remain an important part of digital measurement, but the landscape has changed. Today, measurement cannot rely only on cookies be...
What Happened to Cookies?
Cookies remain an important part of digital measurement, but the landscape has changed. Today, measurement cannot rely only on cookies because browsers, privacy regulations, blockers, and user consent preferences affect data collection.
GA4, the Google tag, and Google Tag Manager operate in an ecosystem where consent plays a larger role. For that reason, a modern implementation should not be limited to simply “pasting the Analytics code.” It should also consider:
- Consent banner.
- Consent Mode.
- Cookie configuration.
- Privacy rules.
- Event quality.
- Internal traffic exclusion.
- Validation with DebugView.
- Testing with Tag Assistant.
- Measurement plan documentation.
Modern analytics is not just about collecting data. It is about collecting useful, permitted, consistent, and actionable data.
08What Is Measurement Protocol in GA4?Measurement Protocol allows events to be sent directly to Google Analytics servers through HTTP requests. This is useful when you need to...
What Is Measurement Protocol in GA4?
Measurement Protocol allows events to be sent directly to Google Analytics servers through HTTP requests. This is useful when you need to complement browser-based measurement with server-side events or offline interactions.
For example, Measurement Protocol can be used to send events related to:
- Payment confirmations from the backend.
- Leads validated in a CRM.
- Bookings confirmed outside the website.
- Offline interactions.
- Server-to-server processes.
- Events that do not depend directly on the browser.
However, Measurement Protocol should not be understood as a replacement for the Google tag, gtag.js, or Google Tag Manager. Its best use is to complement an existing measurement implementation, not replace it.
09Client-Side Tagging vs. Server-Side TaggingTraditionally, most tags ran in the user’s browser. This is known as client-side tagging. In this model, when a person visits a page, the...
Client-Side Tagging vs. Server-Side Tagging
Traditionally, most tags ran in the user’s browser. This is known as client-side tagging. In this model, when a person visits a page, the browser loads measurement scripts and sends requests to Google Analytics, advertising platforms, or other tools.
Server-side tagging adds an intermediate layer. Instead of sending all data directly from the browser to multiple providers, the data first passes through a server controlled by the company or technical team. From there, it can be processed, filtered, and distributed to the corresponding platforms.
This can improve control, governance, performance, and data quality. Even so, it is not a magic solution. It requires configuration, maintenance, infrastructure, costs, and technical judgment.
For many small websites, a clean client-side implementation with Google Tag Manager is enough. For ecommerce, media websites, SaaS companies, or businesses with high advertising investment, server-side tagging can become a natural evolution.
10Does Google Analytics Affect Website Speed?Yes, any external script can influence page performance. This applies to Google Analytics, Tag Manager, advertising pixels, chat widgets,...
Does Google Analytics Affect Website Speed?
Yes, any external script can influence page performance. This applies to Google Analytics, Tag Manager, advertising pixels, chat widgets, maps, embedded videos, external libraries, and third-party tools.
The correct point is not to say that “Google Analytics makes a website slow” in absolute terms. The right approach is to understand that every tag generates requests, processing, and additional load. That is why it is important to regularly audit which scripts are loaded, when they are loaded, and whether they are truly necessary.
Good practices include:
- Avoiding duplicate tags.
- Not installing GA4 directly and through GTM if both send the same events.
- Checking for duplicated events.
- Using Tag Assistant and DebugView.
- Loading only necessary tags.
- Documenting changes.
- Maintaining a measurement plan.
- Reviewing Core Web Vitals when adding external scripts.
A clean implementation measures better and has less impact on performance.
11Example of a Modern Basic GA4 ImplementationIf the project is simple, you can install the Google tag directly:<!-- Google tag (gtag.js) --><script async src="https://www.go...
Example of a Modern Basic GA4 Implementation
If the project is simple, you can install the Google tag directly:
Then you can add events when an important action occurs:
But if the website needs to measure campaigns, forms, buttons, conversions, ecommerce activity, or multiple platforms, the most recommended option is to use Google Tag Manager and centralize tag management there.
12Conclusionanalytics.js was a fundamental piece in the history of Google Analytics, but it no longer represents the present of digital measurement....
Conclusion
analytics.js was a fundamental piece in the history of Google Analytics, but it no longer represents the present of digital measurement. Its place belongs to Universal Analytics, while the current environment revolves around GA4, the Google tag, gtag.js, Google Tag Manager, events, consent, and more privacy-oriented measurement.
The challenge today is not simply installing a code snippet. The real challenge is designing a measurement architecture that answers business questions:
- Where do users come from?
- What actions do they perform?
- What content generates the most interest?
- Which campaigns produce results?
- Which events truly represent value?
- Where are opportunities being lost in the funnel?
- Which data can be trusted for decision-making?
Modern web analytics should no longer be seen as a script pasted into a website. It should be understood as an infrastructure for measurement, business intelligence, and continuous improvement.

0 comments
No published comments yet
Be the first to leave an opinion and rating on this article.