Server-Side Tracking via GA4 Measurement Protocol

Comprehensive GA4 Server-Side Tracking Guide covering technical setup, consent management, and solutions for common tracking issues.

What is GA4 Measurement Protocol?

The GA4 Measurement Protocol is a powerful tool that lets you send event data to Google Analytics directly from a server. Think of it as a way to track important user actions that happen behind the scenes, complementing the data you already collect through regular GA4 tracking.

Unlike platforms such as Meta or TikTok, this API doesn't function as an alternative to client-side tracking or a parallel tracking system. It relies on the GA4 property's browser library, which must be installed within the store for Measurement Protocol events to be successfully transmitted within a 72-hour window.

How Does It Work?

The process happens in four main steps:

1. When a user visits your website, GA4 creates two important IDs:

    • A client ID (identifies the user)
    • A session ID (tracks their current visit)

2. These IDs are saved in cookies by GA4

3. A special JavaScript code reads these IDs and saves them securely on the server.

4. The server can then use these IDs to send additional event data to GA4

Technical Implementation

The detailed process involves:

Google Tag Implementation
  • The GA4 property's Google Tag must be installed and executed
  • Triggers essential events like page_view
  • Initiates user session tracking
Identifier Generation
  • client_id: Generated and stored in cookies
  • session_id: Created for session duration tracking
  • Both are crucial for proper event attribution
Data Extraction Process
  • JavaScript implementation retrieves identifiers from cookies
  • Secure storage in backend systems (e.g., Shopify Orders' Additional Notes)
  • Ensures proper event association with users and sessions

Required Parameters and Fields

To successfully implement server-side tracking, you'll need:

  1. A properly installed GA4 Google Tag on your website
  2. Your GA4 measurement ID and API secret
  3. The client ID and session ID from each user
  4. Event names and any additional data you want to track

Required fields for Measurement Protocol events:

  • event_name: Defines the event type
  • measurement_id and api_secret: Authentication credentials
  • client_id or user_id: User attribution identifiers
  • session_id: Session continuity tracker
  • Additional user properties for cross-session tracking

Common Challenges and Solutions

Sometimes you might see (not set) in your GA4 reports. This can happen when:

  • Users have ad blockers enabled
  • Browsers are in private/incognito mode
  • Cookie restrictions are in place
  • Users haven't given consent for tracking

Detailed breakdown of potential issues:

1. Browser Limitations

    • Ad blockers preventing identifier storage
    • Cookie restrictions affecting tracking
    • Private browsing mode limitations

2. Cookie Management and Browser Limitations

    • First-party vs. third-party cookie restrictions
    • Safari's Intelligent Tracking Prevention (ITP) and similar technologies significantly limit cookie lifespans
    • Ad blockers may prevent proper storage or retrieval of identifiers
    • Incognito/Private Browsing Modes don't maintain persistent cookies and reset identifiers upon closing
    • Cookie restrictions can prevent proper identifier storage

3. Recurring Orders and Data Availability

    • While User and Session reports may show "(not set)" values
    • Order-related data remains accessible in other reports including:
      • Coupons
      • Taxes
      • Shipping
      • Items
      • Other order-specific metrics
    • This allows for partial data analysis even with tracking limitations

4. Consent Management

    • GDPR and CCPA compliance effects
    • Impact on identifier generation and storage
    • Session tracking limitations

User privacy is crucial. When users deny consent, several important changes occur in the tracking system. Standard tracking functionality becomes significantly impacted as Consent Management Platforms (CMPs) take control of monitoring and managing cookie permissions.

In this scenario, marketing and analytics-related cookies are automatically removed when required by the CMP. This leads to a critical tracking limitation: new client_id and session_id values are generated each time the user loads a page, making it impossible to reliably track users across different sessions.

The constant regeneration of these identifiers effectively prevents the system from maintaining consistent user identification, which is essential for accurate analytics data collection

Analyzify's Solution

    • Enhanced Data Storage:
      • Securely stores client_id and session_id in Shopify Order Additional Detail fields
      • Preserves user's cookie consent preference alongside identifiers
      • Maintains data integrity even with cookie limitations
    • Consent-Compliant Mode:
      • When enabled in the app settings:
        • Prevents data transmission to GA4
        • Respects user privacy choices
        • Maintains essential order tracking
    • Attribution Data Preservation:
      • Captures and stores URL parameters regardless of cookie status:
        • UTM parameters (source, medium, campaign, etc.)
        • Ad platform click IDs
        • Referral information
      • Stores this data in Order Additional Notes
      • Ensures attribution data remains available for analysis

Data Storage and Tracking

You can track various data points in your order notes, including:

  • UTM parameters (source, medium, campaign, etc.)
  • Ad click IDs (from Google, Facebook, etc.)
  • User consent preferences

Shopify Order Notes & Stored Values

The following values can be stored in Order Notes for tracking purposes:

  • azfy_consent
  • azfy_fbc
  • azfy_fbclid
  • azfy_fbp
  • azfy_ga
  • azfy_ga_ABC123
  • azfy_gclid
  • azfy_utm_campaign
  • azfy_utm_content
  • azfy_utm_id
  • azfy_utm_medium
  • azfy_utm_source
  • azfy_utm_term

Attribution Logic

  • Multiple click IDs can be stored (e.g., gclid and fbclid)
  • Only the most recent UTM parameters are retained
  • Example: A user clicking Google Ads then Facebook Ads will show:
    • Both click IDs stored
    • UTM source/medium updated to the latest (Facebook/paid)

Remember that proper setup and regular maintenance are crucial for accurate data collection and analysis.

Table Of Contents