Main Stylesheet
Documentation Fundamentals

Geolocation

How to use automatic geolocation in your owntag Server Side GTM Container

owntag automatically detects the country from which each incoming HTTP request originates. This detection is based on the user’s IP address.

You can find the country information in the HTTP header

X-Owntag-Usercountry

as a two-letter country code in ISO 3166-1 alpha-2 format.

Like other HTTP headers, you can see the geoinformation in the preview mode of your SGTM container:

Screenshot of the Server Side GTM Preview Mode window with a page_view request incoming and the link to the request details highlighted

Screenshot of the owntag-powered HTTP headers in SGTM’s Preview Mode window with X-Owntag-Usercountry highlighted

Use in Server Side GTM

You can use the country information anywhere in tags, triggers, and variables by creating a “Request Header” type variable for it. This variable could then be used as {{header.x-owntag-usercountry}}.

Screenshot of a Google Tag Manager variable of the Request Header type for the x-owntag-usercountry header

Example use cases:

  • Transmitting country information to Google Analytics because you do not want to transmit the IP address, and therefore the built-in GA geolocation might not work
  • Triggering tags only for users in certain countries
  • Associating conversions with country-specific advertiser accounts (“If DE → Facebook Pixel ID 123, If FR → 234, …”)
  • Delivering different JavaScript files (e.g., different GTM Web Containers!) depending on the country

Data Privacy

The association of an IP address with a country is done using the continuously updated database from IP2Location. The geolocation takes place entirely on owntag servers, and your users’ IP addresses are not forwarded to external services.

Accuracy of IP Geolocation Generally

IP Geolocation is never 100% accurate. Do not rely on it for particularly business-critical processes like tax calculation, assuming that the association of a user with a country based on their IP address is always correct.

IP addresses do not have a fixed assignment to countries or regions but are typically only linked to Internet providers. IP Geolocation is based on the assumption that an IP address, once assigned, is likely to be allocated again in the same country on its next issuance. Past known IP ↔ country associations are then used to deduce which country a current IP address belongs to.

In addition to the functioning principle of IP Geolocation, factors related to the user can also ensure that their real IP address does not reach your Server Side GTM:

  1. Proxy Servers and VPNs: A user may use a proxy server or a Virtual Private Network (VPN) to hide their real IP address, using the IP address of the proxy or VPN instead, which can lead to an incorrect location.

  2. Mobile Internet: The IP address of smartphones may change as users move between cell towers, for example, while traveling by train. The same applies to other physically flexible networks such as satellite internet services like Starlink.