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:

FeatureClient-SideServer-Side
Ad-blocker resilienceVulnerable to blockingHighly resilient
Data accuracyCan be affected by browser issuesMore accurate
Privacy complianceExposes user data in browserBetter data control
Site performanceImpacts page load timesMinimal client impact
Data controlLimited processing optionsAdvanced processing

Implementation Steps

1

Set Up Hardal Server-Side Host

  1. Log into your Hardal dashboard

  2. Navigate to “Server-Side Hosts”

  3. Click “Deploy” for the “Server-side Google Tag Manager” option

  4. Enter your GTM Container Configuration Key in the “Config Key” field

    Find this key in GTM under Admin > Container Settings > Container Config

  5. Click Save to complete the setup

  6. Copy the generated Tagging URL from Hardal and add it to your GTM server container settings

2

Configure GA4 Client in Server Container

In your server-side GTM container:

  1. Go to “Clients” and click the built-in “GA4” client

  2. 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

  3. Save your client configuration

3

Create GA4 Server Tag

  1. In your server container, go to “Tags” and click “New”

  2. Select “Google Analytics: GA4” as the tag type

  3. Leave default settings (the tag will inherit values from the client)

  4. Create a custom trigger that fires on “Some Events” where “Client Name equals GA4”

  5. Name and save your tag (e.g., “GA4 Server Tag”)

4

Configure Web Container Tag

In your client-side GTM container:

  1. Create a new “Google Tag” tag

  2. Enter your GA4 measurement ID

  3. Add a configuration parameter:

    • Name: server_container_url

    • Value: Your Hardal sGTM Tagging URL (from the Server-Side Hosts page)

  4. Add appropriate triggers (e.g., All Pages)

  5. 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:

1

Test in Preview Mode

  1. Enable Preview mode in your web container

  2. Enable Preview mode in your server container

  3. Navigate to your website

  4. Verify events are being received by the server container

  5. Confirm the GA4 tag is firing in the server container

2

Check Real-Time Reports

  1. Open GA4 Real-Time reports

  2. Perform actions on your website (page views, events)

  3. 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.

3

Validate Event Parameters

Ensure critical parameters are being passed correctly:

  1. Check that user_id and client_id are being preserved

  2. Verify custom parameters are included in events

  3. 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:

  1. Configure User ID through the server container for cross-device tracking

  2. Set up enhanced e-commerce parameters in your data layer

  3. Implement custom dimensions and metrics for business-specific analysis

Troubleshooting

Best Practices

Parallel Implementation

During the transition to server-side tracking:

  1. Set up dual tracking with both client-side and server-side implementations

  2. Compare data between the two implementations

  3. Gradually shift from client-side to server-side as you validate results

  4. Remove client-side tracking only after confirming data parity

Performance Optimization

To maximize server-side tracking efficiency:

  1. Minimize unnecessary events to reduce processing load

  2. Implement event batching for high-frequency interactions

  3. Use a custom domain for improved reliability and first-party context

  4. Configure appropriate caching for static resources