DEV Community

Cover image for How I Set Up Server-Side GTM Tracking with Stape.io, GA4 and Google Ads on a Drupal 11 Marketplace
Daniel Battaglia
Daniel Battaglia

Posted on

How I Set Up Server-Side GTM Tracking with Stape.io, GA4 and Google Ads on a Drupal 11 Marketplace

When I relaunched Parksy — a two-sided parking marketplace — on Drupal 11, I knew I needed rock-solid conversion tracking. Browser-side GTM alone wasn't going to cut it. Ad blockers, iOS privacy changes, and cookie restrictions were killing data quality. So I went full server-side.
Here's exactly how I set it up using Stape.io as my GTM server container host, with GA4 and Google Ads conversion tracking firing server-side.

The Stack
Drupal 11 (custom parksy_gtm module for dataLayer events)
GTM web container (GTM-KNDDDKM9) — client-side tag management
GTM server container hosted on Stape.io — receives and forwards events
GA4 — analytics destination
Google Ads — conversion tracking destination

Step 1: Set Up a Server Container on Stape.io
Stape.io makes hosting a GTM server container easy without managing your own GCP instance.

Create an account at stape.io
Create a new GTM Server Container
Stape provisions a subdomain like gtm.yourdomain.com — point a CNAME DNS record to it
Copy the Container Config string from Stape and paste it into your GTM server container settings

Your server container is now live and ready to receive events.

Step 2: Configure the Web Container to Send to the Server
In your GTM web container, set up a GA4 Configuration tag but point the server container URL to your Stape endpoint instead of Google directly.
This routes all GA4 hits through your server first — giving you full control over what gets forwarded and letting you enrich events server-side.

cloud bubble of mixed tech

Step 3: Push dataLayer Events from Drupal
I built a small custom Drupal module (parksy_gtm) that hooks into key events and pushes them to the dataLayer:
phpfunction parksy_gtm_user_register(array &$edit, UserInterface $account)

{
  $response = new AttachedAssets();
  drupal_add_js([
    'event' => 'sign_up',
    'method' => 'email',
    'user_id' => $account->id(),
  ], 'setting');
}
Enter fullscreen mode Exit fullscreen mode

The three core events I track:

sign_up — new user registration
add_to_cart — user views the subscribe page
purchase — Stripe/PayPal subscription confirmed

Each event carries relevant parameters (user ID, plan type, value) so GA4 and Google Ads get clean, structured data.

Step 4: Set Up GA4 in the Server Container
In the server GTM container:

Add a GA4 client — this receives incoming GA4 hits from the web container
Add a GA4 tag pointing to your Measurement ID (G-XXXXXXXXXX)
Map the incoming event parameters to GA4 event parameters

Now GA4 events are being sent from your server IP, not the user's browser — bypassing most ad blockers.

magnifying glass focus on data

Step 5: Google Ads Conversion Tracking Server-Side
This is where it gets powerful. Instead of relying on the browser-based Google Ads conversion tag (which frequently gets blocked), you fire conversions from the server.
In the server GTM container:

Add a Google Ads Conversion Tracking tag
Set your Conversion ID (AW-XXXXXXXXX) and Conversion Label
Trigger it on the purchase event from your GA4 client
Map transaction_id, value, and currency from the event data

Google Ads now receives purchase conversions directly from your server — far more reliable than client-side.

Step 6: Enhanced Conversions (Optional but Recommended)
To improve match rates, pass hashed user data alongside conversions. In Drupal, hash the email at the point of purchase:
php$hashed_email = hash('sha256', strtolower(trim($account->getEmail())));
Push this into the dataLayer as user_data.email and map it through GTM to the Google Ads enhanced conversions field. This significantly improves attribution, especially on iOS.

Results
After switching to server-side tracking on Parksy:

Conversion data gaps from ad blockers effectively eliminated
Google Ads reporting became consistent with actual Stripe revenue
GA4 session data quality improved noticeably

If you're running a marketplace or any site where conversion accuracy directly affects ad spend decisions, server-side GTM is worth the setup effort.
Happy to answer questions in the comments — especially around the Drupal dataLayer integration or Stape.io configuration.

Top comments (0)