<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged drupal</title>
<link>https://coderlegion.com/tag/drupal</link>
<description>Powered by Question2Answer</description>
<item>
<title>How I Set Up Server-Side GTM Tracking with Stape.io, GA4 and Google Ads on a Drupal 11 Marketplace</title>
<link>https://coderlegion.com/15750/how-set-up-server-side-gtm-tracking-with-stape-io-ga4-and-google-ads-on-drupal-11-marketplace</link>
<description>&lt;p&gt;When I relaunched &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.parksy.com&quot;&gt;Parksy &lt;/a&gt;— 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.&lt;br&gt;
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.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;The Stack&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Drupal 11 (custom parksy_gtm module for dataLayer events)&lt;br&gt;
GTM web container (GTM-KNDDDKM9) — client-side tag management&lt;br&gt;
GTM server container hosted on Stape.io — receives and forwards events&lt;br&gt;
GA4 — analytics destination&lt;br&gt;
Google Ads — conversion tracking destination&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 1: Set Up a Server Container on Stape.io&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Stape.io makes hosting a GTM server container easy without managing your own GCP instance.&lt;/p&gt;
&lt;p&gt;Create an account at stape.io&lt;br&gt;
Create a new GTM Server Container&lt;br&gt;
Stape provisions a subdomain like gtm.yourdomain.com — point a CNAME DNS record to it&lt;br&gt;
Copy the Container Config string from Stape and paste it into your GTM server container settings&lt;/p&gt;
&lt;p&gt;Your server container is now live and ready to receive events.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 2: Configure the Web Container to Send to the Server&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
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.&lt;br&gt;
This routes all GA4 hits through your server first — giving you full control over what gets forwarded and letting you enrich events server-side.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wk08ettuay27vhnq4u8m.png&quot; alt=&quot;cloud bubble of mixed tech&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 3: Push dataLayer Events from Drupal&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
I built a small custom Drupal module (parksy_gtm) that hooks into key events and pushes them to the dataLayer:&lt;br&gt;
phpfunction parksy_gtm_user_register(array &amp;amp;$edit, UserInterface $account) &lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;{
  $response = new AttachedAssets();
  drupal_add_js([
    'event' =&amp;gt; 'sign_up',
    'method' =&amp;gt; 'email',
    'user_id' =&amp;gt; $account-&amp;gt;id(),
  ], 'setting');
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The three core events I track:&lt;/p&gt;
&lt;p&gt;sign_up — new user registration&lt;br&gt;
add_to_cart — user views the subscribe page&lt;br&gt;
purchase — Stripe/PayPal subscription confirmed&lt;/p&gt;
&lt;p&gt;Each event carries relevant parameters (user ID, plan type, value) so GA4 and Google Ads get clean, structured data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 4: Set Up GA4 in the Server Container&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
In the server GTM container:&lt;/p&gt;
&lt;p&gt;Add a GA4 client — this receives incoming GA4 hits from the web container&lt;br&gt;
Add a GA4 tag pointing to your Measurement ID (G-XXXXXXXXXX)&lt;br&gt;
Map the incoming event parameters to GA4 event parameters&lt;/p&gt;
&lt;p&gt;Now GA4 events are being sent from your server IP, not the user's browser — bypassing most ad blockers.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vl2xs2kburjphi826wds.png&quot; alt=&quot;magnifying glass focus on data&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 5: Google Ads Conversion Tracking Server-Side&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
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.&lt;br&gt;
In the server GTM container:&lt;/p&gt;
&lt;p&gt;Add a Google Ads Conversion Tracking tag&lt;br&gt;
Set your Conversion ID (AW-XXXXXXXXX) and Conversion Label&lt;br&gt;
Trigger it on the purchase event from your GA4 client&lt;br&gt;
Map transaction_id, value, and currency from the event data&lt;/p&gt;
&lt;p&gt;Google Ads now receives purchase conversions directly from your server — far more reliable than client-side.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Step 6: Enhanced Conversions (Optional but Recommended)&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
To improve match rates, pass hashed user data alongside conversions. In Drupal, hash the email at the point of purchase:&lt;br&gt;
php$hashed_email = hash('sha256', strtolower(trim($account-&amp;gt;getEmail())));&lt;br&gt;
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.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Results&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
After switching to server-side tracking on Parksy:&lt;/p&gt;
&lt;p&gt;Conversion data gaps from ad blockers effectively eliminated&lt;br&gt;
Google Ads reporting became consistent with actual Stripe revenue&lt;br&gt;
GA4 session data quality improved noticeably&lt;/p&gt;
&lt;p&gt;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.&lt;br&gt;
Happy to answer questions in the comments — especially around the Drupal dataLayer integration or Stape.io configuration.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/15750/how-set-up-server-side-gtm-tracking-with-stape-io-ga4-and-google-ads-on-drupal-11-marketplace</guid>
<pubDate>Fri, 24 Apr 2026 19:42:20 +0000</pubDate>
</item>
</channel>
</rss>