Serve Google tags from your own domain
Route a path of your domain to Google tag gateway for advertisers with a Connector and one Request Phase rule, so your tags load from your domain.
Google tags, such as Google Tag Manager (GTM), Google Analytics 4 (GA4), and Google Ads, load by default from googletagmanager.com. Ad blockers and browsers such as Safari and Brave often block that domain, so visits and conversions happen and never reach your reports. Google tag gateway for advertisers serves the same tags from a path of your own domain, such as www.example.com/k7xqpz/.
On Azion, the gateway takes a Connector that reaches Google’s endpoint and one Request Phase rule on the Application that already serves your site. The rule needs Application Accelerator turned on in that Application. You can configure all of it from Azion Console, the Azion CLI, or the API. The rest of the site keeps reaching your origin.
Solid arrows carry the request, and dotted arrows carry the response. Each label starts with the number of its step below.
- The page in the browser loads the tag script, or sends an event, from the measurement path of your domain. The address bar does not change.
- The Workload of your domain receives the request, and the Application that this Workload’s deployment sets runs its Request Phase rules.
- The gateway rule matches the measurement path, skips the cache, adds the visitor’s country and region, and sets the Connector.
- The Connector sends the request over HTTPS to
<tag-id>.fps.goog, and Google’s answer returns through the Connector and the Application to the browser. - Requests for every other path keep reaching your origin through the rules that already serve the site.
Prerequisites
Console
- The tag ID, from the Google tag gateway console. With GTM, it is the container ID, such as
GTM-ABC123. - The measurement path, a path your site does not use, such as
/k7xqpz/. - An Application that serves your site through a Workload. To create one, refer to Applications quickstart.
- Access to Azion Console.
One GTM container covers every tag inside it. Each standalone Google tag, with an ID that starts with G-, takes a setup of its own. Give each container or tag its own measurement path and its own Connector. Then repeat the Connector, rule, position, and check sections for each one.
A random string, such as /k7xqpz/, avoids a conflict with a path your site already serves. The examples use the tag ID GTM-ABC123, the path /k7xqpz/, and the domain www.example.com: replace them with your own values.
Create a Connector for Google
The Connector holds the address of Google’s endpoint for your tag: <tag-id>.fps.goog, with the tag ID in lowercase, such as gtm-abc123.fps.goog. The Host header carries the same value, because Google reads the tag from it. With the default ${host}, Google receives your site’s domain and does not recognize the tag. The endpoint accepts HTTPS only, on port 443. The Connector sends no path prefix, so the path the browser requested reaches Google unchanged.
A Connector holds the address of an origin, here Google’s endpoint, and takes the place of the origins that an Application held. It changes nothing on your site until a rule sets it.
Console
To create the Connector in Azion Console:
- Access Azion Console > Connectors.
- Select + Connectors.
- In Name, enter
google-tag-gateway. - In Connector Type, keep HTTP.
- In Host, replace
${host}withgtm-abc123.fps.goog. - Leave Path empty.
- In Transport Protocol Policy, select Force HTTPS.
- In Address Management, enter
gtm-abc123.fps.googin Address. - Select Save.
The Connector appears in the Connectors list, with gtm-abc123.fps.goog in Address.
Google also accepts the tag ID in an X-Gtg-Tag-Id header, which is needed only when the Host is the bare fps.goog. In the manual setup that this guide follows, the tag ID is in the address and in the Host, so the Connector needs no other header.
Turn on Application Accelerator
The gateway rule needs Application Accelerator turned on in the Application. Without it, the API refuses Forward Cookies with 25047 Missing Required Modules. Azion Console lists Bypass Cache as Bypass Cache - Required Application Accelerator.
Console
To turn on Application Accelerator in Azion Console:
- Access Azion Console > Applications.
- Select the Application that serves your site.
- In the Main Settings tab, under Modules, turn on Application Accelerator.
- Select Save.
After you save, the Application Accelerator switch is on.
Route the measurement path to Google
One Request Phase rule of the Rules Engine sends the requests for /k7xqpz/ and everything under it to the Connector. Each part of the rule has a job:
| Part of the rule | Why the gateway needs it |
|---|---|
starts with /k7xqpz/ |
Matches the path and everything under it, such as scripts and events |
| Set Connector | Sends only these requests to Google |
| Bypass Cache | Keeps each visitor’s script and events out of Azion’s cache, with no cache setting |
| Forward Cookies | Delivers the Set-Cookie header of Google’s response to the visitor |
| Add Request Header, country | Sends the visitor’s country, such as BR |
| Add Request Header, region | Sends the visitor’s region, such as SP |
With is equal in place of starts with, only the exact path reaches Google, and the measurement breaks. Without Bypass Cache, one visitor can receive the response cached for another, and the POST requests of the events stop reaching Google. The _ga and _gcl_* cookies tie a visit from an ad to the purchase it leads to, so the gain of the gateway depends on them.
Because Azion sits between the browser and Google, Google receives each request from Azion’s IP address and not from the visitor’s. The two headers carry the visitor’s location: ${geoip_country_code} holds the ISO 3166-1 country code, and ${geoip_region} holds the region code. Without them, GA4 reports the visitor’s geography as (not set), and consent rules that depend on the region can fail.
Console
To create the rule in Azion Console:
- Access Azion Console > Applications.
- Select the Application that serves your site.
- Select the Rules Engine tab.
- Select + Rule.
- In Name, enter
Google Tag Gateway. - In Phase, keep Request Phase.
- In Criteria, keep
${uri}and starts with, and enter/k7xqpz/as the argument. - In Behaviors, select Set Connector, then select
google-tag-gateway. - Select + Add Behavior, then select Bypass Cache.
- Select + Add Behavior, then select Forward Cookies.
- Select + Add Behavior, then select Add Request Header.
- In the field of the behavior, enter
X-Forwarded-Country: ${geoip_country_code}. - Select + Add Behavior, then select Add Request Header.
- In the field of the behavior, enter
X-Forwarded-Region: ${geoip_region}. - Select Save.
The rule appears last in the Request list of the Rules Engine tab, with the status Active.
Use Add Request Header, which adds the header to the request that Google receives. Add Response Header adds it to the response the browser receives, which Google never reads. Filter Request Header is optional. When the browser sends a header with the same name, Add Request Header replaces its value, so a visitor cannot forge a location.
The gateway needs no Response Phase rule. Check that no Response Phase rule of the Application removes Content-Type or Set-Cookie. Without them, the script reaches the browser broken, or the cookies never reach it. Removing the Server header does no harm.
Azion forwards the visitor’s IP address to the origin in X-Forwarded-For, and Google requires that value intact. Check that no rule of the Application changes this header.
Google also accepts a header with the latitude, longitude, and city, X-Forwarded-Geolocation. The gateway works without it. The Rules Engine has no variable for latitude or longitude, so a Function can build the header if your setup requires it.
Place the rule last
The Application runs its Request Phase rules in order, and when several matching rules set a Connector, the last one wins. When a rule that sends every path to your origin comes first, the gateway rule goes after it. A new rule takes the last position, so the gateway rule needs a move only when a rule comes after it.
Console
To move the rule in Azion Console:
- Access Azion Console > Applications.
- Select the Application that serves your site.
- Select the Rules Engine tab.
- In the Request list, select the down arrow next to the number of
Google Tag Gatewayuntil it is the last rule. - Select Review Changes.
- In Review Changes, check the new positions and select Save.
Google Tag Gateway is the last rule of the Request list.
Before you check the gateway, open the other Request Phase rules of the Application. Three kinds of rule must not match the measurement path:
- A broad rule, such as one that matches file extensions,
/static, or query string arguments. - A rule that applies a cache setting with Tiered Cache on, because Bypass Cache does not act on the Tiered Cache layer.
- A rule before the gateway rule that ends the processing, such as one with Deny (403 Forbidden).
If the Workload’s deployment sets a Firewall with WAF or bot rules, check that they do not block POST requests to the measurement path.
Check the gateway
Google answers two test URLs through the gateway. Wait for the changes to propagate, then open each URL in a private browser window, or request it with curl:
The second URL checks the country and region headers:
A rule reaches traffic over several minutes, and each data center applies it at its own moment. Until then, the measurement path still reaches your origin, and the answer is your site’s own 404 page. A test can pass and then fail while the change propagates, because each request can reach a different data center.
A person who opens the measurement path in the browser sees only a technical answer from Google. The style of a 404 tells you where the request went. A 404 that looks like your site means the request still reaches your origin. A plain Google error page means the request reached Google, and the Connector or the headers need a fix.
Update your site
The rest of the setup happens on your site and in Google’s products:
- In the Google tag gateway console, choose the manual setup.
- Turn on the gateway with the same measurement path as the rule.
- If GTM is written into your site’s code, point the
srcof the script to the measurement path. The<noscript>snippet keeps pointing togoogletagmanager.com. - In Tag Assistant, check that the hits your page sends go out through the measurement path.
- Watch the results for 24 to 48 hours. GA4 fills in the visitors’ geography with no
(not set), and Real-Time Metrics shows no rise of4xxor5xxresponses on the path.
For a GTM container, the snippet changes one line, the address of gtm.js:
For a standalone Google tag, gtag.js moves to the measurement path:
The gateway changes only where the tag loads from and where it sends data. The tag still runs in the browser, while server-side tagging in GTM processes the data on a server of your own. You can combine the two. Consent stays with your site and its consent management platform, and the gateway does not replace Consent Mode. The location headers help Google apply consent rules by region.
Turn the gateway off
To stop the gateway, first point the src of the tag script back to googletagmanager.com, then deactivate the rule. An inactive rule does not run, so the measurement path reaches your origin again. The Connector stays in place for a later return.
Console
To deactivate the rule in Azion Console:
- Access Azion Console > Applications.
- Select the Application that serves your site.
- Select the Rules Engine tab.
- Select
Google Tag Gateway. - In Status, turn off Active.
- Select Save.
The rule shows the status Inactive in the Request list.
After the change propagates, /k7xqpz/healthy answers with your site’s 404 page, so a snippet that still requests the measurement path stops loading the tags.
Troubleshoot the gateway
Each symptom names its likely cause and the fix:
| Symptom | Cause and fix |
|---|---|
| A test passes, then fails | The change is still propagating. Wait 10 to 15 minutes without editing the rule |
A 404 that looks like your site |
The rule did not match. Check starts with, spaces in the argument, and the rule position |
A 404 that persists after propagation |
Your origin’s 404 is in the cache. Purge www.example.com/k7xqpz/* with a wildcard purge |
healthy passes and validate_geo fails |
The location headers are missing. Check both Add Request Header behaviors and their variables |
| An error page from Google | A wrong address, Host, or ID, such as a GA4 ID in place of the container ID. Use the ID in lowercase |
| The script arrives broken | A Response Phase rule removes Content-Type or changes the compression. Exclude the measurement path |
To purge by wildcard, refer to Purge cached content.
The rule belongs to one Application, so it reaches only the domains of the Workloads whose deployment sets that Application. A staging site served by another Application needs the rule in that Application too. So does any subdomain of your purchase funnel that another Application serves. Both Applications can set the same Connector.
The criteria compare the path as the browser sends it. With starts with /k7xqpz/, a request for /k7xqpz without the final slash does not match and reaches your origin. The snippets in Update your site always request a path under /k7xqpz/.