Google Analytics 4 Setup & Guide -- Complete GA4 Implementation Handbook
Google Analytics 4 (GA4) is an event-based analytics platform that replaces Universal Analytics, offering cross-platform tracking, Machine Learning insights, and privacy-focused data collection for modern web and app measurement.
What You'll Learn
In this tutorial, you will learn how to create and configure a GA4 property, implement event tracking via gtag.js and Google Tag Manager, set up custom dimensions and conversions, export data to BigQuery, and build custom reports using GA4 Explorations.
Why It Matters
Universal Analytics stopped processing data in July 2024. GA4 is the only Google Analytics platform moving forward. Its event-based data model, cross-platform tracking across web and mobile, built-in privacy controls, and free BigQuery export make it fundamentally different from UA. Companies still on UA have no historical data collection and must rebuild their analytics infrastructure from scratch.
Real-World Use
Doda Browser uses GA4 to track cross-platform usage across Windows, macOS, Android, and iOS with 42 custom events covering feature adoption, crash rates, and performance metrics. Data exports to BigQuery daily for custom SQL analysis alongside internal data pipelines that feed a Grafana dashboard for real-time product monitoring.
GA4 Architecture
flowchart TD
A[Website] --> B[gtag.js / GTM]
C[Android App] --> D[Firebase SDK]
E[iOS App] --> D
B --> F[GA4 Property]
D --> F
F --> G[Standard Reports]
F --> H[Explorations]
F --> I[BigQuery Export]
F --> J[Google Ads Integration]
F --> K[Audiences]
F --> L[Predictive Metrics]
K --> M[Google Ads Remarketing]
Creating a GA4 Property
Navigate to Admin > Create Property and configure your property with the correct time zone and currency settings:
// GA4 configuration tag with recommended settings
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag("js", new Date());
gtag("config", "G-XXXXXXXXXX", {
cookie_flags: "SameSite=None;Secure",
cookie_domain: "example.com",
allow_ad_personalization_signals: false,
restricted_data_processing: false,
});
Expected behavior: The gtag snippet initializes GA4 with your measurement ID. The cookie_flags parameter enables secure cross-domain tracking. The allow_ad_personalization_signals setting controls advertising features.
Event Tracking with Google Tag Manager
GTM provides a tag management layer without editing source code:
// dataLayer push for custom GA4 event via GTM
dataLayer.push({
event: "feature_activated",
feature_name: "batch_compress",
feature_category: "compression",
user_tier: "pro",
activation_source: "sidebar_button",
activation_duration_seconds: 2.3,
});
In GTM, create a GA4 Event tag with your measurement ID, set event name to feature_activated, and configure a trigger that fires on the Custom Event feature_activated. Map the dataLayer parameters to GA4 event parameters.
Custom Dimensions and Metrics
Register custom dimensions in GA4 Admin > Custom Definitions before sending data:
// Send event with registered custom parameters
gtag("event", "trial_converted", {
trial_id: "TRIAL-202606-8842",
trial_length_days: 14,
product_name: "DodaZIP Pro",
conversion_type: "credit_card",
conversion_value: 29.99,
currency: "USD",
account_type: "individual",
});
// Set user-scoped properties
gtag("set", "user_properties", {
plan_type: "enterprise",
account_age_days: 365,
region: "EU",
marketing_opt_in: true,
});
Expected output: The event appears in GA4 Realtime report within seconds. User properties persist across sessions and appear in audience definitions. Unregistered parameters appear only in BigQuery raw export, not in standard reports.
BigQuery Export and SQL Analysis
Connect GA4 to BigQuery for custom analysis:
-- Query daily active users by country from GA4 BigQuery export
SELECT
event_date,
geo.country AS country,
COUNT(DISTINCT user_pseudo_id) AS daily_active_users,
COUNT(DISTINCT CASE WHEN event_name = 'purchase' THEN user_pseudo_id END) AS purchasers,
SAFE_DIVIDE(
COUNT(DISTINCT CASE WHEN event_name = 'purchase' THEN user_pseudo_id END),
COUNT(DISTINCT user_pseudo_id)
) AS purchase_rate
FROM `project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20260601' AND '20260622'
AND geo.country IS NOT NULL
GROUP BY event_date, geo.country
ORDER BY event_date, daily_active_users DESC;
Expected output: A daily time series showing DAU and purchase rate by country, enabling geographic performance comparisons and identifying underperforming markets for targeted optimization.
Predictive Metrics Configuration
GA4 provides predictive metrics for churn probability and purchase probability:
// Enable predictive metrics via gtag configuration
gtag("config", "G-XXXXXXXXXX", {
allow_ad_personalization_signals: true,
});
// Track purchase event for predictive model training
gtag("event", "purchase", {
Transaction_id: "TXN-20260623-001",
value: 49.99,
currency: "USD",
items: [
{
item_id: "DZ-PRO-ANNUAL",
item_name: "DodaZIP Pro Annual",
category: "Software Subscription",
price: 49.99,
quantity: 1,
},
],
});
Expected behavior: GA4 requires at least 30 days of purchase data and 1000 positive events before predictive metrics become available in Audiences. The model improves as more conversion data accumulates.
Tool Comparison
| Feature | GA4 | Universal Analytics | Mixpanel | Plausible |
|---|---|---|---|---|
| Data model | Event-based | Session + pageview | Event-based | Event-based |
| Cross-platform | Web + mobile | Web only | Web + mobile | Web only |
| BigQuery export | Free | Paid 360 only | No | No |
| ML insights | Built-in | Limited | Yes | No |
| Data retention | 2-14 months | 26-50 months | 5 years (paid) | Unlimited |
| Sampling | Free tier sampled | Free tier sampled | No sampling | No sampling |
| Cost | Free | Free (discontinued) | Paid | Self-hosted free |
Common Errors
1. Duplicate Event Counting from GTM and gtag.js
Running both gtag.js in the page header and a GA4 tag in GTM sends duplicate page views. Remove the inline gtag.js snippet when using GTM exclusively.
2. Missing Internal Traffic Exclusion
Internal team visits inflate metrics. Configure a data filter in Admin > Data Settings > Data Filters to exclude internal IP addresses or set a debug_mode parameter that you strip in reporting.
3. Unregistered Event Parameters
Sending parameters not registered in GA4 Admin > Custom Definitions causes them to appear as "not set" in standard reports. Register each parameter with the correct scope (Event, User, Session) before sending data.
4. Cross-Domain Tracking Not Configured
Users moving between domains (blog.example.com to app.example.com) appear as separate sessions without cross-domain tracking. Configure the cookie_domain parameter or use GTM tag settings to link domains.
5. Sampling in Standard Reports
GA4 applies sampling to standard reports when the number of events in a date range exceeds thresholds. For unsampled data, use BigQuery export or limit date ranges in Explorations.
Practice Questions
1. What is the fundamental difference between GA4 and Universal Analytics? GA4 uses an event-based data model where every interaction is an event with parameters, replacing UA's session-based model with separate page view, event, and Transaction hit types. GA4 also supports cross-platform tracking and free BigQuery export.
2. How do you Register custom dimensions in GA4? Navigate to Admin > Custom Definitions, click Create Custom Dimension, enter a name, select the scope (Event, User, or Session), and enter the parameter name exactly as it appears in your tracking code. Registration must happen before data collection begins.
3. What does enhanced measurement track automatically in GA4? Page views, scrolls (90% depth), outbound clicks, site search, video engagement (embedded YouTube), and file downloads (.pdf, .zip, .exe, .docx). These require no additional tracking code.
4. How does BigQuery export work with GA4 properties?
GA4 exports raw event data daily to BigQuery in sharded tables named events_YYYYMMDD. The export includes all event parameters, user pseudo-IDs, timestamps, and device information. No additional cost beyond BigQuery storage and query fees.
5. Challenge: Set up a GA4 property with three data streams (web, Android, iOS). Implement six custom events with registered parameters, mark three as conversions, create two audiences based on conversion conditions, connect BigQuery export, and write a SQL query that calculates 7-day purchasing power by traffic source.
Mini Project
Build a complete GA4 instrumentation Strategy for a SaaS product. Create a GA4 property with enhanced measurement enabled. Configure GTM with tags for page views, signup events, feature activations, and purchase events. Register five custom dimensions and three custom metrics. Set up BigQuery export and write SQL queries that calculate user retention cohorts, feature adoption rates, and conversion funnel analysis. Create three audiences for remarketing: high-value purchasers, trial users nearing expiration, and users with high churn probability.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro