Skip to main content

Geolocation Rules in Data Sources: Target Shoppers by Country, Region, City or Postal Code

Use Geolocation data source rules to show different products and widget text by shopper country, region, city or postal code.

Written by Tom

Geolocation rules let you show different products and widget text to shoppers based on where they are, by country, region, city, postal code or latitude and longitude. Geolocation rules are data source IF rules in Rebuy, in the Geolocation Rules group, and they work in on-site widgets and the Rebuy Smart Cart. Rebuy works out each shopper's approximate location from their IP address.

What Geolocation rules can target

Each Geolocation rule matches one part of the shopper's location. The following table lists each rule in the Geolocation Rules group, what it matches, and an example value.

Rule

What it matches

Example value

Country Code

The shopper's country, as a two-letter code

US, CA, GB

Country Name

The shopper's country, as a name

United States

Province Code

The code of the top-level region of the shopper's country, such as a US state or a Canadian province

CA for California, QC for Québec

Province Name

The name of the top-level region of the shopper's country

California, England

Continent Code

The shopper's continent, as a two-letter code

NA, EU

Continent Name

The shopper's continent, as a name

North America, Europe

City Name

The shopper's city

London, Montréal

Postal Code

The shopper's postal code, and for United Kingdom shoppers the first half of the postcode only

10001, WR13

Latitude

How far north or south the shopper is, in degrees

38

Longitude

How far east or west the shopper is, in degrees

-100

Country, province, continent and city rules use the Contains, Does Not Contain, Equals and Does Not Equal operators. Postal Code, Latitude and Longitude rules use Is Greater Than, Is Less Than and Is Equal To.


Where Geolocation rules work

Geolocation rules work wherever a Rebuy widget loads its products on your storefront, and some Rebuy features target by location with their own setting instead. The following table lists where you can target shoppers by location, which setting to use, and where that setting lives.

Where

How to target by location

Where the setting lives

On-site widgets, such as product page, cart page and home page widgets

Geolocation rules

The widget's data source

Rebuy Smart Cart widgets, such as the Smart Cart cross-sell

Geolocation rules

The widget's data source

Bundle Builder steps

Geolocation rules

The step's data source

Gift With Purchase widget

Geolocation rules, checked on your storefront before the gift is added and not checked again at checkout

The widget's data source

Smart Flows

The Smart Flows Location targeting rule, which uses country and state or province

The Smart Flows flow editor, under Targeting Rules

Tiered Progress Bar in the Rebuy Smart Cart

The progress bar's Limit Countries setting

The Smart Cart editor, on each progress bar

Checkout Extensions widgets

Leave Geolocation rules out of a Checkout Extensions widget's data source, since Geolocation rules do not match in Checkout Extensions

Not applicable

Post-purchase offers

Leave Geolocation rules out of a post-purchase offer's data source, since Geolocation rules do not match in post-purchase offers

Not applicable


Set up a Geolocation rule

You set up a Geolocation rule in the data source your widget uses, the same way as any other IF rule:

  1. In Rebuy, open Data Sources and select the data source your widget uses, or create a new one.

  2. Add a rule, open the IF dropdown, and select a rule under Geolocation Rules, such as Country Code.

  3. Select an operator, such as Equals.

  4. Type one value, such as US. Use a separate condition for each value, joined with OR, to match more than one country, region or city.

  5. To narrow the rule, select AND and add another condition, such as Country Code Equals GB under a City Name condition.

  6. Set the RETURN for the rule, such as Specific Product, a collection, or Widget Language text like a new widget title.

  7. Turn on Exit If Matched when shoppers who match this rule should not also get the rules below it.

  8. Add an IF Anything rule at the bottom of the data source that returns your default recommendations, so shoppers outside your locations still see products.

  9. Save the data source.

In the widget editor, the widget's Data Source setting must name this data source. After saving, open your storefront and check that the widget shows the products for your location.


Test Geolocation rules on your storefront

Test Geolocation rules on your live storefront, where each shopper is matched by the location of the device that loads the page. The Preview Ruleset page in the Data Source editor loads products from Rebuy's servers rather than from your browser, so the preview matches Geolocation rules to the location of Rebuy's servers instead of yours, while shoppers on your storefront are still matched by their own location. To test Geolocation rules:

  1. Open a page on your storefront where the widget shows.

  2. Check that the widget returns the products and text set for your own location.

  3. To see what shoppers in another country get, turn on a VPN set to that country and reload the page.

Geolocation rules use the location of the VPN server, so a VPN set to Canada shows the widget as a shopper in Canada sees it.


How Geolocation rules match location values

Geolocation rules compare the value you type with the shopper's location using the points below. Check the spelling of every value, since a rule with a misspelled value, such as a misspelled city, matches no shopper, and the data source moves on to its other rules.

Capital letters and accents do not matter

Geolocation rules ignore capital letters and accents when they compare values, so a City Name rule set to montreal matches shoppers in Montréal, and a Province Name rule set to Quebec matches shoppers in Québec. The spelling of the value you type still has to match the place name.

Use Province for a country's largest regions

Province Code and Province Name hold the first region a country is divided into, not a smaller area inside it. In the United States and Canada, Province is the state or province, such as California or Alberta. In the United Kingdom, Province is England, Scotland, Wales or Northern Ireland, so set a Province Name rule to England to reach shoppers anywhere in England, including London. In countries that are divided into regions and then into smaller areas, such as France, Italy and Spain, Province is likewise the larger region.

To target a city, use a City Name rule and add a Country Code condition to the same rule with AND, for example City Name Equals London and Country Code Equals GB.

Add Country Code to every Province Code rule

The same province code can belong to regions in more than one country, so add a Country Code condition to each Province Code rule with AND. WA is the code for Washington in the United States and for Western Australia in Australia, so a rule with only Province Code Equals WA reaches shoppers in both. A rule with Province Code Equals WA and Country Code Equals US reaches only shoppers in Washington.

Use Country Code rather than Country Name

Country Code is the more reliable way to target a country, since each country has one two-letter code, while a country name can be written more than one way. For example, Country Code Equals NL reaches shoppers in the Netherlands, while Country Name Equals Netherlands misses them because their country name is The Netherlands.

Enter the first half of a UK postcode

To target United Kingdom shoppers by postcode, enter the first half of the postcode in a Postal Code rule with Is Equal To, such as WR13 for the postcode WR13 6AB, since Postal Code holds only that first half, called the outward code, for United Kingdom shoppers. Use the outward code rather than the full postcode, which does not match.


Geolocation rules when a shopper's location is unknown

When a shopper's location can't be determined from their IP address, no Geolocation rule matches that shopper, and that includes rules that use Does Not Equal or Does Not Contain. An unknown location is not treated as being outside a country, since the shopper could be anywhere, including in the country your rule leaves out. For example, a shopper browsing through the Tor network has no known country, so a Country Code Does Not Equal US rule does not match that shopper.

For a shopper with an unknown location, the data source skips its Geolocation rules and moves on to its other rules, so the widget shows what those rules return. Add an IF Anything rule at the bottom of the data source so these shoppers still get your default recommendations, since a widget shows products only from rules that match the shopper.


How accurate Geolocation rules are

Geolocation rules use an approximate location worked out from the shopper's IP address, so they suit merchandising, such as which products and widget text a shopper sees. The location is an estimate, and it reflects the network the shopper connects through, so a shopper on a VPN, a mobile network or a company network can show up in a different city, region or country from where they are. Rebuy does not guarantee the accuracy of a shopper's location.

Geolocation rules choose what a Rebuy widget recommends, and they do not stop a shopper from buying a product, since a shopper can still reach the product page directly. Where you ship and sell is set in Shopify, under Settings > Shipping and delivery, and Shopify's checkout applies it to every order.


Example 1: recommend a product only where you ship it

This Geolocation rules example recommends ski wax only to shoppers in Australia, Canada and the United States, except shoppers in Alaska and Hawaii. It uses the following rules in one data source:

  • Rule 1: IF Country Code Equals AU OR Country Code Equals CA, RETURN Specific Product Ski Wax, with Exit If Matched turned on.

  • Rule 2: IF Country Code Equals US AND Province Code Does Not Equal AK AND Province Code Does Not Equal HI, RETURN Specific Product Ski Wax, with Exit If Matched turned on.

  • Rule 3: IF Anything, RETURN Endpoint Recommended (AI), for every other shopper.

Geolocation Rules in Data Sources, a data source that returns one specific product for Country Code AU or CA, and for Country Code US with Province Code Does Not Equal AK and Does Not Equal HI, each with Exit If Matched on, then an IF Anything rule returning Recommended (AI) for every other shopper

Example 2: launch a seasonal collection earlier in colder regions

This Geolocation rules example shows a winter collection to United States shoppers in the northern half of the country from October 15th, and to shoppers further south from November 1st. It combines Geolocation rules with Date rules:

  • Rule 1: IF Date Is After October 15th AND Date Is Before December 15th AND Country Code Equals US AND Latitude Is Greater Than 38, RETURN Collection Winter Collection, with Exit If Matched turned on.

  • Rule 2: IF Date Is After November 1st AND Date Is Before January 1st AND Country Code Equals US AND Latitude Is Less Than 38, RETURN Collection Winter Collection.

Geolocation Rules in Data Sources, rules returning a seasonal collection to US shoppers, one for Latitude Is Greater Than 38 from October 15th to December 15th with Exit If Matched on, one for Latitude Is Less Than 38 from November 1st to January 1st, each combining Date, Country Code and Latitude conditions with AND

Latitude 38 runs roughly through the middle of the United States, so shoppers north of it see the collection first. For more on Date rules, see Date Based Rules.

Example 3: recommend locally made products with a local widget title

This Geolocation rules example shows shoppers in Utah products tagged Made-in-Utah, under a widget title written for them. It uses the following rule:

  • IF Province Code Equals UT AND Country Code Equals US, RETURN Products with Tags Contains Made-in-Utah, AND Super Title Shop Local, AND Title These Products Are All Made In Utah.

Geolocation Rules in Data Sources, a rule with IF Province Code Equals UT AND Country Code Equals US returning Products with Tags Contains Made-in-Utah, with the widget Super Title set to Shop Local and Title set to These Products Are All Made In Utah

Shoppers in Utah see the Made-in-Utah products under the Shop Local super title, and every other shopper gets the rules below it. The same pattern works at the country level, such as Country Code Equals US with a Made-in-USA tag. For every widget text field you can change from a rule, see the RETURN Widget Language section of Data Sources 101.


FAQs

How do I stop recommending a product to shoppers in one country?

To stop recommending a product to shoppers in one country, return a collection without that product for that country. The Add Exclusion Filter setting applies to the whole data source, so it removes a product for every shopper rather than for one country. To leave a product out for one country:

  1. In Shopify, create a collection that holds the products you want to recommend in that country, without the product.

  2. In the data source, add a rule with IF Country Code Equals the country, such as US, and RETURN Collection with the new collection.

  3. Turn on Exit If Matched for that rule.

  4. Below it, add the rule that returns your usual recommendations for every other shopper.

How do I target several countries or cities in one Geolocation rule?

To target several countries, regions or cities in one Geolocation rule, add one condition per value and join them with OR, such as Country Code Equals US OR Country Code Equals CA. Each Geolocation rule value holds one place, so enter each country or city as its own condition rather than as a comma-separated list such as US, CA in one value, which does not match.

Do Geolocation rules follow a shopper who uses a VPN?

Yes, Geolocation rules follow the location of the VPN server a shopper connects through, so a shopper in the United States using a VPN set to Germany matches Geolocation rules for Germany. The same is true when you test your own store through a VPN, which is how you see what shoppers in another country get.

Do Geolocation rules work on a headless storefront?

Yes, Geolocation rules match each shopper's own location on a headless storefront when the shopper's browser requests the widget's products from Rebuy, since the location comes from the device that makes the request. A headless storefront that requests Rebuy products from its own server instead gets products for that server's location, so request products from the browser when your data sources use Geolocation rules. Headless storefront code is built by your own developer or a Rebuy Partner agency, and Rebuy Support does not build or troubleshoot it.

Did this answer your question?