Knowledge Base: GeoIP headers – Visitor Region setup in MetricsGate sGTM
This article shows how to configure server-side Google Tag Manager (sGTM) in MetricsGate to:
- Read GeoIP information from request headers
- Build an ISO-3166-2 compliant country-region value
- Use it as Visitor Region inside sGTM
- Make geo values available for downstream tags (for example GA4)
MetricsGate sends the following GeoIP headers to your sGTM container:
X-Geoip2-Country: HU
X-Geoip2-Region: BU
X-Geoip2-City: Budapest
Step 1 – Create Request Header variables
In your server-side GTM container, create these variables to read the GeoIP headers.
Variable: RH – Country
- Variable type: Request Header
- Name:
X-Geoip2-Country

Variable: RH – Region
- Variable type: Request Header
- Name:
X-Geoip2-Region

Variable: RH – City
- Variable type: Request Header
- Name:
X-Geoip2-City

After saving, these variables resolve to values like:
RH - Country–HURH - Region–BURH - City–Budapest
Step 2 – Import the Country-Region Variable Template
To construct an ISO-3166-2 compliant subdivision value (for example HU-BU), MetricsGate provides a ready-made Variable Template export.
Import path
- Go to Templates → Variable Templates → New → Import
- Import the provided template export file
- Save the template
No manual editing is required.

Step 3 – Create the Geo – ISO Country-Region variable
After importing the template, create a new variable using it.
- Variable type: Geo – Country-Region (imported template)
- Country:
{{RH - Country}} - Region:
{{RH - Region}}
Name the variable:
Geo - ISO Country-Region
Expected output:
HU-BU

Step 4 – Configure the Visitor Region variable
The Visitor Region variable is used by sGTM for region-specific behavior (for example region-specific settings in Clients and Tags).
Settings
- Variable type: Visitor Region
- Read region data from: Custom Variable
- Country:
{{RH - Country}} - Subdivision:
{{Geo - ISO Country-Region}}

What this setup enables
With the above configuration in place:
- sGTM understands the visitor’s country and region
- Region-specific settings in Clients and Tags work as expected
- The derived
HU-BUvalue is visible in sGTM Preview - GA4 forwarding includes the
ur(user region) parameter when applicable
City-level data (RH - City) is also available for:
- GA4 enrichment
- Custom routing logic
- Server-side analytics or logging
Troubleshooting and verification
Use this section to verify the configuration and quickly locate common issues.
Verify in sGTM Preview
- Open Preview for your server container.
- Trigger any request that reaches your tagging server.
- In the Preview panel, open the relevant request (Client / Tag invocation).
- Check variable values:
RH - CountryreturnsHURH - RegionreturnsBURH - CityreturnsBudapestGeo - ISO Country-RegionreturnsHU-BUVisitor Regionshows countryHUand subdivisionHU-BU
If these values are present, the GeoIP headers are being read correctly and the derived ISO value works.
Verify GA4 output (optional)
If you forward events to GA4 from sGTM, open the outgoing GA4 request in Preview and confirm:
uris present and equalsHU-BU(or the correct ISO-3166-2 subdivision for the visitor)
Common problems
Problem: Request Header variables are empty
- Confirm the incoming request contains the headers
X-Geoip2-Country,X-Geoip2-Region,X-Geoip2-City. - Double-check the Request Header variable names match exactly.
Problem: Geo – ISO Country-Region is empty
- Ensure both
RH - CountryandRH - Regionreturn values. - Confirm the imported template was saved.
Problem: Visitor Region has only country, no subdivision
- Make sure
Subdivisionpoints to{{Geo - ISO Country-Region}}. - Ensure
Geo - ISO Country-Regionreturns an ISO-3166-2 formatted value likeHU-BU.
Problem: Region-specific settings do not work
- Confirm your Clients or Tags actually use region-specific settings.
- Verify the Visitor Region variable returns expected values in Preview.
Notes and best practices
- Header names in Request Header variables are case-insensitive, but keep the names consistent in your configuration.
- Always use ISO-3166-2 formatted subdivision values with Visitor Region.
