# Geolocation Targeting in GT Link Manager

> Geolocation targeting lets one branded link route visitors by country: Indian readers to amazon.in, US readers to amazon.com, everyone else to your default destination. It shipped in GT Link Manager 1.7.0 as a built-in feature with zero dependencies, no GeoIP database to install, no external API call, and no added latency worth measuring. This lesson…

**URL**: https://gauravtiwari.org/course/gt-link-manager-training/configuration-features/geolocation-targeting/
**Author**: 
**Published**: 2026-07-27T17:06:47+05:30
**Updated**: 2026-07-27T17:42:49+05:30

---

Geolocation targeting lets one branded link route visitors by country: Indian readers to amazon.in, US readers to amazon.com, everyone else to your default destination. It shipped in GT Link Manager 1.7.0 as a built-in feature with zero dependencies, no GeoIP database to install, no external API call, and no added latency worth measuring. This lesson covers enabling it, building country rules, and verifying detection actually works on your setup.

Table of Contents

Toggle table of contents
1. [How country detection works](#how-country-detection-works)
2. [Enabling geolocation](#enabling-geolocation)
3. [Building country rules on a link](#building-country-rules-on-a-link)
4. [Previewing rules before you save](#previewing-rules-before-you-save)
5. [Use 302, not 301](#use-302-not-301)
6. [Debugging a live link](#debugging-a-live-link)
7. [Geo rules everywhere else](#geo-rules-everywhere-else)

## How country detection works

The plugin doesn’t look up the visitor’s IP address anywhere. Instead, it reads a country code from a request variable your CDN or web server already provides: Cloudflare’s `CF-IPCountry` header, CloudFront, Vercel, Google App Engine, nginx GeoIP2, Apache mod_geoip, mod_maxminddb, or a custom header you name in settings.

That design has three consequences worth knowing. First, there’s nothing to install or subscribe to. Second, it’s fast, a geo-enabled redirect costs roughly 20 microseconds extra, and links without geo rules pay a single array read. Third, it’s private: the plugin never reads the visitor’s IP, never calls an external service, and never stores or logs the country. It even registers a suggested privacy-policy section under `Settings → Privacy → Policy Guide` stating exactly that.

## Enabling geolocation

Go to `GT Links → Settings` and find the **Geolocation Targeting** section. Turn on **Enable Geolocation** and save. The detection method defaults to `Auto-detect`, which checks Cloudflare first and then the other known sources; the [settings lesson](https://gauravtiwari.org/course/gt-link-manager-training/configuration-features/settings-configuration/) covers the other methods and the custom header option.

Before you build any rules, look at the **Detected Now** readout in that same section. It shows which country and source resolved for the current request. If it shows a country, your CDN is forwarding the header and you’re done. If it doesn’t, the readout tells you which of two situations you’re in: nothing is proxying the site (normal on local, staging, or direct-to-origin installs, geolocation will start resolving once a CDN is in front) or your CDN is in front but didn’t send a country header. Only the second is a misconfiguration. On Cloudflare, the fix is turning on IP Geolocation for the zone.

The **Check Detection** button goes further: it lists every country header present on the request with its raw value, and runs a loopback self-test that sends your site a request carrying a country header and reports what the plugin detected at the other end. That proves detection works even on a local install with no CDN, where “no country on this request” is correct rather than a fault. You can also type a country code into the field next to it to validate the code before using it in a rule.

## Building country rules on a link

![](https://r2.gauravtiwari.org/wp-content/uploads/2026/07/gt-link-manager-geolocation-rule-evaluation-explainer.jpg)

With geolocation enabled, every link’s edit form gains a **Geolocation** section. Tick “Send visitors to a different URL based on their country” and the rule builder appears.

Each rule is a numbered row: the countries it matches, the URL those visitors go to, and an optional per-rule status code. Rules are evaluated top to bottom and the first rule listing the visitor’s country wins, so order matters. Use the arrows to reorder rows.

Picking countries is fast: one-click presets cover common markets (US + CA, EU, UK, India, AU + NZ), the full country list is filterable by typing, and selections show as removable chips. The `EU` preset is a group token that expands to all 27 member states in a single rule; developers can add their own groups via the `gtlm_geo_country_groups` filter.

The final row is always **Everyone else**, the fallback for visitors matching no rule. It has two options: send them to the link’s normal destination URL (the default), or show a 404. The 404 option effectively blocks the link outside your listed countries.

The builder also warns you about the two easy mistakes: a country listed in two rules (only the higher rule can ever match it) and a rule that has countries but no URL.

## Previewing rules before you save

Below the rule table there’s a rule preview: pick a country and see exactly which rule wins and where it sends the visitor. The preview is evaluated in the browser against your unsaved edits, no request is made, so you can sanity-check a rule set before committing it.

## Use 302, not 301

Geo-targeted links should use a 302 redirect. A 301 is cached by the browser permanently, which pins each visitor to whichever country they were in on their first click, and your geo rules silently stop working for returning visitors. The link editor shows a warning when a geo link is set to 301; take it seriously and switch the Redirect Type to 302.

## Debugging a live link

Enable the **Debug Header** setting and geo redirects will carry an `X-GTLM-Country` response header showing the detected country, its source, and whether a rule matched or the fallback applied. Check it with your browser’s network tab or `curl -I`. Turn it off once you’re satisfied.

One honest caveat: a country header can be forged on requests that reach your site without passing through your CDN, so the 404 fallback is not a security control. Behind Cloudflare, `CF-IPCountry` is rewritten at the edge and can’t be spoofed; choosing the “Cloudflare only” detection method is the strictest setting.

## Geo rules everywhere else

Geo rules aren’t locked to the edit form. They round-trip through [CSV export and import](https://gauravtiwari.org/course/gt-link-manager-training/configuration-features/import-export/) as a JSON column, and the [REST API](https://gauravtiwari.org/course/gt-link-manager-training/developer-reference-1771422601/rest-api-reference/) exposes them on the links endpoints with a self-describing schema, so you can geo-target links programmatically. The links list table shows a Geo column with each link’s rule count, and the Diagnostics panel reports geolocation status.

For developers, five hooks cover custom detection and rule interception, documented in [hooks and filters](https://gauravtiwari.org/course/gt-link-manager-training/developer-reference-1771422601/hooks-filters/). And if you’re curious what the pre-1.7.0 snippet-based approach looked like, it lives on in the [geo-based redirects lesson](https://gauravtiwari.org/course/gt-link-manager-training/developer-reference-1771422601/geo-based-redirects/).
