Skip to navigation

Target Selection

Exactly how a route decides which target handles a request.
View as Markdown

Every time someone visits a route, Divertly runs the route’s targeting strategy against the request and picks one target. This page spells out the rules, including what happens when more than one target matches, or none do.

Availability by plan

StrategyFreePaid
WeightedYesYes
RandomYesYes
CountryYes
LanguageYes
Device TypeYes
BrowserYes
Operating SystemYes
HTTP HeaderYes
Query StringYes
User AgentYes
Human vs. BotYes
IP CIDRYes

Weighted and Random are available on every plan. The other strategies are available on paid plans. You can list the strategies your organization can use from the targetStrategies field of the entitlements endpoint.

The resolution rules

  1. A route with no targets has nowhere to send the visitor, and the request returns an error.
  2. A route with exactly one target sends every visitor to it, whatever the strategy.
  3. Otherwise the strategy runs, as described below.
  4. If the strategy finds no match, the route’s fallback applies.

Weighted and Random

  • Random picks any target with equal probability.
  • Weighted picks a target in proportion to its weight. A target with weight 90 and one with weight 10 receive roughly 90% and 10% of traffic. A target with a weight of 0 is never chosen while another target has a weight above 0. If every weight is 0, the route picks at random instead.
  • Weighted routes can be made sticky, so a returning visitor keeps landing on the same target. Sticky behavior is set with the sticky field when you update a route through the API.

Match-based strategies

Country, Language, Device Type, Browser, Operating System, HTTP Header, Query String, and User Agent compare an attribute of the request with each target’s match value:

StrategyWhat the request is compared with
CountryThe visitor’s country, as a two-letter ISO code (for example US), looked up from their IP address.
LanguageThe Accept-Language header.
Device TypeThe device type parsed from the user agent.
BrowserThe browser name parsed from the user agent.
Operating SystemThe operating system parsed from the user agent.
HTTP HeaderThe value of the header named in the route’s Targeting Selector.
Query StringThe value of the query-string parameter named in the route’s Targeting Selector.
User AgentThe full user-agent string.

How matching works:

  • A target’s match value is treated as a regular expression, and matches if it appears anywhere in the request’s value. Matching is case-sensitive. en matches the language header en-US,en;q=0.9, and Chrome matches any user agent containing Chrome. To match exactly, anchor the pattern with ^ and $.
  • Targets are checked in turn, and the first matching target wins. If your match values can overlap, a request may match several targets, so write them so that they don’t.
  • A target whose match value isn’t a valid regular expression is skipped.
  • If the request doesn’t carry the attribute at all, such as a missing header, a missing query parameter, or an IP address whose country isn’t known, nothing matches and the fallback applies.

Pick match values from the preset list when the dashboard offers one, for Country, Device Type, Operating System, Language, and Browser. These are already in the form the strategy expects.

Human vs. Bot

Each request is classified as a human visitor or automated traffic. A target’s match value is Humans, Bots, or Any. A human request considers targets set to Humans or Any, and a bot request considers targets set to Bots or Any. If more than one qualifies, one is chosen at random. See Redirect Bot Traffic.

IP CIDR

A target’s match value can be a single IPv4 address (203.0.113.7), a CIDR range (203.0.113.0/24), or several of these separated by commas (203.0.113.0/24, 198.51.100.7). The request matches when the visitor’s IP address falls in any of them. Targets are checked in turn and the first match wins.

When nothing matches

The route’s Targeting Fallback decides what happens:

FallbackResult
ResolveThe visitor goes to the route’s Default Target. If no default target is set, one of the route’s targets is chosen at random.
ErrorThe visitor receives an error.

Changes take effect immediately

Selection runs on every request, so changing a strategy, a match value, a weight, or whether a target is enabled applies to the next visit. There’s nothing to publish.