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
Setting Google Tag Manager Variable in GTM Server Container: RH - Country

Variable: RH – Region

  • Variable type: Request Header
  • Name: X-Geoip2-Region
Setting Google Tag Manager Variable in GTM Server Container: RH - Region

Variable: RH – City

  • Variable type: Request Header
  • Name: X-Geoip2-City
Setting Google Tag Manager Variable in GTM Server Container: RH - City

After saving, these variables resolve to values like:

  • RH - CountryHU
  • RH - RegionBU
  • RH - CityBudapest

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

  1. Go to Templates → Variable Templates → New → Import
  2. Import the provided template export file
  3. Save the template

No manual editing is required.

Importing Google Tag Manager Variable Template in GTM Server Container: Geo  - Country-Region

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
Setting Google Tag Manager Variable in GTM Server Container: Geo - ISO Country-Region

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}}
Setting Google Tag Manager Variable in GTM Server Container: Visitor 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-BU value 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

  1. Open Preview for your server container.
  2. Trigger any request that reaches your tagging server.
  3. In the Preview panel, open the relevant request (Client / Tag invocation).
  4. Check variable values:
  • RH - Country returns HU
  • RH - Region returns BU
  • RH - City returns Budapest
  • Geo - ISO Country-Region returns HU-BU
  • Visitor Region shows country HU and subdivision HU-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:

  • ur is present and equals HU-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 - Country and RH - Region return values.
  • Confirm the imported template was saved.

Problem: Visitor Region has only country, no subdivision

  • Make sure Subdivision points to {{Geo - ISO Country-Region}}.
  • Ensure Geo - ISO Country-Region returns an ISO-3166-2 formatted value like HU-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.

Don't miss these articles: