GA4 with Server-Side Tracking
Learn how to implement Google Analytics 4 server-side tracking with Hardal for improved data accuracy and privacy
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:
-
Admin access to Google Analytics 4 and Google Tag Manager
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
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: Disabled
-
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
- Configure with the following settings
- 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