Home Integrations First-Party GTM
Tag Manager Google Tag Gateway Firebase Google Cloud

Firebase + Google Tag Gateway (GTG): Server-Side Tagging Integration

How to set up a robust, first-party data pipeline using Google Cloud Run and Firebase Hosting Rewrites. Bypass ad blockers and restore data accuracy.

Is this the right integration for you?

Do you use a CMS?

(Shopify, WordPress, Wix)

If Yes → GTG is not available yet, Keep checking your CMS
No

Do you use Cloudflare?

If Yes → Use Cloudflare Integration

Requires Cloudflare Workers

No

Do you use Amazon CloudFront?

If Yes → Use CloudFront Guide

Requires Lambda@Edge configuration

No

Do you use Google Cloud Load Balancing?

If Yes → Use Cloud Load Balancing

Requires Application Load Balancer (ALB)

No

Manual Configuration

Google Cloud Run + Firebase

You Are Here

This guide covers the manual setup method for maximum control and first-party data ownership.

The Challenge

Client-side tracking is dying. Ad blockers, ITP (Intelligent Tracking Prevention), and browser privacy updates are slashing data accuracy by up to 30%. The solution is Server-Side Tagging, but setting it up correctly on a first-party subdomain (e.g., metrics.yourdomain.com) can be tricky.

Why Does This Matter for Google Ads?

Simple Answer: It helps you recover "lost" conversions.

When browsers block your tracking (because it looks like 3rd-party spying), Google Ads never receives the signal that a sale happened. This means Google's AI bidding algorithms (Target ROAS, Max Conversions) are flying blind.

By looking like a "First Party" (part of your own website), you can recover 15-20% more conversion data. This feeds the AI better data, lowers your Cost Per Acquisition, and gives you a massive advantage over competitors still using the old method.

The Architecture

We utilize specific Google Cloud architecture to keep everything clean, secure, and first-party:


Step 1: Provision the Server

In your GTM, Create a Server Container, go to Create Container > Container Settings. Use the automatic provisioning tool to create a Cloud Run service. This creates a billing-attached environment that scales automatically to zero when not in use.

GTM Server Container Creation

Step 2: Configure Firebase Hosting

This is the secret sauce. Instead of managing complex load balancers, we use Firebase Hosting's native rewrite capabilities to route traffic to Cloud Run.

Update your firebase.json configuration. It is cleaner to separate your GTM service into its own "site" target if you want to isolate it, or you can run it on the same domain.

"hosting": [
  {
    "site": "your-main-site",
    "public": "public",
    "rewrites": [
      {
        "source": "/gtm/**", 
        "run": {
          "serviceId": "your-cloud-run-service-name",
          "region": "us-central1"
        }
      }
    ]
  }
]

Note: Be sure to verify your Cloud Run service name and region.

Step 3: Custom Domain Mapping

Map a subdomain (e.g., metrics.casson.co.za) to your Cloud Run service.

Custom Domain Mapping Configuration

Verify DNS propagation by visiting https://metrics.yourdomain.com/healthy. You should see "ok".

Step 4: GTM Client Configuration

In your GTM Server Container, configure the "Google Tag Manager: Web Container" client.

GTM Client Configuration Interface

Critical Configuration Requirement

To avoid 400 Bad Request errors:

  • Add your Web Container ID (GTM-XXXX) to the "Allowed Container IDs" list.
  • Ensure Region-Specific Settings are ENABLED if you plan to use Google Signals.

Step 5: Browser-Side Implementation

Finally, update your gtm.js snippet on your website to load from your new first-party server instead of Google's.

Replace:

https://www.googletagmanager.com/ns.html

With:

https://metrics.yourdomain.com/ns.html

Replace:

https://www.googletagmanager.com/gtm.js

With:

https://metrics.yourdomain.com/gtm.js

The Result

Your tracking is now First-Party. Browser extensions may report "Not Connected" because they don't recognize the domain, but inspecting the Network Tab will show requests returning 200 OK.

This setup drastically improves data resilience against ITP and ad blockers, ensuring your conversion data remains accurate for Google Ads optimisation.