Master Google Analytics 4 with this comprehensive 2025 setup guide. Learn event-based tracking, key events (formerly conversions), eCommerce implementation, and Next.js integration with GDPR-compliant configuration.
Key Takeaways
- Event-Based Model Revolution: GA4 tracks everything as events, providing more flexibility and granularity than Universal Analytics' session-based tracking. Even page views are now events.
- Key Events Replace Conversions: Google renamed 'Conversions' to 'Key Events' in 2024. Mark important actions like purchases, form submissions, and downloads as key events to measure business success.
- Enhanced Google Ads Integration: Use recommended events whenever possible for better integration with Google Ads and built-in GA4 reports, especially critical for eCommerce tracking.
- Automatic Event Tracking: GA4 automatically tracks page views, scrolls, outbound clicks, site searches, video engagement, and file downloads without manual configuration.
- GDPR Compliance Built-In: GA4 includes enhanced privacy controls with consent mode, IP anonymization by default, and data deletion capabilities for regulatory compliance.
What is Google Analytics 4?
Google Analytics 4 (GA4) is the latest generation of Google's web analytics platform, replacing Universal Analytics which was sunset in July 2023. GA4 represents a fundamental shift in how we track and understand user behavior on websites and mobile apps.
Key Differences from Universal Analytics
- Event-Based Model: Everything is tracked as an event, providing more flexibility than the session-based model
- Cross-Platform Tracking: Unified tracking for web and mobile apps in a single property
- AI-Powered Insights: Machine learning predicts user behavior and identifies trends automatically
- Privacy-First Design: Built-in privacy controls and compliance with GDPR and other regulations
- Enhanced Integration: Deeper connection with Google Ads for better attribution
Universal Analytics was sunset in July 2023, and as of 2025, GA4 is now the standard analytics platform used by millions of websites worldwide. GA4 has achieved widespread adoption with mature documentation and extensive community support.
Setting Up GA4 Property
Creating a GA4 property is straightforward, but proper configuration from the start saves significant troubleshooting later.
Step 1: Create GA4 Property
- Navigate to Google Analytics and click Admin
- In the Property column, click Create Property
- Enter your property name and reporting timezone
- Select your industry category and business size
- Choose your business objectives (this customizes your reports)
Step 2: Set Up Data Stream
Data streams are how GA4 receives data from your website or app. For web properties:
- Select Web as your platform
- Enter your website URL and stream name
- Enable enhanced measurement (tracks page views, scrolls, outbound clicks, site search, video engagement, and file downloads automatically)
- Copy your Measurement ID (format: G-XXXXXXXXXX)
Pro Tip: Enable enhanced measurement from day one. It tracks common interactions automatically without requiring code changes, giving you valuable data immediately.
Step 3: Install Tracking Code
You can install GA4 tracking using Google Tag Manager (recommended for flexibility) or directly via gtag.js. For direct implementation, add this to your site's <head>:
<!-- 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>
Event Tracking Fundamentals
GA4's event-based model means every interaction is tracked as an event with parameters. Even a simple page view is an event named page_view.
Event Categories
Automatically Collected Events: These events are tracked automatically when you install GA4: page_view, session_start, first_visit, user_engagement, and more. No configuration needed.
Enhanced Measurement Events: When enabled, tracks scroll (90% page scroll), click (outbound links), view_search_results, video_start, video_progress, video_complete, and file_download events.
Recommended Events: Google's predefined events with specific names and parameters: login, sign_up, purchase, add_to_cart, etc. Use these for better Google Ads integration.
Custom Events: Events you create with your own names and parameters. Only use when no recommended event fits your needs.
Tracking Custom Events
To track a custom event, use the gtag function:
// Basic event tracking
gtag('event', 'button_click', {
'event_category': 'engagement',
'event_label': 'cta_button',
'value': 1
});
// Recommended event (login)
gtag('event', 'login', {
'method': 'Google'
});
Best Practice: Always use recommended events when possible. They integrate seamlessly with Google Ads and appear in built-in GA4 reports without custom configuration.
Configuring Key Events
In 2024, Google renamed "Conversions" to "Key Events" across GA4. Key events are important actions that measure business success: purchases, form submissions, sign-ups, downloads, etc.
How to Mark Events as Key Events
- Navigate to Admin in GA4
- Select Data Display, then Events
- Find the event you want to mark (it must have been triggered at least once)
- Toggle the star icon to mark it as a key event
- Key events appear in conversion reports and Google Ads
Important: Events must be tracked at least once before you can mark them as key events. Set up event tracking first, test it, then configure key events.
Common Key Events to Track
- eCommerce: purchase, add_to_cart, begin_checkout
- Lead Generation: generate_lead, form_submit, contact_request
- Engagement: sign_up, login, file_download
- Content: video_complete, scroll (90%), content_engagement
When you mark events as key events in GA4, they automatically sync to your linked Google Ads account as conversions. This enables conversion tracking, smart bidding optimization, and performance measurement directly in your ad campaigns without additional configuration.
eCommerce Tracking Setup
GA4 eCommerce tracking follows Google's recommended events standard, providing detailed revenue attribution and product performance insights. For businesses running online stores, proper eCommerce tracking is essential to understand customer behavior and optimize conversion rates.
Essential eCommerce Events
// View item
gtag('event', 'view_item', {
currency: 'USD',
value: 29.99,
items: [{
item_id: 'SKU_12345',
item_name: 'Premium Widget',
item_category: 'Widgets',
price: 29.99,
quantity: 1
}]
});
// Add to cart
gtag('event', 'add_to_cart', {
currency: 'USD',
value: 29.99,
items: [{
item_id: 'SKU_12345',
item_name: 'Premium Widget',
price: 29.99,
quantity: 1
}]
});
// Purchase
gtag('event', 'purchase', {
transaction_id: 'T_12345',
value: 29.99,
tax: 2.40,
shipping: 5.00,
currency: 'USD',
items: [{
item_id: 'SKU_12345',
item_name: 'Premium Widget',
price: 29.99,
quantity: 1
}]
});
eCommerce Event Sequence
- view_item_list: User views product category or search results
- view_item: User views product detail page
- add_to_cart: User adds item to shopping cart
- begin_checkout: User starts checkout process
- add_payment_info: User enters payment details
- purchase: Transaction completed successfully
Critical: Use exact recommended event names and parameters. Variations won't populate built-in eCommerce reports or sync properly with Google Ads.
Next.js Integration Example
Implementing GA4 in Next.js requires handling both server and client components. Here's a production-ready setup for Next.js 15.
1. Create GA4 Script Component
// lib/analytics.tsx
import Script from 'next/script';
export function GoogleAnalytics() {
const GA_ID = process.env.NEXT_PUBLIC_GA_ID;
if (!GA_ID) return null;
return (
<>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_ID}', {
page_path: window.location.pathname,
});
`}
</Script>
</>
);
}
2. Add to Root Layout
// app/layout.tsx
import { GoogleAnalytics } from '@/lib/analytics';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
<GoogleAnalytics />
</body>
</html>
);
}
3. Track Custom Events
// lib/analytics-events.ts
export const trackEvent = (
eventName: string,
eventParams?: Record<string, any>
) => {
if (typeof window !== 'undefined' && window.gtag) {
window.gtag('event', eventName, eventParams);
}
};
// Usage in components
import { trackEvent } from '@/lib/analytics-events';
function ContactForm() {
const handleSubmit = () => {
trackEvent('generate_lead', {
form_name: 'contact_form',
form_location: 'homepage'
});
};
}
4. Track Page Views (App Router)
// app/providers.tsx
'use client';
import { usePathname, useSearchParams } from 'next/navigation';
import { useEffect } from 'react';
export function AnalyticsProvider({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const searchParams = useSearchParams();
useEffect(() => {
if (pathname && window.gtag) {
window.gtag('config', process.env.NEXT_PUBLIC_GA_ID!, {
page_path: pathname + searchParams.toString(),
});
}
}, [pathname, searchParams]);
return <>{children}</>;
}
Custom Reports and Exploration
GA4's Exploration feature allows you to create custom reports that go beyond standard dashboards, providing deep insights into user behavior.
Popular Exploration Templates
Funnel Exploration: Visualize user drop-off at each step of key processes like checkout, sign-up, or onboarding. Identify where users abandon and optimize those steps.
Path Exploration: See the routes users take through your site. Discover common navigation patterns and unexpected user journeys.
User Lifetime: Analyze revenue and engagement over a user's lifetime. Critical for subscription businesses and SaaS products.
Creating Custom Dimensions
Custom dimensions let you add your own metadata to events for more detailed analysis:
- Navigate to Admin, then Data Display, then Custom Definitions
- Click Create Custom Dimension
- Name your dimension and select the event parameter it maps to
- Use in reports to segment data by your custom attributes
GDPR and Privacy Compliance
GA4 includes built-in privacy features, but you still need proper configuration to comply with GDPR, CCPA, and other privacy regulations.
Consent Mode Implementation
Google's Consent Mode allows GA4 to adjust its behavior based on user consent status:
// Set default consent state
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied'
});
// Update consent when user accepts
gtag('consent', 'update', {
'analytics_storage': 'granted',
'ad_storage': 'granted'
});
Privacy Settings in GA4
- IP Anonymization: Enabled by default in GA4 (unlike Universal Analytics)
- Data Retention: Configure how long user data is stored (2-14 months)
- Signals: Control Google Signals for cross-device tracking
- Data Deletion: Request deletion of specific user data via User-ID
Legal Requirement: Always implement a cookie consent banner and only enable analytics after receiving user consent. Consult with legal counsel for your specific jurisdiction.
Recommended Privacy Tools
- Cookiebot: Comprehensive consent management platform with GA4 integration
- OneTrust: Enterprise-grade privacy and consent management
- CookieYes: Affordable GDPR/CCPA compliance solution for small businesses
Start Tracking What Matters
Google Analytics 4 is now the standard for web analytics, and understanding its event-based model is essential for making data-driven decisions. The shift from Universal Analytics wasn't just a rebrand—it's a fundamental change in how we measure and understand user behavior.
Start with the basics: enable enhanced measurement, set up your key events, and implement recommended events for your business model. As you become comfortable with GA4's interface, explore custom reports and advanced features like predictive metrics and audience building.
Most importantly, ensure your implementation is privacy-compliant from day one. The data you collect is only valuable if it's gathered ethically and legally. With proper setup and configuration, GA4 provides the insights you need to optimize your digital presence and grow your business in 2025 and beyond.
Frequently Asked Questions
What's the difference between GA4 and Universal Analytics?
GA4 uses an event-based data model where everything is tracked as an event, while Universal Analytics used a session-based model with page views as the primary metric. GA4 offers cross-platform tracking, enhanced privacy controls, predictive metrics powered by machine learning, and better integration with Google Ads. Universal Analytics was sunset on July 1, 2023, making GA4 the only option going forward.
Do I need to keep Universal Analytics and GA4 running together?
No. Universal Analytics stopped processing new hits on July 1, 2023. You should have fully migrated to GA4 by now. If you haven't, you've lost historical data continuity. Set up GA4 immediately and focus on building new data history going forward.
How do I migrate Universal Analytics goals to GA4 key events?
Goals don't migrate automatically. In GA4, navigate to Admin, then Events, find the event you want to track as a key event (formerly called conversion), and toggle 'Mark as key event'. For eCommerce, use recommended events like 'purchase', 'add_to_cart', 'begin_checkout'. For lead generation, track 'generate_lead' or 'submit_form' events and mark them as key events.
How long does it take for data to appear in GA4?
Real-time data appears within seconds in the Realtime report. Standard reports typically process data within 24-48 hours. Some complex reports and conversions may take up to 72 hours to fully process. If you're not seeing data after 48 hours, verify your measurement ID is correctly implemented and check the DebugView for tracking issues.
Can I track users across my website and mobile app with GA4?
Yes, this is one of GA4's major advantages. Create a GA4 property and add both web and app data streams under the same property. Use User-ID to connect authenticated users across platforms. GA4 will automatically unify user journeys, showing you complete cross-platform behavior patterns in a single reporting interface.
Is GA4 GDPR compliant?
GA4 includes enhanced privacy features like IP anonymization by default, consent mode, and data deletion capabilities. However, GDPR compliance requires more than just using GA4—you must implement a cookie consent banner, update your privacy policy, sign Google's Data Processing Amendment, and configure consent mode correctly. Consider consulting with a privacy attorney to ensure full compliance with GDPR, CCPA, and other regional regulations.
Top comments (0)