GA4 vs Universal Analytics
Google officially retired Universal Analytics (UA), forcing every single web master to migrate to Google Analytics 4 (GA4).
The Fundamental Difference: Session vs Event
The core reason for this architectural shift lies in how data is conceptualized:
- Universal Analytics (Hit-Based): Built around Sessions and Pageviews. Every action is tied to a user session that expires after 30 minutes of inactivity.
- Google Analytics 4 (Event-Driven): Everything is an Event. A pageview is an event, a click is an event, even a session start is just an automatically collected event (
session_start).
Code Example: Simulating a Custom GA4 Event Tracker
// A pure Javascript simulation of GA4 event model
function logGA4Event(eventName, params = {}) {
const payload = {
event: eventName,
timestamp: Date.now(),
client_id: localStorage.getItem('_ga_client_id'),
properties: params
};
console.log("👉 Sending Event to GA4 Endpoint:", payload);
}
// Log a custom user fingerprint analysis action
logGA4Event('fingerprint_mismatch', {
browser: 'Chrome',
os: 'Windows',
risk_score: 85
});