# Smart routing

URL: https://qrdx.dev/docs/smart-routing
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/smart-routing.mdx

Send each scan of a dynamic QR code to a different URL by device, country, area, language, time or scan count, run A/B tests and add UTM parameters.

A [dynamic QR code](https://qrdx.dev/docs/dynamic-qr-codes) normally sends every scan to one destination. With smart routing, one printed code can open the App Store on iPhones and Google Play on Android, a Spanish page for Spanish-speaking visitors, or a different offer outside business hours. Use it when the right page depends on who scans, where, or when.

**Pro and Business**

Smart routing and UTM parameters are part of Pro and Business. They apply to codes that open a website link; [hosted pages](https://qrdx.dev/docs/landing-pages) don't redirect, so they have no routing. See [Plans and limits](https://qrdx.dev/docs/plans-and-limits).

In a hurry? The short task page: [Send scans to different links](https://qrdx.dev/docs/help/dynamic-codes/routing).

## How it works [#how-it-works]

You set up routing in the **Smart routing** panel on the code's **Settings** tab (open the code from [Codes](https://qrdx.dev/dashboard?to=codes)).

- A code has up to 20 **rules**. Each rule has conditions ("when") and an action ("then": a URL, or an A/B split).
- Rules are checked top to bottom for every scan. The first rule whose conditions all match decides where the scan goes. Use the arrows to reorder rules.
- When no rule matches, the scan goes to the code's main destination.
- A rule without conditions matches every scan, so rules below it never run.
- Turn a rule off to keep it without using it.
- Changes apply to the next scan; you never need to reprint the code.

If a rule can't be evaluated for some reason, the scan still goes to the main destination: routing never stops a code from working.

![The Smart routing panel of a code's Settings tab: rules by operating system, language and time of day, each with its destination, an A/B split at the end, and the Test your rules panel under them.](https://qrdx.dev/docs-static/shots/routing-rules.light.webp)

## Conditions [#conditions]

Each condition can be inverted with **is not** (for example "country is not US").

| Condition | Matches when | Notes |
| --- | --- | --- |
| Device | The scanner uses a phone, tablet, desktop or other device | From the browser's user agent |
| Operating system | iOS, Android, Windows, macOS, Linux, ChromeOS, HarmonyOS and others | iPhone and iPad both count as iOS |
| Country | The scan comes from one of the listed countries | 2-letter codes like `US, CA, GB` |
| Region | The scan comes from one of the listed regions | Codes like `US-CA, US-NY` (country and subdivision) |
| Language | The visitor's preferred browser language is one of the listed ones | `es` matches every Spanish variant (`es-MX`, `es-ES`); `pt-BR` only Brazilian Portuguese |
| Time of day | The scan happens on the chosen weekdays between two times in a time zone you pick | A window like 22:00 to 02:00 runs past midnight and belongs to the day it starts |
| Date range | The scan happens between two dates | Leave one side empty for "until" or "from"; dates are in your browser's time zone |
| Scan count | It's one of the first N scans, or any scan after N | Counts recorded scans (bots aren't counted), so it is approximate when many people scan at once |
| Area | The scanner is within a radius (100 m to 500 km) of a point | Uses the location the scanner shared when [precise location](https://qrdx.dev/docs/precise-location) is on, otherwise the approximate location of their IP address |

Country, region and the IP-based location for areas come from the scanner's IP address, which QRdx never stores. When a location is unknown, location conditions don't match (and "is not" conditions do). [Precise location and geofencing](https://qrdx.dev/docs/precise-location) explains areas, including how to make a code work only inside one.

## Smart app links [#smart-app-links]

Choose **Add rule** → **Smart app link (App Store / Google Play)** to create two rules at once: iOS goes to your App Store link, Android to your Google Play link. Everyone else (desktop, other phones) goes to the main destination, for example your website.

## A/B tests [#ab-tests]

Set a rule's action to **Split between URLs (A/B)** and add 2 to 5 variants, each with a URL and a weight. A split of 70 and 30 sends about 70% of visitors to the first URL.

- Assignment is sticky: a visitor who scans again the same day gets the same variant. It is based on an anonymous daily visitor hash, never a cookie.
- The code's **Analytics** tab shows an **A/B split** card with scans per variant since the split's variants or weights last changed. Each scan stores the variant it was served. Scans from before QRdx stored variants are replayed with your current rules, and the card is then marked as an estimate.
- A split can have conditions too, for example an A/B test for visitors in Germany only.

## Test your rules [#test-your-rules]

Once a code has at least one rule, **Test your rules (uses unsaved changes)** at the bottom of the panel shows where a scan would go for any device, operating system, country, region, language, date and time, scan number, visitor and location. It runs the rules as you have them in the panel, saved or not, against the code's saved main destination and UTM settings. It lists which rule matched and why the others didn't, and shows the final URL including UTM parameters.

![The routing test panel: a pretend scan with a chosen device, operating system, country and language, the Run test button, and the rule that would match.](https://qrdx.dev/docs-static/shots/routing-test.light.webp)

## UTM parameters [#utm-parameters]

The **UTM parameters** panel, below the routing panel, adds `utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, `utm_content` and up to 10 parameters of your own to the URL each scan opens, so analytics tools can tell QR traffic apart.

- Parameters are added after routing, to whichever URL the scan goes to.
- A parameter the URL already has is never replaced, and the rest of the URL is kept exactly as you entered it.
- Names starting with `qrdx_` are reserved for [conversion tracking](https://qrdx.dev/docs/tracking-and-conversions).

## Limits and plans [#limits-and-plans]

| | Free | Pro | Business |
| --- | --- | --- | --- |
| Rules per code | None | 20 | 20 |
| Variants per A/B split | None | 2 to 5 | 2 to 5 |
| Custom UTM parameters | None | 10 | 10 |

Rules and UTM parameters saved on Pro keep working if you downgrade: limits only block creating new things. Without Pro you can still turn rules off, delete them and remove UTM parameters; changing them needs Pro again.

## For developers [#for-developers]

Rules, splits and UTM parameters are set in the dashboard. The [codes API](https://qrdx.dev/docs/developers/api/update-code) creates and updates codes and their destinations but doesn't manage routing rules. Each recorded scan in [`GET /v1/codes/{id}/scans`](https://qrdx.dev/docs/developers/api/get-code-scans) carries the device type, operating system, country, region and city the rules saw.

## Related [#related]

- [Precise location and geofencing](https://qrdx.dev/docs/precise-location): route by area, down to about 100 m
- [Tracking and conversions](https://qrdx.dev/docs/tracking-and-conversions): UTM parameters and conversion tracking together
- [A code opens the wrong page](https://qrdx.dev/docs/help/troubleshooting/wrong-destination): when a rule matched that you didn't expect
