GA4 with Server-Side Tracking
Learn how to implement Google Analytics 4 server-side tracking with Hardal for improved data accuracy and privacy
Configuring GA4 with Server-Side Tracking
Overview
This guide explains how to set up Google Analytics 4 (GA4) server-side tracking using Hardal. Server-side tracking improves data accuracy, enhances privacy compliance, and helps bypass ad blockers by moving data collection from the browser to a server environment.
Server-side tracking doesn’t replace your existing GA4 implementation entirely. It changes where and how the data is processed before being sent to Google Analytics.
Prerequisites
Before you begin, ensure you have:
-
A Hardal account with access to server-side hosts
-
Admin access to Google Analytics 4
-
Admin access to Google Tag Manager (optional but recommended)
-
Basic understanding of GA4 implementation
-
A website with Hardal tracking script already implemented
This guide assumes you have already implemented the Hardal tracking script on your website. If you haven’t done this yet, please refer to the Hardal Website Installation guide first.
Why Use Server-Side Tracking for GA4?
Server-side tracking offers several advantages over traditional client-side implementation:
Feature | Client-Side | Server-Side |
---|---|---|
Ad-blocker resilience | Vulnerable to blocking | Highly resilient |
Data accuracy | Can be affected by browser issues | More accurate |
Privacy compliance | Exposes user data in browser | Better data control |
Site performance | Impacts page load times | Minimal client impact |
Data control | Limited processing options | Advanced processing |
Implementation Steps
Set Up Hardal Server-Side Host
-
Log into your Hardal dashboard
-
Navigate to “Server-Side Hosts”
-
Click “Deploy” for the “Server-side Google Tag Manager” option
-
Enter your GTM Container Configuration Key in the “Config Key” field
Find this key in GTM under Admin > Container Settings > Container Config
-
Click Save to complete the setup
-
Copy the generated Tagging URL from Hardal and add it to your GTM server container settings
Configure GA4 Client in Server Container
In your server-side GTM container:
-
Go to “Clients” and click the built-in “GA4” client
-
Configure with the following settings:
-
Priority: 0 (default)
-
Default GA4 paths: Enabled
-
Default gtag.js paths: Enabled with your GA4 Measurement ID(s)
-
Automatically serve dependent scripts: Enabled
-
Compress HTTP response: Enabled
-
Enable region-specific settings: Enabled with Visitor Region variable
-
Cookies and Client Identification: JavaScript Managed
-
-
Save your client configuration
Create GA4 Server Tag
-
In your server container, go to “Tags” and click “New”
-
Select “Google Analytics: GA4” as the tag type
-
Leave default settings (the tag will inherit values from the client)
-
Create a custom trigger that fires on “Some Events” where “Client Name equals GA4”
-
Name and save your tag (e.g., “GA4 Server Tag”)
Configure Web Container Tag
In your client-side GTM container:
-
Create a new “Google Tag” tag
-
Enter your GA4 measurement ID
-
Add a configuration parameter:
-
Name: server_container_url
-
Value: Your Hardal sGTM Tagging URL (from the Server-Side Hosts page)
-
-
Add appropriate triggers (e.g., All Pages)
-
Save and publish your container
For optimal performance and first-party data collection, set up a custom domain for your Hardal endpoint before implementation.
Validation and Testing
After setting up server-side tracking, validate your implementation:
Test in Preview Mode
-
Enable Preview mode in your web container
-
Enable Preview mode in your server container
-
Navigate to your website
-
Verify events are being received by the server container
-
Confirm the GA4 tag is firing in the server container
Check Real-Time Reports
-
Open GA4 Real-Time reports
-
Perform actions on your website (page views, events)
-
Verify the events appear in the real-time report
If using parallel measurement (both client and server), you’ll need to check both GA4 properties.
Validate Event Parameters
Ensure critical parameters are being passed correctly:
-
Check that user_id and client_id are being preserved
-
Verify custom parameters are included in events
-
Confirm engagement metrics (engagement_time_msec, session_id) are present
Enhanced Features
Enabling Enhanced Measurement
To take full advantage of GA4’s enhanced measurement capabilities with server-side tracking:
-
Configure User ID through the server container for cross-device tracking
-
Set up enhanced e-commerce parameters in your data layer
-
Implement custom dimensions and metrics for business-specific analysis
Troubleshooting
Best Practices
Parallel Implementation
During the transition to server-side tracking:
-
Set up dual tracking with both client-side and server-side implementations
-
Compare data between the two implementations
-
Gradually shift from client-side to server-side as you validate results
-
Remove client-side tracking only after confirming data parity
Performance Optimization
To maximize server-side tracking efficiency:
-
Minimize unnecessary events to reduce processing load
-
Implement event batching for high-frequency interactions
-
Use a custom domain for improved reliability and first-party context
-
Configure appropriate caching for static resources